aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar László Csomor <laszlocsomor@google.com>2017-03-03 14:24:46 +0000
committerGravatar Yue Gan <yueg@google.com>2017-03-06 09:44:33 +0000
commit0768f3e444a121c5c8e8e0bd0bb98772fab0e0e2 (patch)
treedf97957907a51d063b38326a556168be3e9b8745 /src/test
parent0ca44769ea775485aac177664a13d4e178fa037b (diff)
PathFragment comparisons are now platform-aware
PathFragment's `equals`, `hashCode`, `compareTo`, `startsWith`, `endsWith`, and `relativeTo` are now aware of case-insensitivity when running on Windows. This approach is better than https://bazel-review.googlesource.com/c/9124/ because it preserves path casing, which is important when computing action output paths. This change contains two additional bugfixes: - `compareTo` now takes `driveLetter` into account - the `InMemoryFileSystem` in `PathWindowsTest` is not case-insensitive Fixes https://github.com/bazelbuild/bazel/issues/2613 -- Change-Id: I1a4250a373fff03fa02a6d8360457450b47a42a8 Reviewed-on: https://cr.bazel.build/9126 PiperOrigin-RevId: 149106930 MOS_MIGRATED_REVID=149106930
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java b/src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java
index 388c3fd754..04015dd28f 100644
--- a/src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java
@@ -24,6 +24,7 @@ import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.Path.PathFactory;
import com.google.devtools.build.lib.vfs.PathFragment;
+import com.google.devtools.build.lib.vfs.RootedPath;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
import com.google.devtools.build.lib.windows.WindowsFileSystem.WindowsPath;
import java.util.ArrayList;
@@ -65,6 +66,11 @@ public class PathWindowsTest {
protected PathFactory getPathFactory() {
return WindowsFileSystem.getPathFactoryForTesting(shortPathResolver);
}
+
+ @Override
+ public boolean isFilePathCaseSensitive() {
+ return false;
+ }
};
root = (WindowsPath) filesystem.getRootDirectory().getRelative("C:/");
root.createDirectory();
@@ -280,4 +286,53 @@ public class PathWindowsTest {
"D:/program files/microsoft something/foo/~bar_hello",
"D:/program files/microsoft something/foo/will.exist");
}
+
+ @Test
+ public void testCaseInsensitivePathFragment() {
+ // equals
+ assertThat(new PathFragment("c:/FOO/BAR")).isEqualTo(new PathFragment("c:\\foo\\bar"));
+ assertThat(new PathFragment("c:/FOO/BAR")).isNotEqualTo(new PathFragment("d:\\foo\\bar"));
+ assertThat(new PathFragment("c:/FOO/BAR")).isNotEqualTo(new PathFragment("/foo/bar"));
+ // equals for the string representation
+ assertThat(new PathFragment("c:/FOO/BAR").toString())
+ .isNotEqualTo(new PathFragment("c:/foo/bar").toString());
+ // hashCode
+ assertThat(new PathFragment("c:/FOO/BAR").hashCode())
+ .isEqualTo(new PathFragment("c:\\foo\\bar").hashCode());
+ assertThat(new PathFragment("c:/FOO/BAR").hashCode())
+ .isNotEqualTo(new PathFragment("d:\\foo\\bar").hashCode());
+ assertThat(new PathFragment("c:/FOO/BAR").hashCode())
+ .isNotEqualTo(new PathFragment("/foo/bar").hashCode());
+ // compareTo
+ assertThat(new PathFragment("c:/FOO/BAR").compareTo(new PathFragment("c:\\foo\\bar")))
+ .isEqualTo(0);
+ assertThat(new PathFragment("c:/FOO/BAR").compareTo(new PathFragment("d:\\foo\\bar")))
+ .isLessThan(0);
+ assertThat(new PathFragment("c:/FOO/BAR").compareTo(new PathFragment("/foo/bar")))
+ .isGreaterThan(0);
+ // startsWith
+ assertThat(new PathFragment("c:/FOO/BAR").startsWith(new PathFragment("c:\\foo"))).isTrue();
+ assertThat(new PathFragment("c:/FOO/BAR").startsWith(new PathFragment("d:\\foo"))).isFalse();
+ // endsWith
+ assertThat(new PathFragment("c:/FOO/BAR/BAZ").endsWith(new PathFragment("bar\\baz"))).isTrue();
+ assertThat(new PathFragment("c:/FOO/BAR/BAZ").endsWith(new PathFragment("/bar/baz"))).isFalse();
+ assertThat(new PathFragment("c:/FOO/BAR/BAZ").endsWith(new PathFragment("d:\\bar\\baz")))
+ .isFalse();
+ // relativeTo
+ assertThat(new PathFragment("c:/FOO/BAR/BAZ/QUX").relativeTo(new PathFragment("c:\\foo\\bar")))
+ .isEqualTo(new PathFragment("Baz/Qux"));
+ }
+
+ @Test
+ public void testCaseInsensitiveRootedPath() {
+ Path ancestor = filesystem.getPath("C:\\foo\\bar");
+ assertThat(ancestor).isInstanceOf(WindowsPath.class);
+ Path child = filesystem.getPath("C:\\FOO\\Bar\\baz");
+ assertThat(child).isInstanceOf(WindowsPath.class);
+ assertThat(child.startsWith(ancestor)).isTrue();
+ assertThat(child.relativeTo(ancestor)).isEqualTo(new PathFragment("baz"));
+ RootedPath actual = RootedPath.toRootedPath(ancestor, child);
+ assertThat(actual.getRoot()).isEqualTo(ancestor);
+ assertThat(actual.getRelativePath()).isEqualTo(new PathFragment("baz"));
+ }
}