1// run 2 3// Copyright 2018 The Go Authors. All rights reserved. 4// Use of this source code is governed by a BSD-style 5// license that can be found in the LICENSE file. 6 7// Verify effect of various line directives. 8// TODO: check columns 9 10package main 11 12import ( 13 "fmt" 14 "runtime" 15) 16 17func check(file string, line int) { 18 _, f, l, ok := runtime.Caller(1) 19 if !ok { 20 panic("runtime.Caller(1) failed") 21 } 22 if f != file || l != line { 23 panic(fmt.Sprintf("got %s:%d; want %s:%d", f, l, file, line)) 24 } 25} 26 27func main() { 28//-style line directives 29//line :1 30 check("??", 1) // no file specified 31//line foo.go:1 32 check("foo.go", 1) 33//line bar.go:10:20 34 check("bar.go", 10) 35//line :11:22 36 check("bar.go", 11) // no file, but column specified => keep old filename 37 38/*-style line directives */ 39/*line :1*/ check("??", 1) // no file specified 40/*line foo.go:1*/ check("foo.go", 1) 41/*line bar.go:10:20*/ check("bar.go", 10) 42/*line :11:22*/ check("bar.go", 11) // no file, but column specified => keep old filename 43 44 /*line :10*/ check("??", 10); /*line foo.go:20*/ check("foo.go", 20); /*line :30:1*/ check("foo.go", 30) 45 check("foo.go", 31) 46} 47