MCPcopy Create free account
hub / github.com/golang/mobile / runTest

Function runTest

bind/java/seq_test.go:103–188  ·  view source on GitHub ↗

runTest runs the Android java test class specified with javaCls. If javaPkg is set, it is passed with the -javapkg flag to gomobile. The pkgNames lists the Go packages to bind for the test. This requires the gradle command to be in PATH and the Android SDK to be installed.

(t *testing.T, pkgNames []string, javaPkg, javaCls string)

Source from the content-addressed store, hash-verified

101// This requires the gradle command to be in PATH and the Android SDK to be
102// installed.
103func runTest(t *testing.T, pkgNames []string, javaPkg, javaCls string) {
104 if gomobileBin == "" {
105 t.Skipf("no gomobile on %s", runtime.GOOS)
106 }
107 gradle, err := exec.LookPath("gradle")
108 if err != nil {
109 t.Skip("command gradle not found, skipping")
110 }
111 if _, err := sdkpath.AndroidHome(); err != nil {
112 t.Skip("Android SDK not found, skipping")
113 }
114
115 cwd, err := os.Getwd()
116 if err != nil {
117 t.Fatalf("failed pwd: %v", err)
118 }
119 tmpdir, err := os.MkdirTemp("", "bind-java-seq-test-")
120 if err != nil {
121 t.Fatalf("failed to prepare temp dir: %v", err)
122 }
123 defer os.RemoveAll(tmpdir)
124 t.Logf("tmpdir = %s", tmpdir)
125
126 if err := os.Chdir(tmpdir); err != nil {
127 t.Fatalf("failed chdir: %v", err)
128 }
129 defer os.Chdir(cwd)
130
131 for _, d := range []string{"src/main", "src/androidTest/java/go", "libs", "src/main/res/values"} {
132 err = os.MkdirAll(filepath.Join(tmpdir, d), 0700)
133 if err != nil {
134 t.Fatal(err)
135 }
136 }
137
138 args := []string{"bind", "-tags", "aaa bbb", "-o", "pkg.aar"}
139 if javaPkg != "" {
140 args = append(args, "-javapkg", javaPkg)
141 }
142 args = append(args, pkgNames...)
143 cmd := exec.Command(gomobileBin, args...)
144 // Reverse binding doesn't work with Go module since imports starting with Java or ObjC are not valid FQDNs.
145 // Disable Go module explicitly until this problem is solved. See golang/go#27234.
146 cmd.Env = append(os.Environ(), "GO111MODULE=off")
147 buf, err := cmd.CombinedOutput()
148 if err != nil {
149 t.Logf("%s", buf)
150 t.Fatalf("failed to run gomobile bind: %v", err)
151 }
152
153 fname := filepath.Join(tmpdir, "libs", "pkg.aar")
154 err = cp(fname, filepath.Join(tmpdir, "pkg.aar"))
155 if err != nil {
156 t.Fatalf("failed to copy pkg.aar: %v", err)
157 }
158
159 fname = filepath.Join(tmpdir, "src/androidTest/java/go/"+javaCls+".java")
160 err = cp(fname, filepath.Join(cwd, javaCls+".java"))

Callers 4

TestClassesFunction · 0.70
TestCustomPkgFunction · 0.70
TestJavaSeqTestFunction · 0.70
TestJavaSeqBenchFunction · 0.70

Calls 3

AndroidHomeFunction · 0.92
cpFunction · 0.70
runFunction · 0.70

Tested by

no test coverage detected