diff --git a/MoreAsserts.java b/MoreAsserts.java index e1201cd..2f7f00f 100644 --- a/MoreAsserts.java +++ b/MoreAsserts.java @@ -64,54 +64,27 @@ public class MoreAsserts { throw new RuntimeException(msg); } - private static boolean failed = false; - - private static String pattern = ".*"; - public static void main(String[] args) { - if (args.length > 0) { - pattern = args[0]; + SeqTest test = new SeqTest(); + Class c = test.getClass(); + boolean failed = false; + for (Method method : c.getDeclaredMethods()) { + if (!method.getName().startsWith("test") || !Pattern.matches(args[0], method.getName())) { + continue; + } + + System.out.print(method.getName()); + try { + method.invoke(test); + System.out.println(" PASS"); + } catch (Exception ex) { + System.out.println(" FAIL"); + ex.printStackTrace(); + failed = true; + } } - - new TestRunner(new SeqTest()).runTests(); - new TestRunner(new ExtraTest()).runTests(); - // NOTE: We need to call System.exit to force all go threads to exit. System.exit(failed ? 1 : 0); } - - private static class TestRunner { - private T test; - - public TestRunner(T test) { - this.test = test; - } - - public void runTests() { - Class c = test.getClass(); - for (Method method : c.getDeclaredMethods()) { - if (!method.getName().startsWith("test") || !Pattern.matches(pattern, method.getName())) { - continue; - } - - System.out.print(method.getName()); - try { - method.invoke(test); - System.out.println(" PASS"); - } catch (Exception ex) { - System.out.println(" FAIL"); - ex.printStackTrace(); - failed = true; - } - } - } - } - - private static class ExtraTest { - public void testCopyFromScanDir() { - Dummy d = new Dummy(); - assertEquals("Values must match", 42, d.fortyTwo); - } - } } diff --git a/README.md b/README.md index f2700fe..f547d1f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The same set of types are supported. Details on how the binding works can be fou -o string Path to write the generated jar file. (default "libgojava.jar") -s string - Additional path to scan for Java files. These files will be compiled and + Additional path to scan for Java source code. These files will be compiled and included in the final jar. -v Verbose output. ``` diff --git a/gojava.go b/gojava.go index 8bdd03d..c6a8cf0 100644 --- a/gojava.go +++ b/gojava.go @@ -10,10 +10,10 @@ Usage -o string Path to write the generated jar file. (default "libgojava.jar") -s string - Additional path to scan for Java files. These files will be compiled and + Additional path to scan for Java source code. These files will be compiled and included in the final jar. -v Verbose output. - */ +*/ package main import ( @@ -133,19 +133,19 @@ func bindPackages(bindDir, javaDir string, pkgs []*types.Package) ([]string, err return javaFiles, nil } -func addExtraFiles(javaDir, scanDir string) ([]string, error) { - if scanDir == "" { +func addExtraFiles(javaDir, sourceDir string) ([]string, error) { + if sourceDir == "" { return nil, nil } extraFiles := make([]string, 0) - err := filepath.Walk(scanDir, func(path string, info os.FileInfo, walkErr error) error { + err := filepath.Walk(sourceDir, func(path string, info os.FileInfo, walkErr error) error { if walkErr != nil { return walkErr } if info.IsDir() { return nil } - fileName, err := filepath.Rel(scanDir, path) + fileName, err := filepath.Rel(sourceDir, path) if err != nil { return err } @@ -160,7 +160,7 @@ func addExtraFiles(javaDir, scanDir string) ([]string, error) { return nil, err } if len(extraFiles) == 0 { - verbosef("warning: argument -s was passed on command line, but no .java files were found in '%s'\n", scanDir) + verbosef("warning: argument -s was passed on command line, but no .java files were found in '%s'\n", sourceDir) } return extraFiles, nil } @@ -259,7 +259,7 @@ func createJar(target, jarDir string) error { return nil } -func bindToJar(target string, scanDir string, pkgs ...string) error { +func bindToJar(target string, sourceDir string, pkgs ...string) error { tmpDir, cleanup, err := initBuild() if err != nil { return err @@ -286,7 +286,7 @@ func bindToJar(target string, scanDir string, pkgs ...string) error { if err != nil { return err } - extraFiles, err := addExtraFiles(javaDir, scanDir) + extraFiles, err := addExtraFiles(javaDir, sourceDir) if err != nil { return err } @@ -378,7 +378,7 @@ This generates a jar containing Java bindings to the specified Go packages. func main() { o := flag.String("o", "libgojava.jar", "Path to the generated jar file.") - s := flag.String("s", "", "Additional path to scan for Java files.") + s := flag.String("s", "", "Additional path to scan for Java source code.") flag.BoolVar(&verbose, "v", false, "Verbose output.") flag.Usage = func() { fmt.Fprintln(os.Stderr, usage) diff --git a/gojava_test.go b/gojava_test.go index a6f7970..f461dad 100644 --- a/gojava_test.go +++ b/gojava_test.go @@ -13,15 +13,18 @@ import ( var javaTest = flag.String("javatest", ".*", "Run only java tests matching the regular expression") -func TestJavaBind(t *testing.T) { +func init() { verbose = testing.Verbose() +} + +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, - "testdata", + "", "github.com/sridharv/gomobile-java/bind/testpkg", "github.com/sridharv/gomobile-java/bind/testpkg/secondpkg", "github.com/sridharv/gomobile-java/bind/testpkg/simplepkg", @@ -46,3 +49,23 @@ func TestJavaBind(t *testing.T) { 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) + } +} diff --git a/testdata/Dummy.java b/testdata/Dummy.java deleted file mode 100644 index 2d3fb7a..0000000 --- a/testdata/Dummy.java +++ /dev/null @@ -1,5 +0,0 @@ -package go; - -public class Dummy { - public int fortyTwo = 42; -} \ No newline at end of file diff --git a/testdata/SourceDirTest.java b/testdata/SourceDirTest.java new file mode 100644 index 0000000..88146fe --- /dev/null +++ b/testdata/SourceDirTest.java @@ -0,0 +1,7 @@ +package go; + +public class SourceDirTest { + public static void main(String[] args) { + System.out.println("testSourceDirInclusion PASS"); + } +} \ No newline at end of file