aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2016-06-15 10:00:55 +0000
committerGravatar Yue Gan <yueg@google.com>2016-06-15 14:49:20 +0000
commitce79c8170a723e9e21407f891c92f2730e272f78 (patch)
tree3d6f1549693d71e8bea233630e2020ab9a23c451
parent3c18cd05f9eb573cf1b153da97fd42d1b380b6c7 (diff)
Make bazel test work on Windows
bazel test now works for java native example tests, but most of Bazel's java_test still fail on Windows due to other reasons. -- Change-Id: Ie4ab6570b294815b9e06dd9bbd0cb7a48eb6ed11 Reviewed-on: https://bazel-review.googlesource.com/#/c/3810 MOS_MIGRATED_REVID=124932604
-rw-r--r--examples/java-native/src/test/java/com/example/myproject/TestCustomGreeting.java4
-rw-r--r--examples/java-native/src/test/java/com/example/myproject/TestHello.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt6
3 files changed, 10 insertions, 4 deletions
diff --git a/examples/java-native/src/test/java/com/example/myproject/TestCustomGreeting.java b/examples/java-native/src/test/java/com/example/myproject/TestCustomGreeting.java
index f14b7d234a..7bc55fc643 100644
--- a/examples/java-native/src/test/java/com/example/myproject/TestCustomGreeting.java
+++ b/examples/java-native/src/test/java/com/example/myproject/TestCustomGreeting.java
@@ -18,7 +18,7 @@ public class TestCustomGreeting {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Greeter.out = new PrintStream(out);
Greeter.main();
- assertEquals("Bye world\n", new String(out.toByteArray(), StandardCharsets.UTF_8));
+ assertEquals("Bye world", new String(out.toByteArray(), StandardCharsets.UTF_8).trim());
}
@Test
@@ -26,7 +26,7 @@ public class TestCustomGreeting {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Greeter.out = new PrintStream(out);
Greeter.main("toto");
- assertEquals("Bye toto\n", new String(out.toByteArray(), StandardCharsets.UTF_8));
+ assertEquals("Bye toto", new String(out.toByteArray(), StandardCharsets.UTF_8).trim());
}
}
diff --git a/examples/java-native/src/test/java/com/example/myproject/TestHello.java b/examples/java-native/src/test/java/com/example/myproject/TestHello.java
index d50e6e503f..e8b775847f 100644
--- a/examples/java-native/src/test/java/com/example/myproject/TestHello.java
+++ b/examples/java-native/src/test/java/com/example/myproject/TestHello.java
@@ -21,7 +21,7 @@ public class TestHello {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Greeter.out = new PrintStream(out);
Greeter.main();
- assertEquals("Hello world\n", new String(out.toByteArray(), StandardCharsets.UTF_8));
+ assertEquals("Hello world", new String(out.toByteArray(), StandardCharsets.UTF_8).trim());
}
@Test
@@ -29,7 +29,7 @@ public class TestHello {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Greeter.out = new PrintStream(out);
Greeter.main("toto");
- assertEquals("Hello toto\n", new String(out.toByteArray(), StandardCharsets.UTF_8));
+ assertEquals("Hello toto", new String(out.toByteArray(), StandardCharsets.UTF_8).trim());
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt
index 18f75e2eed..25dbc1b39f 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt
@@ -142,6 +142,12 @@ if [[ "$SINGLEJAR" != 1 || "%needs_runfiles%" == 1 ]]; then
fi
fi
+# This script is running with msys on Windows, so CLASSPATH has to be unix format. If JAVA_RUNFILES
+# is like C:/blah/blah, we need convert it to /c/blah/blah, otherwise CLASSPATH doesn't work.
+if [ ${JAVA_RUNFILES:1:1} == : ]; then
+ JAVA_RUNFILES=$(cygpath --unix "$JAVA_RUNFILES")
+fi
+
# Set JAVABIN to the path to the JVM launcher.
%javabin%