mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-17 04:06:18 +00:00
Merge branch 'master' into chgrp/no-err
This commit is contained in:
commit
a7797c01c0
39 changed files with 1361 additions and 1359 deletions
|
@ -1,5 +1,4 @@
|
|||
use crate::common::util::*;
|
||||
#[cfg(unix)]
|
||||
use std::fs::OpenOptions;
|
||||
#[cfg(unix)]
|
||||
use std::io::Read;
|
||||
|
@ -274,6 +273,26 @@ fn test_stdin_show_ends() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn squeeze_all_files() {
|
||||
// empty lines at the end of a file are "squeezed" together with empty lines at the beginning
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.write("input1", "a\n\n");
|
||||
at.write("input2", "\n\nb");
|
||||
ucmd.args(&["input1", "input2", "-s"])
|
||||
.succeeds()
|
||||
.stdout_only("a\n\nb");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_show_ends_crlf() {
|
||||
new_ucmd!()
|
||||
.arg("-E")
|
||||
.pipe_in("a\nb\r\n\rc\n\r\n\r")
|
||||
.succeeds()
|
||||
.stdout_only("a$\nb^M$\n\rc$\n^M$\n\r");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stdin_show_all() {
|
||||
for same_param in &["-A", "--show-all"] {
|
||||
|
@ -443,3 +462,49 @@ fn test_domain_socket() {
|
|||
|
||||
thread.join().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_to_self_empty() {
|
||||
// it's ok if the input file is also the output file if it's empty
|
||||
let s = TestScenario::new(util_name!());
|
||||
let file_path = s.fixtures.plus("file.txt");
|
||||
|
||||
let file = OpenOptions::new()
|
||||
.create_new(true)
|
||||
.write(true)
|
||||
.append(true)
|
||||
.open(&file_path)
|
||||
.unwrap();
|
||||
|
||||
s.ucmd().set_stdout(file).arg(&file_path).succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_to_self() {
|
||||
let s = TestScenario::new(util_name!());
|
||||
let file_path = s.fixtures.plus("first_file");
|
||||
s.fixtures.write("second_file", "second_file_content.");
|
||||
|
||||
let file = OpenOptions::new()
|
||||
.create_new(true)
|
||||
.write(true)
|
||||
.append(true)
|
||||
.open(&file_path)
|
||||
.unwrap();
|
||||
|
||||
s.fixtures.append("first_file", "first_file_content.");
|
||||
|
||||
s.ucmd()
|
||||
.set_stdout(file)
|
||||
.arg("first_file")
|
||||
.arg("first_file")
|
||||
.arg("second_file")
|
||||
.fails()
|
||||
.code_is(2)
|
||||
.stderr_only("cat: first_file: input file is output file\ncat: first_file: input file is output file");
|
||||
|
||||
assert_eq!(
|
||||
s.fixtures.read("first_file"),
|
||||
"first_file_content.second_file_content."
|
||||
);
|
||||
}
|
||||
|
|
|
@ -244,3 +244,10 @@ fn basic_succeeds() {
|
|||
.no_stderr();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_no_change() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.touch("file");
|
||||
ucmd.arg("").arg(at.plus("file")).succeeds();
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@ use std::os::windows::fs::symlink_file;
|
|||
use filetime::FileTime;
|
||||
#[cfg(target_os = "linux")]
|
||||
use rlimit::Resource;
|
||||
#[cfg(not(windows))]
|
||||
use std::env;
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::fs as std_fs;
|
||||
#[cfg(target_os = "linux")]
|
||||
|
@ -743,20 +741,16 @@ fn test_cp_deref_folder_to_folder() {
|
|||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let cwd = env::current_dir().unwrap();
|
||||
let path_to_new_symlink = at.plus(TEST_COPY_FROM_FOLDER);
|
||||
|
||||
let path_to_new_symlink = at.subdir.join(TEST_COPY_FROM_FOLDER);
|
||||
|
||||
// Change the cwd to have a correct symlink
|
||||
assert!(env::set_current_dir(&path_to_new_symlink).is_ok());
|
||||
|
||||
#[cfg(not(windows))]
|
||||
let _r = fs::symlink(TEST_HELLO_WORLD_SOURCE, TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
||||
#[cfg(windows)]
|
||||
let _r = symlink_file(TEST_HELLO_WORLD_SOURCE, TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
||||
|
||||
// Back to the initial cwd (breaks the other tests)
|
||||
assert!(env::set_current_dir(&cwd).is_ok());
|
||||
at.symlink_file(
|
||||
&path_to_new_symlink
|
||||
.join(TEST_HELLO_WORLD_SOURCE)
|
||||
.to_string_lossy(),
|
||||
&path_to_new_symlink
|
||||
.join(TEST_HELLO_WORLD_SOURCE_SYMLINK)
|
||||
.to_string_lossy(),
|
||||
);
|
||||
|
||||
//using -P -R option
|
||||
scene
|
||||
|
@ -843,20 +837,16 @@ fn test_cp_no_deref_folder_to_folder() {
|
|||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let cwd = env::current_dir().unwrap();
|
||||
let path_to_new_symlink = at.plus(TEST_COPY_FROM_FOLDER);
|
||||
|
||||
let path_to_new_symlink = at.subdir.join(TEST_COPY_FROM_FOLDER);
|
||||
|
||||
// Change the cwd to have a correct symlink
|
||||
assert!(env::set_current_dir(&path_to_new_symlink).is_ok());
|
||||
|
||||
#[cfg(not(windows))]
|
||||
let _r = fs::symlink(TEST_HELLO_WORLD_SOURCE, TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
||||
#[cfg(windows)]
|
||||
let _r = symlink_file(TEST_HELLO_WORLD_SOURCE, TEST_HELLO_WORLD_SOURCE_SYMLINK);
|
||||
|
||||
// Back to the initial cwd (breaks the other tests)
|
||||
assert!(env::set_current_dir(&cwd).is_ok());
|
||||
at.symlink_file(
|
||||
&path_to_new_symlink
|
||||
.join(TEST_HELLO_WORLD_SOURCE)
|
||||
.to_string_lossy(),
|
||||
&path_to_new_symlink
|
||||
.join(TEST_HELLO_WORLD_SOURCE_SYMLINK)
|
||||
.to_string_lossy(),
|
||||
);
|
||||
|
||||
//using -P -R option
|
||||
scene
|
||||
|
@ -969,10 +959,9 @@ fn test_cp_archive() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "unix")]
|
||||
#[cfg(unix)]
|
||||
fn test_cp_archive_recursive() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
let cwd = env::current_dir().unwrap();
|
||||
|
||||
// creates
|
||||
// dir/1
|
||||
|
@ -988,26 +977,13 @@ fn test_cp_archive_recursive() {
|
|||
at.touch(&file_1.to_string_lossy());
|
||||
at.touch(&file_2.to_string_lossy());
|
||||
|
||||
// Change the cwd to have a correct symlink
|
||||
assert!(env::set_current_dir(&at.subdir.join(TEST_COPY_TO_FOLDER)).is_ok());
|
||||
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let _r = fs::symlink("1", &file_1_link);
|
||||
let _r = fs::symlink("2", &file_2_link);
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let _r = symlink_file("1", &file_1_link);
|
||||
let _r = symlink_file("2", &file_2_link);
|
||||
}
|
||||
// Back to the initial cwd (breaks the other tests)
|
||||
assert!(env::set_current_dir(&cwd).is_ok());
|
||||
at.symlink_file("1", &file_1_link.to_string_lossy());
|
||||
at.symlink_file("2", &file_2_link.to_string_lossy());
|
||||
|
||||
ucmd.arg("--archive")
|
||||
.arg(TEST_COPY_TO_FOLDER)
|
||||
.arg(TEST_COPY_TO_FOLDER_NEW)
|
||||
.fails(); // fails for now
|
||||
.succeeds();
|
||||
|
||||
let scene2 = TestScenario::new("ls");
|
||||
let result = scene2
|
||||
|
@ -1025,18 +1001,6 @@ fn test_cp_archive_recursive() {
|
|||
.run();
|
||||
|
||||
println!("ls dest {}", result.stdout_str());
|
||||
assert!(at.file_exists(
|
||||
&at.subdir
|
||||
.join(TEST_COPY_TO_FOLDER_NEW)
|
||||
.join("1.link")
|
||||
.to_string_lossy()
|
||||
));
|
||||
assert!(at.file_exists(
|
||||
&at.subdir
|
||||
.join(TEST_COPY_TO_FOLDER_NEW)
|
||||
.join("2.link")
|
||||
.to_string_lossy()
|
||||
));
|
||||
assert!(at.file_exists(
|
||||
&at.subdir
|
||||
.join(TEST_COPY_TO_FOLDER_NEW)
|
||||
|
|
|
@ -8,7 +8,10 @@
|
|||
|
||||
// spell-checker:ignore (methods) hexdigest
|
||||
|
||||
use tempfile::TempDir;
|
||||
|
||||
use crate::common::util::*;
|
||||
use std::fs::OpenOptions;
|
||||
use std::time::SystemTime;
|
||||
|
||||
#[path = "../../src/uu/factor/sieve.rs"]
|
||||
|
@ -24,6 +27,43 @@ use self::sieve::Sieve;
|
|||
const NUM_PRIMES: usize = 10000;
|
||||
const NUM_TESTS: usize = 100;
|
||||
|
||||
#[test]
|
||||
fn test_parallel() {
|
||||
// factor should only flush the buffer at line breaks
|
||||
let n_integers = 100_000;
|
||||
let mut input_string = String::new();
|
||||
for i in 0..=n_integers {
|
||||
input_string.push_str(&(format!("{} ", i))[..]);
|
||||
}
|
||||
|
||||
let tmp_dir = TempDir::new().unwrap();
|
||||
let tmp_dir = AtPath::new(tmp_dir.path());
|
||||
tmp_dir.touch("output");
|
||||
let output = OpenOptions::new()
|
||||
.append(true)
|
||||
.open(tmp_dir.plus("output"))
|
||||
.unwrap();
|
||||
|
||||
for mut child in (0..10)
|
||||
.map(|_| {
|
||||
new_ucmd!()
|
||||
.set_stdout(output.try_clone().unwrap())
|
||||
.pipe_in(input_string.clone())
|
||||
.run_no_wait()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
{
|
||||
assert_eq!(child.wait().unwrap().code().unwrap(), 0);
|
||||
}
|
||||
|
||||
let result = TestScenario::new(util_name!())
|
||||
.ccmd("sort")
|
||||
.arg(tmp_dir.plus("output"))
|
||||
.succeeds();
|
||||
let hash_check = sha1::Sha1::from(result.stdout()).hexdigest();
|
||||
assert_eq!(hash_check, "cc743607c0ff300ff575d92f4ff0c87d5660c393");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_first_100000_integers() {
|
||||
extern crate sha1;
|
||||
|
|
|
@ -128,6 +128,7 @@ fn test_ls_width() {
|
|||
scene
|
||||
.ucmd()
|
||||
.args(&option.split(' ').collect::<Vec<_>>())
|
||||
.arg("-C")
|
||||
.succeeds()
|
||||
.stdout_only("test-width-1 test-width-2 test-width-3 test-width-4\n");
|
||||
}
|
||||
|
@ -136,30 +137,33 @@ fn test_ls_width() {
|
|||
scene
|
||||
.ucmd()
|
||||
.args(&option.split(' ').collect::<Vec<_>>())
|
||||
.arg("-C")
|
||||
.succeeds()
|
||||
.stdout_only("test-width-1 test-width-3\ntest-width-2 test-width-4\n");
|
||||
}
|
||||
|
||||
for option in &[
|
||||
"-w 25",
|
||||
"-w=25",
|
||||
"--width=25",
|
||||
"--width 25",
|
||||
"-w 0",
|
||||
"-w=0",
|
||||
"--width=0",
|
||||
"--width 0",
|
||||
] {
|
||||
for option in &["-w 25", "-w=25", "--width=25", "--width 25"] {
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&option.split(' ').collect::<Vec<_>>())
|
||||
.arg("-C")
|
||||
.succeeds()
|
||||
.stdout_only("test-width-1\ntest-width-2\ntest-width-3\ntest-width-4\n");
|
||||
}
|
||||
|
||||
for option in &["-w 0", "-w=0", "--width=0", "--width 0"] {
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&option.split(' ').collect::<Vec<_>>())
|
||||
.arg("-C")
|
||||
.succeeds()
|
||||
.stdout_only("test-width-1 test-width-2 test-width-3 test-width-4\n");
|
||||
}
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-w=bad")
|
||||
.arg("-C")
|
||||
.fails()
|
||||
.stderr_contains("invalid line width");
|
||||
|
||||
|
@ -167,6 +171,7 @@ fn test_ls_width() {
|
|||
scene
|
||||
.ucmd()
|
||||
.args(&option.split(' ').collect::<Vec<_>>())
|
||||
.arg("-C")
|
||||
.fails()
|
||||
.stderr_only("ls: invalid line width: '1a'");
|
||||
}
|
||||
|
@ -184,16 +189,10 @@ fn test_ls_columns() {
|
|||
// Columns is the default
|
||||
let result = scene.ucmd().succeeds();
|
||||
|
||||
#[cfg(not(windows))]
|
||||
result.stdout_only("test-columns-1\ntest-columns-2\ntest-columns-3\ntest-columns-4\n");
|
||||
#[cfg(windows)]
|
||||
result.stdout_only("test-columns-1 test-columns-2 test-columns-3 test-columns-4\n");
|
||||
|
||||
for option in &["-C", "--format=columns"] {
|
||||
let result = scene.ucmd().arg(option).succeeds();
|
||||
#[cfg(not(windows))]
|
||||
result.stdout_only("test-columns-1\ntest-columns-2\ntest-columns-3\ntest-columns-4\n");
|
||||
#[cfg(windows)]
|
||||
result.stdout_only("test-columns-1 test-columns-2 test-columns-3 test-columns-4\n");
|
||||
}
|
||||
|
||||
|
@ -205,6 +204,38 @@ fn test_ls_columns() {
|
|||
.succeeds()
|
||||
.stdout_only("test-columns-1 test-columns-3\ntest-columns-2 test-columns-4\n");
|
||||
}
|
||||
|
||||
// On windows we are always able to get the terminal size, so we can't simulate falling back to the
|
||||
// environment variable.
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
for option in &["-C", "--format=columns"] {
|
||||
scene
|
||||
.ucmd()
|
||||
.env("COLUMNS", "40")
|
||||
.arg(option)
|
||||
.succeeds()
|
||||
.stdout_only("test-columns-1 test-columns-3\ntest-columns-2 test-columns-4\n");
|
||||
}
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.env("COLUMNS", "garbage")
|
||||
.arg("-C")
|
||||
.succeeds()
|
||||
.stdout_is("test-columns-1 test-columns-2 test-columns-3 test-columns-4\n")
|
||||
.stderr_is("ls: ignoring invalid width in environment variable COLUMNS: 'garbage'");
|
||||
}
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-Cw0")
|
||||
.succeeds()
|
||||
.stdout_only("test-columns-1 test-columns-2 test-columns-3 test-columns-4\n");
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-mw0")
|
||||
.succeeds()
|
||||
.stdout_only("test-columns-1, test-columns-2, test-columns-3, test-columns-4\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -220,11 +251,7 @@ fn test_ls_across() {
|
|||
let result = scene.ucmd().arg(option).succeeds();
|
||||
// Because the test terminal has width 0, this is the same output as
|
||||
// the columns option.
|
||||
if cfg!(unix) {
|
||||
result.stdout_only("test-across-1\ntest-across-2\ntest-across-3\ntest-across-4\n");
|
||||
} else {
|
||||
result.stdout_only("test-across-1 test-across-2 test-across-3 test-across-4\n");
|
||||
}
|
||||
result.stdout_only("test-across-1 test-across-2 test-across-3 test-across-4\n");
|
||||
}
|
||||
|
||||
for option in &["-x", "--format=across"] {
|
||||
|
@ -250,11 +277,7 @@ fn test_ls_commas() {
|
|||
|
||||
for option in &["-m", "--format=commas"] {
|
||||
let result = scene.ucmd().arg(option).succeeds();
|
||||
if cfg!(unix) {
|
||||
result.stdout_only("test-commas-1,\ntest-commas-2,\ntest-commas-3,\ntest-commas-4\n");
|
||||
} else {
|
||||
result.stdout_only("test-commas-1, test-commas-2, test-commas-3, test-commas-4\n");
|
||||
}
|
||||
result.stdout_only("test-commas-1, test-commas-2, test-commas-3, test-commas-4\n");
|
||||
}
|
||||
|
||||
for option in &["-m", "--format=commas"] {
|
||||
|
@ -571,13 +594,11 @@ fn test_ls_sort_name() {
|
|||
at.touch("test-1");
|
||||
at.touch("test-2");
|
||||
|
||||
let sep = if cfg!(unix) { "\n" } else { " " };
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("--sort=name")
|
||||
.succeeds()
|
||||
.stdout_is(["test-1", "test-2", "test-3\n"].join(sep));
|
||||
.stdout_is("test-1\ntest-2\ntest-3\n");
|
||||
|
||||
let scene_dot = TestScenario::new(util_name!());
|
||||
let at = &scene_dot.fixtures;
|
||||
|
@ -591,7 +612,7 @@ fn test_ls_sort_name() {
|
|||
.arg("--sort=name")
|
||||
.arg("-A")
|
||||
.succeeds()
|
||||
.stdout_is([".a", ".b", "a", "b\n"].join(sep));
|
||||
.stdout_is(".a\n.b\na\nb\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -612,28 +633,16 @@ fn test_ls_order_size() {
|
|||
scene.ucmd().arg("-al").succeeds();
|
||||
|
||||
let result = scene.ucmd().arg("-S").succeeds();
|
||||
#[cfg(not(windows))]
|
||||
result.stdout_only("test-4\ntest-3\ntest-2\ntest-1\n");
|
||||
#[cfg(windows)]
|
||||
result.stdout_only("test-4 test-3 test-2 test-1\n");
|
||||
|
||||
let result = scene.ucmd().arg("-S").arg("-r").succeeds();
|
||||
#[cfg(not(windows))]
|
||||
result.stdout_only("test-1\ntest-2\ntest-3\ntest-4\n");
|
||||
#[cfg(windows)]
|
||||
result.stdout_only("test-1 test-2 test-3 test-4\n");
|
||||
|
||||
let result = scene.ucmd().arg("--sort=size").succeeds();
|
||||
#[cfg(not(windows))]
|
||||
result.stdout_only("test-4\ntest-3\ntest-2\ntest-1\n");
|
||||
#[cfg(windows)]
|
||||
result.stdout_only("test-4 test-3 test-2 test-1\n");
|
||||
|
||||
let result = scene.ucmd().arg("--sort=size").arg("-r").succeeds();
|
||||
#[cfg(not(windows))]
|
||||
result.stdout_only("test-1\ntest-2\ntest-3\ntest-4\n");
|
||||
#[cfg(windows)]
|
||||
result.stdout_only("test-1 test-2 test-3 test-4\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -755,9 +764,6 @@ fn test_ls_styles() {
|
|||
|
||||
at.touch("test2");
|
||||
let result = scene.ucmd().arg("--full-time").arg("-x").succeeds();
|
||||
#[cfg(not(windows))]
|
||||
assert_eq!(result.stdout_str(), "test\ntest2\n");
|
||||
#[cfg(windows)]
|
||||
assert_eq!(result.stdout_str(), "test test2\n");
|
||||
}
|
||||
|
||||
|
@ -794,28 +800,16 @@ fn test_ls_order_time() {
|
|||
|
||||
// ctime was changed at write, so the order is 4 3 2 1
|
||||
let result = scene.ucmd().arg("-t").succeeds();
|
||||
#[cfg(not(windows))]
|
||||
result.stdout_only("test-4\ntest-3\ntest-2\ntest-1\n");
|
||||
#[cfg(windows)]
|
||||
result.stdout_only("test-4 test-3 test-2 test-1\n");
|
||||
|
||||
let result = scene.ucmd().arg("--sort=time").succeeds();
|
||||
#[cfg(not(windows))]
|
||||
result.stdout_only("test-4\ntest-3\ntest-2\ntest-1\n");
|
||||
#[cfg(windows)]
|
||||
result.stdout_only("test-4 test-3 test-2 test-1\n");
|
||||
|
||||
let result = scene.ucmd().arg("-tr").succeeds();
|
||||
#[cfg(not(windows))]
|
||||
result.stdout_only("test-1\ntest-2\ntest-3\ntest-4\n");
|
||||
#[cfg(windows)]
|
||||
result.stdout_only("test-1 test-2 test-3 test-4\n");
|
||||
|
||||
let result = scene.ucmd().arg("--sort=time").arg("-r").succeeds();
|
||||
#[cfg(not(windows))]
|
||||
result.stdout_only("test-1\ntest-2\ntest-3\ntest-4\n");
|
||||
#[cfg(windows)]
|
||||
result.stdout_only("test-1 test-2 test-3 test-4\n");
|
||||
|
||||
// 3 was accessed last in the read
|
||||
// So the order should be 2 3 4 1
|
||||
|
@ -826,19 +820,11 @@ fn test_ls_order_time() {
|
|||
|
||||
// It seems to be dependent on the platform whether the access time is actually set
|
||||
if file3_access > file4_access {
|
||||
if cfg!(not(windows)) {
|
||||
result.stdout_only("test-3\ntest-4\ntest-2\ntest-1\n");
|
||||
} else {
|
||||
result.stdout_only("test-3 test-4 test-2 test-1\n");
|
||||
}
|
||||
result.stdout_only("test-3\ntest-4\ntest-2\ntest-1\n");
|
||||
} else {
|
||||
// Access time does not seem to be set on Windows and some other
|
||||
// systems so the order is 4 3 2 1
|
||||
if cfg!(not(windows)) {
|
||||
result.stdout_only("test-4\ntest-3\ntest-2\ntest-1\n");
|
||||
} else {
|
||||
result.stdout_only("test-4 test-3 test-2 test-1\n");
|
||||
}
|
||||
result.stdout_only("test-4\ntest-3\ntest-2\ntest-1\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -991,6 +977,7 @@ fn test_ls_color() {
|
|||
.ucmd()
|
||||
.arg("--color")
|
||||
.arg("-w=15")
|
||||
.arg("-C")
|
||||
.succeeds()
|
||||
.stdout_only(format!(
|
||||
"{} test-color\nb {}\n",
|
||||
|
@ -2009,11 +1996,7 @@ fn test_ls_path() {
|
|||
};
|
||||
scene.ucmd().arg(&abs_path).run().stdout_is(expected_stdout);
|
||||
|
||||
let expected_stdout = if cfg!(windows) {
|
||||
format!("{} {}\n", path, file1)
|
||||
} else {
|
||||
format!("{}\n{}\n", path, file1)
|
||||
};
|
||||
let expected_stdout = format!("{}\n{}\n", path, file1);
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(file1)
|
||||
|
|
|
@ -46,6 +46,17 @@ fn test_file() {
|
|||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_is(unindent(ALPHA_OUT));
|
||||
|
||||
// Ensure that default format matches `-t o2`, and that `-t` does not absorb file argument
|
||||
new_ucmd!()
|
||||
.arg("--endian=little")
|
||||
.arg("-t")
|
||||
.arg("o2")
|
||||
.arg(file.as_os_str())
|
||||
.succeeds()
|
||||
.no_stderr()
|
||||
.stdout_is(unindent(ALPHA_OUT));
|
||||
|
||||
let _ = remove_file(file);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,41 +68,36 @@ fn test_with_numbering_option_with_number_width() {
|
|||
fn test_with_long_header_option() {
|
||||
let test_file_path = "test_one_page.log";
|
||||
let expected_test_file_path = "test_one_page_header.log.expected";
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
let header = "new file";
|
||||
scenario
|
||||
.args(&["--header=new file", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(
|
||||
expected_test_file_path,
|
||||
&[("{last_modified_time}", &value), ("{header}", header)],
|
||||
);
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["-h", header, test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(
|
||||
expected_test_file_path,
|
||||
&[("{last_modified_time}", &value), ("{header}", header)],
|
||||
);
|
||||
for args in &[&["-h", header][..], &["--header=new file"][..]] {
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
.args(args)
|
||||
.arg(test_file_path)
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(
|
||||
expected_test_file_path,
|
||||
&[("{last_modified_time}", &value), ("{header}", header)],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_double_space_option() {
|
||||
let test_file_path = "test_one_page.log";
|
||||
let expected_test_file_path = "test_one_page_double_line.log.expected";
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
.args(&["-d", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["--double-space", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
|
||||
for &arg in &["-d", "--double-space"] {
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
.args(&[arg, test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(
|
||||
expected_test_file_path,
|
||||
&[("{last_modified_time}", &value)],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -188,33 +183,28 @@ fn test_with_page_range() {
|
|||
let test_file_path = "test.log";
|
||||
let expected_test_file_path = "test_page_range_1.log.expected";
|
||||
let expected_test_file_path1 = "test_page_range_2.log.expected";
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
.args(&["--pages=15", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["+15", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["--pages=15:17", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(
|
||||
expected_test_file_path1,
|
||||
&[("{last_modified_time}", &value)],
|
||||
);
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["+15:17", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(
|
||||
expected_test_file_path1,
|
||||
&[("{last_modified_time}", &value)],
|
||||
);
|
||||
for &arg in &["--pages=15", "+15"] {
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
.args(&[arg, test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(
|
||||
expected_test_file_path,
|
||||
&[("{last_modified_time}", &value)],
|
||||
);
|
||||
}
|
||||
for &arg in &["--pages=15:17", "+15:17"] {
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
.args(&[arg, test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(
|
||||
expected_test_file_path1,
|
||||
&[("{last_modified_time}", &value)],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -232,19 +222,17 @@ fn test_with_no_header_trailer_option() {
|
|||
#[test]
|
||||
fn test_with_page_length_option() {
|
||||
let test_file_path = "test.log";
|
||||
let expected_test_file_path = "test_page_length.log.expected";
|
||||
let expected_test_file_path1 = "test_page_length1.log.expected";
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
.args(&["--pages=2:3", "-l", "100", "-n", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["--pages=2:3", "-l", "5", "-n", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_fixture(expected_test_file_path1);
|
||||
for (arg, expected) in &[
|
||||
("100", "test_page_length.log.expected"),
|
||||
("5", "test_page_length1.log.expected"),
|
||||
] {
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
.args(&["--pages=2:3", "-l", arg, "-n", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(expected, &[("{last_modified_time}", &value)]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -277,17 +265,17 @@ fn test_with_stdin() {
|
|||
fn test_with_column() {
|
||||
let test_file_path = "column.log";
|
||||
let expected_test_file_path = "column.log.expected";
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
.args(&["--pages=3:5", "--column=3", "-n", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["--pages=3:5", "-3", "-n", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
|
||||
for arg in &["-3", "--column=3"] {
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
.args(&["--pages=3:5", arg, "-n", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(
|
||||
expected_test_file_path,
|
||||
&[("{last_modified_time}", &value)],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -305,36 +293,17 @@ fn test_with_column_across_option() {
|
|||
#[test]
|
||||
fn test_with_column_across_option_and_column_separator() {
|
||||
let test_file_path = "column.log";
|
||||
let expected_test_file_path = "column_across_sep.log.expected";
|
||||
let expected_test_file_path1 = "column_across_sep1.log.expected";
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
.args(&[
|
||||
"--pages=3:5",
|
||||
"--column=3",
|
||||
"-s|",
|
||||
"-a",
|
||||
"-n",
|
||||
test_file_path,
|
||||
])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(expected_test_file_path, &[("{last_modified_time}", &value)]);
|
||||
|
||||
new_ucmd!()
|
||||
.args(&[
|
||||
"--pages=3:5",
|
||||
"--column=3",
|
||||
"-Sdivide",
|
||||
"-a",
|
||||
"-n",
|
||||
test_file_path,
|
||||
])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(
|
||||
expected_test_file_path1,
|
||||
&[("{last_modified_time}", &value)],
|
||||
);
|
||||
for (arg, expected) in &[
|
||||
("-s|", "column_across_sep.log.expected"),
|
||||
("-Sdivide", "column_across_sep1.log.expected"),
|
||||
] {
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
.args(&["--pages=3:5", "--column=3", arg, "-a", "-n", test_file_path])
|
||||
.succeeds()
|
||||
.stdout_is_templated_fixture(expected, &[("{last_modified_time}", &value)]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue