2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2016-03-25 21:25:52 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ls_ls() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!().succeeds();
|
2016-05-22 07:46:54 +00:00
|
|
|
}
|
2016-12-25 05:32:12 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ls_ls_i() {
|
|
|
|
new_ucmd!().arg("-i").succeeds();
|
|
|
|
new_ucmd!().arg("-il").succeeds();
|
|
|
|
}
|
ls: implement --color flag
GNU coreutils ls command implements the --color option as follow:
--color[=WHEN]
colorize the output; WHEN can be 'always' (default if omitted),
'auto', or 'never'
With --color=auto, ls emits color codes only when standard output is connected
to a terminal.
Also, add support for the following aliases:
- ‘always’, ‘yes’, ‘force’
- ‘never’, ‘no’, ‘none’
- ‘auto’, ‘tty’, ‘if-tty’
Signed-off-by: Gabriel Ganne <gabriel.ganne@gmail.com>
2019-06-20 07:55:01 +00:00
|
|
|
|
2020-12-13 11:09:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_ls_non_existing() {
|
|
|
|
new_ucmd!().arg("doesntexist").fails();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ls_files_dirs() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
at.mkdir("a");
|
|
|
|
at.mkdir("a/b");
|
|
|
|
at.mkdir("a/b/c");
|
|
|
|
at.mkdir("z");
|
|
|
|
at.touch(&at.plus_as_string("a/a"));
|
|
|
|
at.touch(&at.plus_as_string("a/b/b"));
|
|
|
|
|
|
|
|
scene.ucmd().arg("a").succeeds();
|
|
|
|
scene.ucmd().arg("a/a").succeeds();
|
|
|
|
scene.ucmd().arg("a").arg("z").succeeds();
|
|
|
|
|
|
|
|
let result = scene.ucmd().arg("doesntexist").fails();
|
|
|
|
// Doesn't exist
|
|
|
|
assert!(result
|
|
|
|
.stderr
|
|
|
|
.contains("error: 'doesntexist': No such file or directory"));
|
|
|
|
|
|
|
|
let result = scene.ucmd().arg("a").arg("doesntexist").fails();
|
|
|
|
// One exists, the other doesn't
|
|
|
|
assert!(result
|
|
|
|
.stderr
|
|
|
|
.contains("error: 'doesntexist': No such file or directory"));
|
|
|
|
assert!(result.stdout.contains("a:"));
|
|
|
|
}
|
|
|
|
|
2020-12-13 11:22:31 +00:00
|
|
|
#[test]
|
|
|
|
fn test_ls_recursive() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
let at = &scene.fixtures;
|
|
|
|
at.mkdir("a");
|
|
|
|
at.mkdir("a/b");
|
|
|
|
at.mkdir("a/b/c");
|
|
|
|
at.mkdir("z");
|
|
|
|
at.touch(&at.plus_as_string("a/a"));
|
|
|
|
at.touch(&at.plus_as_string("a/b/b"));
|
|
|
|
|
|
|
|
scene.ucmd().arg("a").succeeds();
|
|
|
|
scene.ucmd().arg("a/a").succeeds();
|
|
|
|
let result = scene
|
|
|
|
.ucmd()
|
|
|
|
.arg("--color=never")
|
|
|
|
.arg("-R")
|
|
|
|
.arg("a")
|
|
|
|
.arg("z")
|
|
|
|
.succeeds();
|
|
|
|
|
|
|
|
println!("stderr = {:?}", result.stderr);
|
|
|
|
println!("stdout = {:?}", result.stdout);
|
|
|
|
if cfg!(target_os = "windows") {
|
|
|
|
assert!(result.stdout.contains("a\\b:\nb"));
|
|
|
|
} else {
|
|
|
|
assert!(result.stdout.contains("a/b:\nb"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
ls: implement --color flag
GNU coreutils ls command implements the --color option as follow:
--color[=WHEN]
colorize the output; WHEN can be 'always' (default if omitted),
'auto', or 'never'
With --color=auto, ls emits color codes only when standard output is connected
to a terminal.
Also, add support for the following aliases:
- ‘always’, ‘yes’, ‘force’
- ‘never’, ‘no’, ‘none’
- ‘auto’, ‘tty’, ‘if-tty’
Signed-off-by: Gabriel Ganne <gabriel.ganne@gmail.com>
2019-06-20 07:55:01 +00:00
|
|
|
#[test]
|
|
|
|
fn test_ls_ls_color() {
|
|
|
|
new_ucmd!().arg("--color").succeeds();
|
|
|
|
new_ucmd!().arg("--color=always").succeeds();
|
|
|
|
new_ucmd!().arg("--color=never").succeeds();
|
|
|
|
}
|