1
2 # Testcase for issue 64661. This testcase is intended to verify that
3 # we don't try to send swig-generated Go files through the cover tool
4 # for "go test -cover" runs on packages that have *.swig source files.
5
6 [!exec:swig] skip
7 [!cgo] skip
8
9 go test -v -count=1 -coverprofile=foo.p
10 stdout 'coverage: 100.0% of statements'
11
12 -- go.mod --
13 module simple
14
15 go 1.21
16 -- main.c --
17 /* A global variable */
18 double Foo = 3.0;
19
20 /* Compute the greatest common divisor of positive integers */
21 int gcd(int x, int y) {
22 int g;
23 g = y;
24 while (x > 0) {
25 g = x;
26 x = y % x;
27 y = g;
28 }
29 return g;
30 }
31
32
33 -- main.go --
34 package main
35
36 import (
37 "fmt"
38 )
39
40 func main() {
41 // Call our gcd() function
42 x := 42
43 y := 105
44 g := Gcd(x, y)
45 fmt.Println("The gcd of", x, "and", y, "is", g)
46
47 // Manipulate the Foo global variable
48
49 // Output its current value
50 fmt.Println("Foo =", GetFoo())
51
52 // Change its value
53 SetFoo(3.1415926)
54
55 // See if the change took effect
56 fmt.Println("Foo =", GetFoo())
57 }
58 -- main.swig --
59 %module main
60
61 %inline %{
62 extern int gcd(int x, int y);
63 extern double Foo;
64 %}
65 -- main_test.go --
66 package main
67
68 import "testing"
69
70 func TestSwigFuncs(t *testing.T) {
71 main()
72 }
73
View as plain text