modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue18149.go (about)

     1  // run
     2  
     3  // Copyright 2016 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 that //line directives with filenames
     8  // containing ':' (Windows) are correctly parsed.
     9  // (For a related issue, see test/fixedbugs/bug305.go)
    10  
    11  package main
    12  
    13  import (
    14  	"fmt"
    15  	"runtime"
    16  )
    17  
    18  func check(file string, line int) {
    19  	_, f, l, ok := runtime.Caller(1)
    20  	if !ok {
    21  		panic("runtime.Caller(1) failed")
    22  	}
    23  	if f != file || l != line {
    24  		panic(fmt.Sprintf("got %s:%d; want %s:%d", f, l, file, line))
    25  	}
    26  }
    27  
    28  func main() {
    29  //line /foo/bar.go:123
    30  	check(`/foo/bar.go`, 123)
    31  //line c:/foo/bar.go:987
    32  	check(`c:/foo/bar.go`, 987)
    33  }