From c90c146446f2b59901b313c4e083b3143936ecb2 Mon Sep 17 00:00:00 2001 From: Son Luong Ngoc Date: Mon, 13 May 2024 11:36:30 +0200 Subject: [PATCH] PathFragment: test Windows mixed separator On Windows, if a user were to specify a PathFragment with mixed separator such as ``` bazel build --profile='C:/foo\\bar' //... ``` then the profile file will be written as `bar` and recorded in BuildToolLogs event as so. Provide a test that demonstrates the current behavior to discuss whether this is "correct" or not. --- .../build/lib/vfs/PathFragmentWindowsTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentWindowsTest.java b/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentWindowsTest.java index a8dc24fa1870b5..01d1e3376063b0 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentWindowsTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/PathFragmentWindowsTest.java @@ -177,6 +177,9 @@ public void testGetParentDirectoryWindows() { public void testSegmentsCountWindows() { assertThat(create("C:/foo").segmentCount()).isEqualTo(1); assertThat(create("C:/").segmentCount()).isEqualTo(0); + // Mix usage of Windows and Unix separator is valid + assertThat(create("C:/foo\\bar").segmentCount()).isEqualTo(2); + assertThat(create("C:\\foo\\bar/baz").segmentCount()).isEqualTo(3); } @Test @@ -185,6 +188,12 @@ public void testGetSegmentWindows() { assertThat(create("C:/foo/bar").getSegment(1)).isEqualTo("bar"); assertThat(create("C:/foo/").getSegment(0)).isEqualTo("foo"); assertThat(create("C:/foo").getSegment(0)).isEqualTo("foo"); + // Mix usage of Windows and Unix separator is valid + assertThat(create("C:/foo\\bar").getSegment(0)).isEqualTo("foo"); + assertThat(create("C:/foo\\bar").getSegment(1)).isEqualTo("bar"); + assertThat(create("C:\\foo\\bar/baz").getSegment(0)).isEqualTo("foo"); + assertThat(create("C:\\foo\\bar/baz").getSegment(1)).isEqualTo("bar"); + assertThat(create("C:\\foo\\bar/baz").getSegment(2)).isEqualTo("baz"); } @Test @@ -193,6 +202,9 @@ public void testBasenameWindows() throws Exception { assertThat(create("C:/foo").getBaseName()).isEqualTo("foo"); // Never return the drive name as a basename. assertThat(create("C:/").getBaseName()).isEmpty(); + // Mix usage of Windows and Unix separator is valid + assertThat(create("C:/foo\\bar").getBaseName()).isEqualTo("bar"); + assertThat(create("C:\\foo\\bar/baz").getBaseName()).isEqualTo("baz"); } @Test