2
0
mirror of synced 2025-02-24 15:28:28 +00:00
mobile/cmd/gobind/gobind_test.go
Elias Naur 5d5d88d1b1 cmd/gomobile: add CGO_ENABLED=1 to gobind runs
A previous CL switched gobind to use the "source" importer so go
files using cgo can be type checked. However, CGO_ENABLED=1 also
have to be passed in for such files not be ignored.

Also add -tags ios to the gomobile test output missing from CL
99777.

Fixes golang/go#24941

Change-Id: I868469af3061b82ab592899e365a8a90a0333e58
Reviewed-on: https://go-review.googlesource.com/108336
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2018-04-20 08:11:07 +00:00

74 lines
1.9 KiB
Go

// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"os"
"os/exec"
"testing"
)
var tests = []struct {
name string
lang string
pkg string
goos string
}{
{"ObjC-Testpkg", "objc", "golang.org/x/mobile/bind/testdata/testpkg", ""},
{"Java-Testpkg", "java", "golang.org/x/mobile/bind/testdata/testpkg", ""},
{"Go-Testpkg", "go", "golang.org/x/mobile/bind/testdata/testpkg", ""},
{"Java-Javapkg", "java", "golang.org/x/mobile/bind/testdata/testpkg/javapkg", "android"},
{"Go-Javapkg", "go", "golang.org/x/mobile/bind/testdata/testpkg/javapkg", "android"},
{"Go-Javapkg", "go,java,objc", "golang.org/x/mobile/bind/testdata/cgopkg", "android"},
}
func installGobind() error {
if out, err := exec.Command("go", "install", "golang.org/x/mobile/cmd/gobind").CombinedOutput(); err != nil {
return fmt.Errorf("gobind install failed: %v: %s", err, out)
}
return nil
}
func runGobind(lang, pkg, goos string) error {
cmd := exec.Command("gobind", "-lang", lang, pkg)
if goos != "" {
cmd.Env = append(os.Environ(), "GOOS="+goos)
cmd.Env = append(os.Environ(), "CGO_ENABLED=1")
}
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("gobind -lang %s %s failed: %v: %s", lang, pkg, err, out)
}
return nil
}
func TestGobind(t *testing.T) {
if err := installGobind(); err != nil {
t.Fatal(err)
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if err := runGobind(test.lang, test.pkg, test.goos); err != nil {
t.Error(err)
}
})
}
}
func BenchmarkGobind(b *testing.B) {
if err := installGobind(); err != nil {
b.Fatal(err)
}
for _, test := range tests {
b.Run(test.name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
if err := runGobind(test.lang, test.pkg, test.goos); err != nil {
b.Error(err)
}
}
})
}
}