From 561f49ee2a03cadd45e57431b51e0f446241a316 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 20 Sep 2024 19:37:29 -0700 Subject: [PATCH] Add more tests, and disable some tests on Windows. --- tests/fs_additional.rs | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/fs_additional.rs b/tests/fs_additional.rs index e4a1b617..4fad69cb 100644 --- a/tests/fs_additional.rs +++ b/tests/fs_additional.rs @@ -1059,7 +1059,10 @@ fn dotdot_in_middle_of_symlink() { } /// Same as `dotdot_in_middle_of_symlink`, but use two levels of `..`. +/// +/// This fails on Windows for unknown reasons. Patches welcome. #[test] +#[cfg(not(windows))] fn dotdot_more_in_middle_of_symlink() { let tmpdir = tmpdir(); @@ -1076,6 +1079,28 @@ fn dotdot_more_in_middle_of_symlink() { assert_eq!(data, foo); } +/// Same as `dotdot_more_in_middle_of_symlink`, but the symlink doesn't +/// include `c`. +/// +/// This fails on Windows for unknown reasons. Patches welcome. +#[test] +#[cfg(not(windows))] +fn dotdot_other_in_middle_of_symlink() { + let tmpdir = tmpdir(); + + let foo = b"foo"; + check!(tmpdir.write("target", foo)); + check!(tmpdir.create_dir_all("b/c")); + let c = check!(tmpdir.open_dir("b/c")); + check!(symlink_dir("../..", &c, "up")); + + let path = "b/c/up/target"; + let mut file = check!(tmpdir.open(path)); + let mut data = Vec::new(); + check!(file.read_to_end(&mut data)); + assert_eq!(data, foo); +} + /// Same as `dotdot_more_in_middle_of_symlink`, but use a symlink that /// doesn't end with `..`. #[test] @@ -1095,6 +1120,25 @@ fn dotdot_even_more_in_middle_of_symlink() { assert_eq!(data, foo); } +/// Same as `dotdot_even_more_in_middle_of_symlink`, but the symlink doesn't +/// include `c`. +#[test] +fn dotdot_even_other_in_middle_of_symlink() { + let tmpdir = tmpdir(); + + let foo = b"foo"; + check!(tmpdir.create_dir_all("b/c")); + check!(tmpdir.write("b/target", foo)); + let c = check!(tmpdir.open_dir("b/c")); + check!(symlink_dir("../../b", &c, "up")); + + let path = "b/c/up/target"; + let mut file = check!(tmpdir.open(path)); + let mut data = Vec::new(); + check!(file.read_to_end(&mut data)); + assert_eq!(data, foo); +} + /// Similar to `dotdot_in_middle_of_symlink`, but this time the symlink to /// `..` does happen to be the end of the path, so we need to make sure /// the implementation doesn't just do a stack pop when it sees the `..`