2019-12-17 18:54:39 +00:00
|
|
|
use nu_test_support::fs::Stub::EmptyFile;
|
2021-03-15 07:26:30 +00:00
|
|
|
use nu_test_support::playground::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"),
|
2023-03-15 05:54:55 +00:00
|
|
|
EmptyFile("jttxt"),
|
2019-10-15 10:16:47 +00:00
|
|
|
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
|
2021-03-13 21:46:40 +00:00
|
|
|
| length
|
2019-08-29 06:31:56 +00:00
|
|
|
"#
|
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
|
2021-03-13 21:46:40 +00:00
|
|
|
| length
|
2019-08-29 06:31:56 +00:00
|
|
|
"#
|
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"),
|
2023-03-15 05:54:55 +00:00
|
|
|
EmptyFile("jt.10.txt"),
|
2019-09-11 14:36:50 +00:00
|
|
|
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
|
2021-03-13 21:46:40 +00:00
|
|
|
| length
|
2019-08-29 06:31:56 +00:00
|
|
|
"#
|
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")
|
2023-03-15 05:54:55 +00:00
|
|
|
.with_files(vec![EmptyFile("yehuda.10.txt"), EmptyFile("jt10.txt")])
|
2020-01-22 03:56:12 +00:00
|
|
|
.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
|
2022-02-17 11:40:24 +00:00
|
|
|
| each { |it| ls $it }
|
2022-02-04 20:32:13 +00:00
|
|
|
| flatten | length
|
2020-01-19 02:25:07 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
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
|
2021-03-13 21:46:40 +00:00
|
|
|
| length
|
2020-02-01 08:34:34 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
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"),
|
2023-03-15 05:54:55 +00:00
|
|
|
EmptyFile("jtjson"),
|
2020-04-06 11:28:56 +00:00
|
|
|
EmptyFile("andres.xml"),
|
|
|
|
EmptyFile("kevin.txt"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
sandbox.within("foo").mkdir("bar");
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test().join("foo/bar"),
|
|
|
|
r#"
|
2021-03-13 21:46:40 +00:00
|
|
|
ls ... | length
|
2020-04-06 11:28:56 +00:00
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
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
|
2021-03-13 21:46:40 +00:00
|
|
|
| length
|
2020-08-22 01:49:34 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
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"),
|
2023-03-15 05:54:55 +00:00
|
|
|
EmptyFile("jt10.txt"),
|
2020-08-22 01:49:34 +00:00
|
|
|
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 **/.*
|
2021-03-13 21:46:40 +00:00
|
|
|
| length
|
2020-08-22 01:49:34 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
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"),
|
2023-03-15 05:54:55 +00:00
|
|
|
EmptyFile("jt10.txt"),
|
2020-09-04 19:32:58 +00:00
|
|
|
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 **/*
|
2021-03-13 21:46:40 +00:00
|
|
|
| length
|
2020-09-04 19:32:58 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "5");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-31 00:13:27 +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 glob_with_hidden_directory() {
|
|
|
|
Playground::setup("ls_test_8", |dirs, sandbox| {
|
|
|
|
sandbox.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 **/*
|
|
|
|
| length
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "");
|
|
|
|
assert!(actual.err.contains("No matches found"));
|
|
|
|
|
|
|
|
// will list files if provide `-a` flag.
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
ls -a **/*
|
|
|
|
| length
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "4");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-03-31 06:52:39 +00:00
|
|
|
#[test]
|
|
|
|
#[cfg(unix)]
|
|
|
|
fn fails_with_ls_to_dir_without_permission() {
|
|
|
|
Playground::setup("ls_test_1", |dirs, sandbox| {
|
2023-03-15 05:54:55 +00:00
|
|
|
sandbox
|
|
|
|
.within("dir_a")
|
|
|
|
.with_files(vec![EmptyFile("yehuda.11.txt"), EmptyFile("jt10.txt")]);
|
2021-03-31 06:52:39 +00:00
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
chmod 000 dir_a; ls dir_a
|
|
|
|
"#
|
|
|
|
));
|
2022-05-21 02:48:36 +00:00
|
|
|
|
|
|
|
let check_not_root = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
id -u
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
actual
|
|
|
|
.err
|
|
|
|
.contains("The permissions of 0 do not allow access for this user")
|
|
|
|
|| check_not_root.out == "0"
|
|
|
|
);
|
2021-03-31 06:52:39 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-09-21 07:56:37 +00:00
|
|
|
#[test]
|
|
|
|
fn lists_files_including_starting_with_dot() {
|
|
|
|
Playground::setup("ls_test_9", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("yehuda.txt"),
|
2023-03-15 05:54:55 +00:00
|
|
|
EmptyFile("jttxt"),
|
2020-09-21 07:56:37 +00:00
|
|
|
EmptyFile("andres.txt"),
|
|
|
|
EmptyFile(".hidden1.txt"),
|
|
|
|
EmptyFile(".hidden2.txt"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
ls -a
|
2021-03-13 21:46:40 +00:00
|
|
|
| length
|
2020-09-21 07:56:37 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "5");
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-04 20:17:36 +00:00
|
|
|
#[test]
|
|
|
|
fn list_all_columns() {
|
2021-03-15 07:26:30 +00:00
|
|
|
Playground::setup("ls_test_all_columns", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("Leonardo.yaml"),
|
|
|
|
EmptyFile("Raphael.json"),
|
|
|
|
EmptyFile("Donatello.xml"),
|
|
|
|
EmptyFile("Michelangelo.txt"),
|
|
|
|
]);
|
|
|
|
// Normal Operation
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
2022-02-04 20:32:13 +00:00
|
|
|
"ls | columns | to md"
|
2021-03-15 07:26:30 +00:00
|
|
|
);
|
|
|
|
let expected = ["name", "type", "size", "modified"].join("");
|
|
|
|
assert_eq!(actual.out, expected, "column names are incorrect for ls");
|
|
|
|
// Long
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(),
|
2022-02-04 20:32:13 +00:00
|
|
|
"ls -l | columns | to md"
|
2021-03-15 07:26:30 +00:00
|
|
|
);
|
|
|
|
let expected = {
|
|
|
|
#[cfg(unix)]
|
|
|
|
{
|
|
|
|
[
|
|
|
|
"name",
|
|
|
|
"type",
|
|
|
|
"target",
|
2022-02-04 02:01:45 +00:00
|
|
|
"readonly",
|
|
|
|
"mode",
|
2022-02-04 20:32:13 +00:00
|
|
|
"num_links",
|
|
|
|
"inode",
|
2023-06-11 16:02:08 +00:00
|
|
|
"user",
|
2021-03-15 07:26:30 +00:00
|
|
|
"group",
|
|
|
|
"size",
|
|
|
|
"created",
|
|
|
|
"accessed",
|
|
|
|
"modified",
|
|
|
|
]
|
|
|
|
.join("")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
[
|
|
|
|
"name", "type", "target", "readonly", "size", "created", "accessed", "modified",
|
|
|
|
]
|
|
|
|
.join("")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
assert_eq!(
|
|
|
|
actual.out, expected,
|
|
|
|
"column names are incorrect for ls long"
|
|
|
|
);
|
|
|
|
});
|
2020-07-04 20:17:36 +00:00
|
|
|
}
|
2022-06-03 16:37:27 +00:00
|
|
|
|
2022-07-08 19:15:34 +00:00
|
|
|
#[test]
|
|
|
|
fn lists_with_directory_flag() {
|
|
|
|
Playground::setup("ls_test_flag_directory_1", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.within("dir_files")
|
|
|
|
.with_files(vec![EmptyFile("nushell.json")])
|
|
|
|
.within("dir_empty");
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
cd dir_empty;
|
|
|
|
['.' '././.' '..' '../dir_files' '../dir_files/*']
|
|
|
|
| each { |it| ls --directory $it }
|
|
|
|
| flatten
|
|
|
|
| get name
|
|
|
|
| to text
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
let expected = [".", ".", "..", "../dir_files", "../dir_files/nushell.json"].join("");
|
|
|
|
#[cfg(windows)]
|
2022-08-11 16:54:54 +00:00
|
|
|
let expected = expected.replace('/', "\\");
|
2022-07-08 19:15:34 +00:00
|
|
|
assert_eq!(
|
|
|
|
actual.out, expected,
|
|
|
|
"column names are incorrect for ls --directory (-D)"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn lists_with_directory_flag_without_argument() {
|
|
|
|
Playground::setup("ls_test_flag_directory_2", |dirs, sandbox| {
|
|
|
|
sandbox
|
|
|
|
.within("dir_files")
|
|
|
|
.with_files(vec![EmptyFile("nushell.json")])
|
|
|
|
.within("dir_empty");
|
|
|
|
// Test if there are some files in the current directory
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
cd dir_files;
|
|
|
|
ls --directory
|
|
|
|
| get name
|
|
|
|
| to text
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
let expected = ".";
|
|
|
|
assert_eq!(
|
|
|
|
actual.out, expected,
|
|
|
|
"column names are incorrect for ls --directory (-D)"
|
|
|
|
);
|
|
|
|
// Test if there is no file in the current directory
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
|
|
|
cd dir_empty;
|
|
|
|
ls -D
|
|
|
|
| get name
|
|
|
|
| to text
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
let expected = ".";
|
|
|
|
assert_eq!(
|
|
|
|
actual.out, expected,
|
|
|
|
"column names are incorrect for ls --directory (-D)"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-06-03 16:37:27 +00:00
|
|
|
/// Rust's fs::metadata function is unable to read info for certain system files on Windows,
|
|
|
|
/// like the `C:\Windows\System32\Configuration` folder. https://github.com/rust-lang/rust/issues/96980
|
|
|
|
/// This test confirms that Nu can work around this successfully.
|
|
|
|
#[test]
|
|
|
|
#[cfg(windows)]
|
|
|
|
fn can_list_system_folder() {
|
|
|
|
// the awkward `ls Configuration* | where name == "Configuration"` thing is for speed;
|
|
|
|
// listing the entire System32 folder is slow and `ls Configuration*` alone
|
|
|
|
// might return more than 1 file someday
|
|
|
|
let file_type = nu!(
|
|
|
|
cwd: "C:\\Windows\\System32", pipeline(
|
|
|
|
r#"ls Configuration* | where name == "Configuration" | get type.0"#
|
|
|
|
));
|
|
|
|
assert_eq!(file_type.out, "dir");
|
|
|
|
|
|
|
|
let file_size = nu!(
|
|
|
|
cwd: "C:\\Windows\\System32", pipeline(
|
|
|
|
r#"ls Configuration* | where name == "Configuration" | get size.0"#
|
|
|
|
));
|
2023-01-15 02:03:32 +00:00
|
|
|
assert_ne!(file_size.out.trim(), "");
|
2022-06-03 16:37:27 +00:00
|
|
|
|
|
|
|
let file_modified = nu!(
|
|
|
|
cwd: "C:\\Windows\\System32", pipeline(
|
|
|
|
r#"ls Configuration* | where name == "Configuration" | get modified.0"#
|
|
|
|
));
|
2023-01-15 02:03:32 +00:00
|
|
|
assert_ne!(file_modified.out.trim(), "");
|
2022-06-03 16:37:27 +00:00
|
|
|
|
|
|
|
let file_accessed = nu!(
|
|
|
|
cwd: "C:\\Windows\\System32", pipeline(
|
|
|
|
r#"ls -l Configuration* | where name == "Configuration" | get accessed.0"#
|
|
|
|
));
|
2023-01-15 02:03:32 +00:00
|
|
|
assert_ne!(file_accessed.out.trim(), "");
|
2022-06-03 16:37:27 +00:00
|
|
|
|
|
|
|
let file_created = nu!(
|
|
|
|
cwd: "C:\\Windows\\System32", pipeline(
|
|
|
|
r#"ls -l Configuration* | where name == "Configuration" | get created.0"#
|
|
|
|
));
|
2023-01-15 02:03:32 +00:00
|
|
|
assert_ne!(file_created.out.trim(), "");
|
2022-06-03 16:37:27 +00:00
|
|
|
|
|
|
|
let ls_with_filter = nu!(
|
|
|
|
cwd: "C:\\Windows\\System32", pipeline(
|
|
|
|
r#"ls | where size > 10mb"#
|
|
|
|
));
|
|
|
|
assert_eq!(ls_with_filter.err, "");
|
|
|
|
}
|
2022-07-27 15:53:00 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn list_a_directory_not_exists() {
|
|
|
|
Playground::setup("ls_test_directory_not_exists", |dirs, _sandbox| {
|
|
|
|
let actual = nu!(cwd: dirs.test(), "ls a_directory_not_exists");
|
|
|
|
assert!(actual.err.contains("directory not found"));
|
|
|
|
})
|
|
|
|
}
|
2022-08-04 01:59:57 +00:00
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn list_directory_contains_invalid_utf8() {
|
|
|
|
use std::ffi::OsStr;
|
|
|
|
use std::os::unix::ffi::OsStrExt;
|
|
|
|
|
|
|
|
Playground::setup(
|
|
|
|
"ls_test_directory_contains_invalid_utf8",
|
|
|
|
|dirs, _sandbox| {
|
|
|
|
let v: [u8; 4] = [7, 196, 144, 188];
|
|
|
|
let s = OsStr::from_bytes(&v);
|
|
|
|
|
|
|
|
let cwd = dirs.test();
|
|
|
|
let path = cwd.join(s);
|
|
|
|
|
2022-11-04 20:11:17 +00:00
|
|
|
std::fs::create_dir_all(path).expect("failed to create directory");
|
2022-08-04 01:59:57 +00:00
|
|
|
|
2022-08-13 02:13:50 +00:00
|
|
|
let actual = nu!(cwd: cwd, "ls");
|
2022-08-04 01:59:57 +00:00
|
|
|
|
|
|
|
assert!(actual.out.contains("warning: get non-utf8 filename"));
|
|
|
|
assert!(actual.err.contains("No matches found for"));
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
2022-08-04 11:59:20 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn list_ignores_ansi() {
|
|
|
|
Playground::setup("ls_test_ansi", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
|
|
|
r#"
|
Restrict closure expression to be something like `{|| ...}` (#8290)
# Description
As title, closes: #7921 closes: #8273
# User-Facing Changes
when define a closure without pipe, nushell will raise error for now:
```
❯ let x = {ss ss}
Error: nu::parser::closure_missing_pipe
× Missing || inside closure
╭─[entry #2:1:1]
1 │ let x = {ss ss}
· ───┬───
· ╰── Parsing as a closure, but || is missing
╰────
help: Try add || to the beginning of closure
```
`any`, `each`, `all`, `where` command accepts closure, it forces user
input closure like `{||`, or parse error will returned.
```
❯ {major:2, minor:1, patch:4} | values | each { into string }
Error: nu::parser::closure_missing_pipe
× Missing || inside closure
╭─[entry #4:1:1]
1 │ {major:2, minor:1, patch:4} | values | each { into string }
· ───────┬───────
· ╰── Parsing as a closure, but || is missing
╰────
help: Try add || to the beginning of closure
```
`with-env`, `do`, `def`, `try` are special, they still remain the same,
although it says that it accepts a closure, but they don't need to be
written like `{||`, it's more likely a block but can capture variable
outside of scope:
```
❯ def test [input] { echo [0 1 2] | do { do { echo $input } } }; test aaa
aaa
```
Just realize that It's a big breaking change, we need to update config
and scripts...
# Tests + Formatting
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass
# After Submitting
If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
2023-03-17 12:36:28 +00:00
|
|
|
ls | find .txt | each {|| ls $in.name }
|
2022-08-04 11:59:20 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.is_empty());
|
|
|
|
})
|
|
|
|
}
|
2022-12-13 12:45:33 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn list_unknown_flag() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
ls -r
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("Available flags: --help(-h), --all(-a),"));
|
|
|
|
}
|