Source file
test/fixedbugs/issue22662.go
1
2
3
4
5
6
7
8
9
10 package main
11
12 import (
13 "fmt"
14 "runtime"
15 )
16
17 func 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
27 func main() {
28
29
30 check("??", 1)
31
32 check("foo.go", 1)
33
34 check("bar.go", 10)
35
36 check("bar.go", 11)
37
38
39 check("??", 1)
40 check("foo.go", 1)
41 check("bar.go", 10)
42 check("bar.go", 11)
43
44 check("??", 10); check("foo.go", 20); check("foo.go", 30)
45 check("foo.go", 31)
46 }
47
View as plain text