| 1 |
// Copyright 2017 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
// This file is here just to cause problems. |
| 6 |
// main.swig turns into a file also named main.go. |
| 7 |
// Make sure cmd/go keeps them separate |
| 8 |
// when both are passed to cgo. |
| 9 |
|
| 10 |
package main |
| 11 |
|
| 12 |
//int F(void) { return 1; } |
| 13 |
import "C" |
| 14 |
import ( |
| 15 |
"fmt" |
| 16 |
"os" |
| 17 |
) |
| 18 |
|
| 19 |
func F() int { return int(C.F()) } |
| 20 |
|
| 21 |
func main() { |
| 22 |
if x := int(C.F()); x != 1 { |
| 23 |
fatal("x = %d, want 1", x) |
| 24 |
} |
| 25 |
|
| 26 |
// Open this file itself and verify that the first few characters are |
| 27 |
// as expected. |
| 28 |
f := Fopen("main.go", "r") |
| 29 |
if f.Swigcptr() == 0 { |
| 30 |
fatal("fopen failed") |
| 31 |
} |
| 32 |
if Fgetc(f) != '/' || Fgetc(f) != '/' || Fgetc(f) != ' ' || Fgetc(f) != 'C' { |
| 33 |
fatal("read unexpected characters") |
| 34 |
} |
| 35 |
if Fclose(f) != 0 { |
| 36 |
fatal("fclose failed") |
| 37 |
} |
| 38 |
|
| 39 |
println("OK") |
| 40 |
} |
| 41 |
|
| 42 |
func fatal(f string, args ...any) { |
| 43 |
fmt.Fprintln(os.Stderr, fmt.Sprintf(f, args...)) |
| 44 |
os.Exit(1) |
| 45 |
} |