From 56f94b6d2a685858372393c414a1d9cad74e6e91 Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Mon, 25 Jul 2016 08:26:14 +0000 Subject: Fixed ConvertersTest on Windows Recently, a new java test is added into Bazel, but failing on Windows because using the wrong path separator. This change fixs it. -- Change-Id: Ib73abac9c22b1d21180f76c13358a1173fde863c Reviewed-on: https://bazel-review.googlesource.com/#/c/4131 MOS_MIGRATED_REVID=128331068 --- .../google/devtools/build/android/ConvertersTest.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/test/java/com/google/devtools/build/android/ConvertersTest.java') diff --git a/src/test/java/com/google/devtools/build/android/ConvertersTest.java b/src/test/java/com/google/devtools/build/android/ConvertersTest.java index 130a7ec964..83bbe66677 100644 --- a/src/test/java/com/google/devtools/build/android/ConvertersTest.java +++ b/src/test/java/com/google/devtools/build/android/ConvertersTest.java @@ -24,6 +24,7 @@ import com.google.devtools.build.android.Converters.PathListConverter; import com.google.devtools.build.android.Converters.PathStringDictionaryConverter; import com.google.devtools.build.android.Converters.StringDictionaryConverter; import com.google.devtools.common.options.OptionsParsingException; +import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; @@ -41,8 +42,9 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public final class ConvertersTest { - @Rule - public final TemporaryFolder tmp = new TemporaryFolder(); + private static final String SEPARATOR = File.pathSeparator; + + @Rule public final TemporaryFolder tmp = new TemporaryFolder(); @Rule public final ExpectedException expected = ExpectedException.none(); @@ -90,9 +92,11 @@ public final class ConvertersTest { @Test public void testPathListConverter() throws Exception { PathListConverter converter = new PathListConverter(); - List result = converter.convert("foo:bar::baz:"); + List result = + converter.convert("foo" + SEPARATOR + "bar" + SEPARATOR + SEPARATOR + "baz" + SEPARATOR); assertThat(result) - .containsAllOf(Paths.get("foo"), Paths.get("bar"), Paths.get("baz")).inOrder(); + .containsAllOf(Paths.get("foo"), Paths.get("bar"), Paths.get("baz")) + .inOrder(); } @Test @@ -102,7 +106,7 @@ public final class ConvertersTest { expected.expect(OptionsParsingException.class); expected.expectMessage(String.format("%s is not a valid path: it does not exist.", arg)); ExistingPathListConverter converter = new ExistingPathListConverter(); - converter.convert(Joiner.on(":").join(existingFile.toString(), arg)); + converter.convert(Joiner.on(SEPARATOR).join(existingFile.toString(), arg)); } @Test @@ -162,7 +166,10 @@ public final class ConvertersTest { public void testExistingPathStringDictionaryConverter() throws Exception { Path existingFile = tmp.newFile("existing").toPath(); ExistingPathStringDictionaryConverter converter = new ExistingPathStringDictionaryConverter(); - Map result = converter.convert(String.format("%s:string", existingFile)); + Map result = + converter + // On Windows, the path starts like C:\foo\bar\..., we need to escape the colon. + .convert(String.format("%s:string", existingFile.toString().replace(":", "\\:"))); assertThat(result).containsExactly(existingFile, "string"); } } -- cgit v1.2.3