Skip to content

Commit

Permalink
misc/cgo/testcarchive: check that os.Args is set
Browse files Browse the repository at this point in the history
Change-Id: I4278abca9d2a8f25149fa8935a93d32e7d04a43a
Reviewed-on: https://go-review.googlesource.com/9050
Reviewed-by: Ian Lance Taylor <[email protected]>
Run-TryBot: David Crawshaw <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
crawshaw committed Apr 17, 2015
1 parent 4d01922 commit c5befcf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions misc/cgo/testcarchive/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
extern signed char DidInitRun();
extern signed char DidMainRun();
extern int32_t FromPkg();
extern void CheckArgs();

int main(void) {
int32_t res;
Expand All @@ -28,5 +29,7 @@ int main(void) {
return 2;
}

CheckArgs();

return 0;
}
15 changes: 14 additions & 1 deletion misc/cgo/testcarchive/src/libgo/libgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
package main

import (
_ "p"
"fmt"
"os"
"reflect"
"syscall"
"time"

_ "p"
)

import "C"
Expand Down Expand Up @@ -40,3 +44,12 @@ func DidInitRun() bool {

//export DidMainRun
func DidMainRun() bool { return ranMain }

//export CheckArgs
func CheckArgs() {
want := []string{"./testp", "arg1", "arg2"}
if !reflect.DeepEqual(want, os.Args) {
fmt.Printf("CheckArgs: want %v, got: %v\n", want, os.Args)
os.Exit(2)
}
}
4 changes: 2 additions & 2 deletions misc/cgo/testcarchive/test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ fi

GOPATH=$(pwd) go build -buildmode=c-archive src/libgo/libgo.go
$(go env CC) $(go env GOGCCFLAGS) $ccargs -o testp main.c libgo.a
$bin
$bin arg1 arg2
rm libgo.a testp

GOPATH=$(pwd) go build -buildmode=c-archive -o libgo.a libgo
$(go env CC) $(go env GOGCCFLAGS) $ccargs -o testp main.c libgo.a
$bin
$bin arg1 arg2
rm libgo.a testp

0 comments on commit c5befcf

Please sign in to comment.