...

Text file src/cmd/go/testdata/script/cover_swig.txt

Documentation: cmd/go/testdata/script

     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
     9go test -v -count=1 -coverprofile=foo.p
    10stdout 'coverage: 100.0% of statements'
    11
    12-- go.mod --
    13module simple
    14
    15go 1.21
    16-- main.c --
    17/* A global variable */
    18double Foo = 3.0;
    19
    20/* Compute the greatest common divisor of positive integers */
    21int 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 --
    34package main
    35
    36import (
    37	"fmt"
    38)
    39
    40func 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 %{
    62extern int    gcd(int x, int y);
    63extern double Foo;
    64%}
    65-- main_test.go --
    66package main
    67
    68import "testing"
    69
    70func TestSwigFuncs(t *testing.T) {
    71	main()
    72}

View as plain text