summaryrefslogtreecommitdiffstats
path: root/src/cmd/go/testdata/script/cover_swig.txt
blob: decb29aaec2a71d8a302d3fc0c2b398369f1d359 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Testcase for issue 64661.  This testcase is intended to verify that
# we don't try to send swig-generated Go files through the cover tool
# for "go test -cover" runs on packages that have *.swig source files.

[!exec:swig] skip
[!cgo] skip

go test -v -count=1 -coverprofile=foo.p
stdout 'coverage: 100.0% of statements'

-- go.mod --
module simple

go 1.21
-- main.c --
/* A global variable */
double Foo = 3.0;

/* Compute the greatest common divisor of positive integers */
int gcd(int x, int y) {
  int g;
  g = y;
  while (x > 0) {
    g = x;
    x = y % x;
    y = g;
  }
  return g;
}


-- main.go --
package main

import (
	"fmt"
)

func main() {
	// Call our gcd() function
	x := 42
	y := 105
	g := Gcd(x, y)
	fmt.Println("The gcd of", x, "and", y, "is", g)

	// Manipulate the Foo global variable

	// Output its current value
	fmt.Println("Foo =", GetFoo())

	// Change its value
	SetFoo(3.1415926)

	// See if the change took effect
	fmt.Println("Foo =", GetFoo())
}
-- main.swig --
%module main

%inline %{
extern int    gcd(int x, int y);
extern double Foo;
%}
-- main_test.go --
package main

import "testing"

func TestSwigFuncs(t *testing.T) {
	main()
}