-
Notifications
You must be signed in to change notification settings - Fork 15
/
gojava_test.go
79 lines (70 loc) · 1.81 KB
/
gojava_test.go
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
73
74
75
76
77
78
79
package main
import (
"testing"
"flag"
"go/build"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"github.com/surullabs/lint"
)
var javaTest = flag.String("javatest", ".*", "Run only java tests matching the regular expression")
func init() {
verbose = testing.Verbose()
}
func TestLint(t *testing.T) {
if err := lint.Default.Check("."); err != nil {
t.Fatal(err)
}
}
func TestJavaBind(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "gojavatest")
if err != nil {
t.Fatal(err)
}
jar := filepath.Join(tmpDir, "gojavatest.jar")
if err := bindToJar(jar,
"",
"github.com/sridharv/gomobile-java/bind/testpkg",
"github.com/sridharv/gomobile-java/bind/testpkg/secondpkg",
"github.com/sridharv/gomobile-java/bind/testpkg/simplepkg",
); err != nil {
t.Fatal(err)
}
toCopy := []filePair{
{filepath.Join(tmpDir, "MoreAsserts.java"), "MoreAsserts.java"},
{filepath.Join(tmpDir, "SeqTest.java"), filepath.Join(build.Default.GOPATH, "src/github.com/sridharv/gomobile-java/bind/java/SeqTest.java")},
}
if err := copyFiles(toCopy); err != nil {
t.Fatal(err)
}
if err := runCommand("javac", "-cp", jar, "-d", tmpDir, toCopy[0].dst, toCopy[1].dst); err != nil {
t.Fatal(err)
}
cmd := exec.Command("java", "-cp", jar+":"+tmpDir, "go.MoreAsserts", *javaTest)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
if err := cmd.Run(); err != nil {
t.Fatal(err)
}
}
func TestSourceDir(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "gojavatest")
if err != nil {
t.Fatal(err)
}
jar := filepath.Join(tmpDir, "gojavatest.jar")
if err := bindToJar(jar,
"testdata",
"github.com/sridharv/gomobile-java/bind/testpkg",
); err != nil {
t.Fatal(err)
}
cmd := exec.Command("java", "-cp", jar, "go.SourceDirTest")
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
if err := cmd.Run(); err != nil {
t.Fatal(err)
}
}