2019-12-17 18:54:39 +00:00
|
|
|
use nu_test_support::fs::Stub::EmptyFile;
|
2020-07-04 20:17:36 +00:00
|
|
|
use nu_test_support::playground::{Dirs, Playground};
|
2020-05-07 11:03:43 +00:00
|
|
|
use nu_test_support::{nu, pipeline};
|
2019-08-02 09:23:39 +00:00
|
|
|
|
|
|
|
#[test]
|
2019-12-15 16:15:06 +00:00
|
|
|
fn lists_regular_files() {
|
2019-08-29 00:32:42 +00:00
|
|
|
Playground::setup("ls_test_1", |dirs, sandbox| {
|
2019-09-11 14:36:50 +00:00
|
|
|
sandbox.with_files(vec![
|
2019-10-15 10:16:47 +00:00
|
|
|
EmptyFile("yehuda.txt"),
|
|
|
|
EmptyFile("jonathan.txt"),
|
|
|
|
EmptyFile("andres.txt"),
|
2019-08-29 00:32:42 +00:00
|
|
|
]);
|
2019-08-02 09:23:39 +00:00
|
|
|
|
2019-08-29 00:32:42 +00:00
|
|
|
let actual = nu!(
|
2019-12-15 16:15:06 +00:00
|
|
|
cwd: dirs.test(), pipeline(
|
2019-08-29 06:31:56 +00:00
|
|
|
r#"
|
2019-09-03 00:49:51 +00:00
|
|
|
ls
|
2019-10-15 10:16:47 +00:00
|
|
|
| count
|
2019-08-29 06:31:56 +00:00
|
|
|
| echo $it
|
|
|
|
"#
|
2019-08-29 00:32:42 +00:00
|
|
|
));
|
2019-08-02 09:23:39 +00:00
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "3");
|
2019-08-28 17:01:16 +00:00
|
|
|
})
|
2019-08-02 09:23:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-12-15 16:15:06 +00:00
|
|
|
fn lists_regular_files_using_asterisk_wildcard() {
|
2019-08-29 00:32:42 +00:00
|
|
|
Playground::setup("ls_test_2", |dirs, sandbox| {
|
2019-09-11 14:36:50 +00:00
|
|
|
sandbox.with_files(vec![
|
2019-10-15 10:16:47 +00:00
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
2019-08-29 00:32:42 +00:00
|
|
|
]);
|
2019-08-02 09:23:39 +00:00
|
|
|
|
2019-08-29 00:32:42 +00:00
|
|
|
let actual = nu!(
|
2019-12-15 16:15:06 +00:00
|
|
|
cwd: dirs.test(), pipeline(
|
2019-08-29 06:31:56 +00:00
|
|
|
r#"
|
2019-09-03 00:49:51 +00:00
|
|
|
ls *.txt
|
2019-10-15 10:16:47 +00:00
|
|
|
| count
|
2019-08-29 06:31:56 +00:00
|
|
|
| echo $it
|
|
|
|
"#
|
2019-08-29 00:32:42 +00:00
|
|
|
));
|
2019-08-02 09:23:39 +00:00
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "3");
|
2019-08-28 17:01:16 +00:00
|
|
|
})
|
2019-08-02 09:23:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-12-15 16:15:06 +00:00
|
|
|
fn lists_regular_files_using_question_mark_wildcard() {
|
2019-08-29 00:32:42 +00:00
|
|
|
Playground::setup("ls_test_3", |dirs, sandbox| {
|
2019-09-11 14:36:50 +00:00
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("yehuda.10.txt"),
|
|
|
|
EmptyFile("jonathan.10.txt"),
|
|
|
|
EmptyFile("andres.10.txt"),
|
|
|
|
EmptyFile("chicken_not_to_be_picked_up.100.txt"),
|
2019-08-29 00:32:42 +00:00
|
|
|
]);
|
2019-08-02 09:23:39 +00:00
|
|
|
|
2019-08-29 00:32:42 +00:00
|
|
|
let actual = nu!(
|
2019-12-15 16:15:06 +00:00
|
|
|
cwd: dirs.test(), pipeline(
|
2019-08-29 06:31:56 +00:00
|
|
|
r#"
|
2019-09-03 00:49:51 +00:00
|
|
|
ls *.??.txt
|
2019-10-15 10:16:47 +00:00
|
|
|
| count
|
2019-08-29 06:31:56 +00:00
|
|
|
| echo $it
|
|
|
|
"#
|
2019-08-29 00:32:42 +00:00
|
|
|
));
|
2019-08-02 09:23:39 +00:00
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "3");
|
2019-08-28 17:01:16 +00:00
|
|
|
})
|
2019-08-02 09:23:39 +00:00
|
|
|
}
|
2020-01-19 02:25:07 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lists_all_files_in_directories_from_stream() {
|
|
|
|
Playground::setup("ls_test_4", |dirs, sandbox| {
|
2020-01-22 03:56:12 +00:00
|
|
|
sandbox
|
|
|
|
.with_files(vec![EmptyFile("root1.txt"), EmptyFile("root2.txt")])
|
|
|
|
.within("dir_a")
|
|
|
|
.with_files(vec![
|
|
|
|
EmptyFile("yehuda.10.txt"),
|
|
|
|
EmptyFile("jonathan.10.txt"),
|
|
|
|
])
|
|
|
|
.within("dir_b")
|
|
|
|
.with_files(vec![
|
|
|
|
EmptyFile("andres.10.txt"),
|
|
|
|
EmptyFile("chicken_not_to_be_picked_up.100.txt"),
|
|
|
|
]);
|
2020-01-19 02:25:07 +00:00
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
echo dir_a dir_b
|
|
|
|
| ls $it
|
|
|
|
| count
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "4");
|
2020-01-19 02:25:07 +00:00
|
|
|
})
|
|
|
|
}
|
2020-02-01 08:34:34 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn does_not_fail_if_glob_matches_empty_directory() {
|
|
|
|
Playground::setup("ls_test_5", |dirs, sandbox| {
|
|
|
|
sandbox.within("dir_a");
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
ls dir_a
|
|
|
|
| count
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "0");
|
2020-02-01 08:34:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn fails_when_glob_doesnt_match() {
|
|
|
|
Playground::setup("ls_test_5", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![EmptyFile("root1.txt"), EmptyFile("root2.txt")]);
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
let actual = nu!(
|
2020-02-01 08:34:34 +00:00
|
|
|
cwd: dirs.test(),
|
|
|
|
"ls root3*"
|
|
|
|
);
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert!(actual.err.contains("no matches found"));
|
2020-02-01 08:34:34 +00:00
|
|
|
})
|
|
|
|
}
|
2020-04-06 11:28:56 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn list_files_from_two_parents_up_using_multiple_dots() {
|
|
|
|
Playground::setup("ls_test_6", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("yahuda.yaml"),
|
|
|
|
EmptyFile("jonathan.json"),
|
|
|
|
EmptyFile("andres.xml"),
|
|
|
|
EmptyFile("kevin.txt"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
sandbox.within("foo").mkdir("bar");
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test().join("foo/bar"),
|
|
|
|
r#"
|
|
|
|
ls ... | count | echo $it
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "5");
|
2020-04-06 11:28:56 +00:00
|
|
|
})
|
|
|
|
}
|
2020-07-04 20:17:36 +00:00
|
|
|
|
2020-08-22 01:49:34 +00:00
|
|
|
#[test]
|
|
|
|
fn lists_hidden_file_when_explicitly_specified() {
|
|
|
|
Playground::setup("ls_test_7", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
|
|
|
EmptyFile(".testdotfile"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
ls .testdotfile
|
|
|
|
| count
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lists_all_hidden_files_when_glob_contains_dot() {
|
|
|
|
Playground::setup("ls_test_8", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.with_files(vec![
|
|
|
|
EmptyFile("root1.txt"),
|
|
|
|
EmptyFile("root2.txt"),
|
|
|
|
EmptyFile(".dotfile1"),
|
|
|
|
])
|
|
|
|
.within("dir_a")
|
|
|
|
.with_files(vec![
|
|
|
|
EmptyFile("yehuda.10.txt"),
|
|
|
|
EmptyFile("jonathan.10.txt"),
|
|
|
|
EmptyFile(".dotfile2"),
|
|
|
|
])
|
|
|
|
.within("dir_b")
|
|
|
|
.with_files(vec![
|
|
|
|
EmptyFile("andres.10.txt"),
|
|
|
|
EmptyFile("chicken_not_to_be_picked_up.100.txt"),
|
|
|
|
EmptyFile(".dotfile3"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
ls **/.*
|
|
|
|
| count
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "3");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-09-04 19:32:58 +00:00
|
|
|
#[test]
|
|
|
|
// TODO Remove this cfg value when we have an OS-agnostic way
|
|
|
|
// of creating hidden files using the playground.
|
|
|
|
#[cfg(unix)]
|
|
|
|
fn lists_all_hidden_files_when_glob_does_not_contain_dot() {
|
|
|
|
Playground::setup("ls_test_8", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.with_files(vec![
|
|
|
|
EmptyFile("root1.txt"),
|
|
|
|
EmptyFile("root2.txt"),
|
|
|
|
EmptyFile(".dotfile1"),
|
|
|
|
])
|
|
|
|
.within("dir_a")
|
|
|
|
.with_files(vec![
|
|
|
|
EmptyFile("yehuda.10.txt"),
|
|
|
|
EmptyFile("jonathan.10.txt"),
|
|
|
|
EmptyFile(".dotfile2"),
|
|
|
|
])
|
|
|
|
.within(".dir_b")
|
|
|
|
.with_files(vec![
|
|
|
|
EmptyFile("andres.10.txt"),
|
|
|
|
EmptyFile("chicken_not_to_be_picked_up.100.txt"),
|
|
|
|
EmptyFile(".dotfile3"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
ls **/*
|
|
|
|
| count
|
|
|
|
| echo $it
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "5");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-04 20:17:36 +00:00
|
|
|
#[test]
|
|
|
|
fn list_all_columns() {
|
|
|
|
Playground::setup(
|
|
|
|
"ls_test_all_columns",
|
|
|
|
|dirs: Dirs, sandbox: &mut Playground| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("Leonardo.yaml"),
|
|
|
|
EmptyFile("Raphael.json"),
|
|
|
|
EmptyFile("Donatello.xml"),
|
|
|
|
EmptyFile("Michelangelo.txt"),
|
|
|
|
]);
|
|
|
|
// Normal Operation
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
|
|
|
"ls | get | to md"
|
|
|
|
);
|
|
|
|
let expected = ["name", "type", "size", "modified"].join("");
|
|
|
|
assert_eq!(actual.out, expected, "column names are incorrect for ls");
|
2020-08-01 18:30:45 +00:00
|
|
|
// Long
|
2020-07-04 20:17:36 +00:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
2020-08-01 18:30:45 +00:00
|
|
|
"ls -l | get | to md"
|
2020-07-04 20:17:36 +00:00
|
|
|
);
|
|
|
|
let expected = {
|
|
|
|
#[cfg(unix)]
|
|
|
|
{
|
|
|
|
[
|
2020-09-06 16:36:50 +00:00
|
|
|
"name",
|
|
|
|
"type",
|
|
|
|
"target",
|
|
|
|
"num_links",
|
|
|
|
"readonly",
|
|
|
|
"mode",
|
|
|
|
"uid",
|
|
|
|
"group",
|
|
|
|
"size",
|
|
|
|
"created",
|
|
|
|
"accessed",
|
|
|
|
"modified",
|
2020-07-04 20:17:36 +00:00
|
|
|
]
|
|
|
|
.join("")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
[
|
|
|
|
"name", "type", "target", "readonly", "size", "created", "accessed",
|
|
|
|
"modified",
|
|
|
|
]
|
|
|
|
.join("")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
assert_eq!(
|
|
|
|
actual.out, expected,
|
2020-08-01 18:30:45 +00:00
|
|
|
"column names are incorrect for ls long"
|
2020-07-04 20:17:36 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|