Fix substring bug

When one directory was a substring of another the directory would appear
as a subdirectory instead of a sibling

Fixed originally by this: 6e03dd77e6
Broken by this: db6c8a019d

Added integration test as this has bitten me before
This commit is contained in:
andy.boot
2019-12-04 21:58:29 +00:00
parent 7ba91a4a22
commit 5535478fe8
6 changed files with 90 additions and 18 deletions
+44 -2
View File
@@ -138,7 +138,7 @@ pub fn test_d_flag_works() {
.unwrap();
}
fn build_temp_file(dir: &TempDir) -> (PathBuf) {
fn build_temp_file(dir: &TempDir) -> PathBuf {
let file_path = dir.path().join("notes.txt");
let mut file = File::create(&file_path).unwrap();
writeln!(file, "I am a temp file").unwrap();
@@ -164,7 +164,7 @@ pub fn test_soft_sym_link() {
let r = soft_sym_link_output(dir_s, file_path_s, link_name_s);
// We cannot guarantee which version will appear first.
// TODO: Consider adding predictable itteration order (sort file entries by name?)
// TODO: Consider adding predictable iteration order (sort file entries by name?)
assert_cli::Assert::main_binary()
.with_args(&[dir_s])
.stdout()
@@ -308,3 +308,45 @@ fn recursive_sym_link_output(dir: &str, link_name: &str) -> String {
format_string(link_name, true, true, " 0B", " └──",),
)
}
// Check against directories and files whos names are substrings of each other
#[test]
#[cfg(target_os = "macos")]
pub fn test_substring_of_names() {
assert_cli::Assert::main_binary()
.with_args(&["src/test_dir2"])
.stdout()
.contains(" ─┬ test_dir2")
.stdout()
.contains(" ├─┬ dir")
.stdout()
.contains(" │ └── hello")
.stdout()
.contains(" ├── dir_name_clash")
.stdout()
.contains(" └─┬ dir_substring")
.stdout()
.contains(" └── hello")
.unwrap();
}
// Check against directories and files whos names are substrings of each other
#[test]
#[cfg(target_os = "linux")]
pub fn test_substring_of_names() {
assert_cli::Assert::main_binary()
.with_args(&["src/test_dir2"])
.stdout()
.contains(" ─┬ test_dir2")
.stdout()
.contains(" ├─┬ dir")
.stdout()
.contains(" │ └── hello")
.stdout()
.contains(" ├─┬ dir_substring")
.stdout()
.contains(" │ └── hello")
.stdout()
.contains(" └── dir_name_clash")
.unwrap();
}