mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-16 03:36:18 +00:00
Merge branch 'main' into tail_notify
This commit is contained in:
commit
7228902e55
196 changed files with 3582 additions and 1752 deletions
|
@ -5,7 +5,7 @@ authors = ["nicoo <nicoo@debian.org>"]
|
|||
license = "MIT"
|
||||
description = "Benchmarks for the uu_factor integer factorization tool"
|
||||
homepage = "https://github.com/uutils/coreutils"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
uu_factor = { path = "../../../src/uu/factor" }
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use array_init::array_init;
|
||||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
|
||||
use std::convert::TryInto;
|
||||
use uu_factor::{table::*, Factors};
|
||||
|
||||
fn table(c: &mut Criterion) {
|
||||
|
|
|
@ -34,7 +34,7 @@ fn test_base32_encode_file() {
|
|||
|
||||
#[test]
|
||||
fn test_decode() {
|
||||
for decode_param in &["-d", "--decode", "--dec"] {
|
||||
for decode_param in ["-d", "--decode", "--dec"] {
|
||||
let input = "JBSWY3DPFQQFO33SNRSCC===\n"; // spell-checker:disable-line
|
||||
new_ucmd!()
|
||||
.arg(decode_param)
|
||||
|
@ -56,7 +56,7 @@ fn test_garbage() {
|
|||
|
||||
#[test]
|
||||
fn test_ignore_garbage() {
|
||||
for ignore_garbage_param in &["-i", "--ignore-garbage", "--ig"] {
|
||||
for ignore_garbage_param in ["-i", "--ignore-garbage", "--ig"] {
|
||||
let input = "JBSWY\x013DPFQ\x02QFO33SNRSCC===\n"; // spell-checker:disable-line
|
||||
new_ucmd!()
|
||||
.arg("-d")
|
||||
|
@ -69,7 +69,7 @@ fn test_ignore_garbage() {
|
|||
|
||||
#[test]
|
||||
fn test_wrap() {
|
||||
for wrap_param in &["-w", "--wrap", "--wr"] {
|
||||
for wrap_param in ["-w", "--wrap", "--wr"] {
|
||||
let input = "The quick brown fox jumps over the lazy dog.";
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
|
@ -84,7 +84,7 @@ fn test_wrap() {
|
|||
|
||||
#[test]
|
||||
fn test_wrap_no_arg() {
|
||||
for wrap_param in &["-w", "--wrap"] {
|
||||
for wrap_param in ["-w", "--wrap"] {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let expected_stderr = &format!(
|
||||
"error: The argument '--wrap <wrap>\' requires a value but none was \
|
||||
|
@ -102,7 +102,7 @@ fn test_wrap_no_arg() {
|
|||
|
||||
#[test]
|
||||
fn test_wrap_bad_arg() {
|
||||
for wrap_param in &["-w", "--wrap"] {
|
||||
for wrap_param in ["-w", "--wrap"] {
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
.arg("b")
|
||||
|
|
|
@ -26,7 +26,7 @@ fn test_base64_encode_file() {
|
|||
|
||||
#[test]
|
||||
fn test_decode() {
|
||||
for decode_param in &["-d", "--decode", "--dec"] {
|
||||
for decode_param in ["-d", "--decode", "--dec"] {
|
||||
let input = "aGVsbG8sIHdvcmxkIQ=="; // spell-checker:disable-line
|
||||
new_ucmd!()
|
||||
.arg(decode_param)
|
||||
|
@ -48,7 +48,7 @@ fn test_garbage() {
|
|||
|
||||
#[test]
|
||||
fn test_ignore_garbage() {
|
||||
for ignore_garbage_param in &["-i", "--ignore-garbage", "--ig"] {
|
||||
for ignore_garbage_param in ["-i", "--ignore-garbage", "--ig"] {
|
||||
let input = "aGVsbG8sIHdvcmxkIQ==\0"; // spell-checker:disable-line
|
||||
new_ucmd!()
|
||||
.arg("-d")
|
||||
|
@ -61,7 +61,7 @@ fn test_ignore_garbage() {
|
|||
|
||||
#[test]
|
||||
fn test_wrap() {
|
||||
for wrap_param in &["-w", "--wrap", "--wr"] {
|
||||
for wrap_param in ["-w", "--wrap", "--wr"] {
|
||||
let input = "The quick brown fox jumps over the lazy dog.";
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
|
@ -75,7 +75,7 @@ fn test_wrap() {
|
|||
|
||||
#[test]
|
||||
fn test_wrap_no_arg() {
|
||||
for wrap_param in &["-w", "--wrap"] {
|
||||
for wrap_param in ["-w", "--wrap"] {
|
||||
new_ucmd!().arg(wrap_param).fails().stderr_contains(
|
||||
&"The argument '--wrap <wrap>' requires a value but none was supplied",
|
||||
);
|
||||
|
@ -84,7 +84,7 @@ fn test_wrap_no_arg() {
|
|||
|
||||
#[test]
|
||||
fn test_wrap_bad_arg() {
|
||||
for wrap_param in &["-w", "--wrap"] {
|
||||
for wrap_param in ["-w", "--wrap"] {
|
||||
new_ucmd!()
|
||||
.arg(wrap_param)
|
||||
.arg("b")
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::ffi::OsStr;
|
|||
|
||||
#[test]
|
||||
fn test_help() {
|
||||
for help_flg in &["-h", "--help"] {
|
||||
for help_flg in ["-h", "--help"] {
|
||||
new_ucmd!()
|
||||
.arg(&help_flg)
|
||||
.succeeds()
|
||||
|
@ -17,7 +17,7 @@ fn test_help() {
|
|||
|
||||
#[test]
|
||||
fn test_version() {
|
||||
for version_flg in &["-V", "--version"] {
|
||||
for version_flg in ["-V", "--version"] {
|
||||
assert!(new_ucmd!()
|
||||
.arg(&version_flg)
|
||||
.succeeds()
|
||||
|
@ -61,7 +61,7 @@ fn test_do_not_remove_suffix() {
|
|||
|
||||
#[test]
|
||||
fn test_multiple_param() {
|
||||
for &multiple_param in &["-a", "--multiple", "--mul"] {
|
||||
for multiple_param in ["-a", "--multiple", "--mul"] {
|
||||
let path = "/foo/bar/baz";
|
||||
new_ucmd!()
|
||||
.args(&[multiple_param, path, path])
|
||||
|
@ -72,7 +72,7 @@ fn test_multiple_param() {
|
|||
|
||||
#[test]
|
||||
fn test_suffix_param() {
|
||||
for &suffix_param in &["-s", "--suffix", "--suf"] {
|
||||
for suffix_param in ["-s", "--suffix", "--suf"] {
|
||||
let path = "/foo/bar/baz.exe";
|
||||
new_ucmd!()
|
||||
.args(&[suffix_param, ".exe", path, path])
|
||||
|
@ -83,7 +83,7 @@ fn test_suffix_param() {
|
|||
|
||||
#[test]
|
||||
fn test_zero_param() {
|
||||
for &zero_param in &["-z", "--zero", "--ze"] {
|
||||
for zero_param in ["-z", "--zero", "--ze"] {
|
||||
let path = "/foo/bar/baz";
|
||||
new_ucmd!()
|
||||
.args(&[zero_param, "-a", path, path])
|
||||
|
|
|
@ -19,7 +19,7 @@ fn test_output_simple() {
|
|||
#[test]
|
||||
fn test_no_options() {
|
||||
// spell-checker:disable-next-line
|
||||
for fixture in &["empty.txt", "alpha.txt", "nonewline.txt"] {
|
||||
for fixture in ["empty.txt", "alpha.txt", "nonewline.txt"] {
|
||||
// Give fixture through command line file argument
|
||||
new_ucmd!()
|
||||
.args(&[fixture])
|
||||
|
@ -36,7 +36,7 @@ fn test_no_options() {
|
|||
#[test]
|
||||
#[cfg(any(target_vendor = "apple", target_os = "linux", target_os = "android"))]
|
||||
fn test_no_options_big_input() {
|
||||
for &n in &[
|
||||
for n in [
|
||||
0,
|
||||
1,
|
||||
42,
|
||||
|
@ -114,7 +114,7 @@ fn test_closes_file_descriptors() {
|
|||
fn test_piped_to_regular_file() {
|
||||
use std::fs::read_to_string;
|
||||
|
||||
for &append in &[true, false] {
|
||||
for append in [true, false] {
|
||||
let s = TestScenario::new(util_name!());
|
||||
let file_path = s.fixtures.plus("file.txt");
|
||||
|
||||
|
@ -139,7 +139,7 @@ fn test_piped_to_regular_file() {
|
|||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_piped_to_dev_null() {
|
||||
for &append in &[true, false] {
|
||||
for append in [true, false] {
|
||||
let s = TestScenario::new(util_name!());
|
||||
{
|
||||
let dev_null = OpenOptions::new()
|
||||
|
@ -159,7 +159,7 @@ fn test_piped_to_dev_null() {
|
|||
#[test]
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))]
|
||||
fn test_piped_to_dev_full() {
|
||||
for &append in &[true, false] {
|
||||
for append in [true, false] {
|
||||
let s = TestScenario::new(util_name!());
|
||||
{
|
||||
let dev_full = OpenOptions::new()
|
||||
|
@ -192,7 +192,7 @@ fn test_directory_and_file() {
|
|||
let s = TestScenario::new(util_name!());
|
||||
s.fixtures.mkdir("test_directory2");
|
||||
// spell-checker:disable-next-line
|
||||
for fixture in &["empty.txt", "alpha.txt", "nonewline.txt"] {
|
||||
for fixture in ["empty.txt", "alpha.txt", "nonewline.txt"] {
|
||||
s.ucmd()
|
||||
.args(&["test_directory2", fixture])
|
||||
.fails()
|
||||
|
@ -264,7 +264,7 @@ fn test_numbered_lines_no_trailing_newline() {
|
|||
|
||||
#[test]
|
||||
fn test_stdin_show_nonprinting() {
|
||||
for same_param in &["-v", "--show-nonprinting", "--show-non"] {
|
||||
for same_param in ["-v", "--show-nonprinting", "--show-non"] {
|
||||
new_ucmd!()
|
||||
.args(&[same_param])
|
||||
.pipe_in("\t\0\n")
|
||||
|
@ -275,7 +275,7 @@ fn test_stdin_show_nonprinting() {
|
|||
|
||||
#[test]
|
||||
fn test_stdin_show_tabs() {
|
||||
for same_param in &["-T", "--show-tabs", "--show-ta"] {
|
||||
for same_param in ["-T", "--show-tabs", "--show-ta"] {
|
||||
new_ucmd!()
|
||||
.args(&[same_param])
|
||||
.pipe_in("\t\0\n")
|
||||
|
@ -286,7 +286,7 @@ fn test_stdin_show_tabs() {
|
|||
|
||||
#[test]
|
||||
fn test_stdin_show_ends() {
|
||||
for &same_param in &["-E", "--show-ends", "--show-e"] {
|
||||
for same_param in ["-E", "--show-ends", "--show-e"] {
|
||||
new_ucmd!()
|
||||
.args(&[same_param, "-"])
|
||||
.pipe_in("\t\0\n\t")
|
||||
|
@ -317,7 +317,7 @@ fn test_show_ends_crlf() {
|
|||
|
||||
#[test]
|
||||
fn test_stdin_show_all() {
|
||||
for same_param in &["-A", "--show-all", "--show-a"] {
|
||||
for same_param in ["-A", "--show-all", "--show-a"] {
|
||||
new_ucmd!()
|
||||
.args(&[same_param])
|
||||
.pipe_in("\t\0\n")
|
||||
|
@ -346,7 +346,7 @@ fn test_stdin_nonprinting_and_tabs() {
|
|||
|
||||
#[test]
|
||||
fn test_stdin_squeeze_blank() {
|
||||
for same_param in &["-s", "--squeeze-blank", "--squeeze"] {
|
||||
for same_param in ["-s", "--squeeze-blank", "--squeeze"] {
|
||||
new_ucmd!()
|
||||
.arg(same_param)
|
||||
.pipe_in("\n\na\n\n\n\n\nb\n\n\n")
|
||||
|
@ -358,7 +358,7 @@ fn test_stdin_squeeze_blank() {
|
|||
#[test]
|
||||
fn test_stdin_number_non_blank() {
|
||||
// spell-checker:disable-next-line
|
||||
for same_param in &["-b", "--number-nonblank", "--number-non"] {
|
||||
for same_param in ["-b", "--number-nonblank", "--number-non"] {
|
||||
new_ucmd!()
|
||||
.arg(same_param)
|
||||
.arg("-")
|
||||
|
@ -371,7 +371,7 @@ fn test_stdin_number_non_blank() {
|
|||
#[test]
|
||||
fn test_non_blank_overrides_number() {
|
||||
// spell-checker:disable-next-line
|
||||
for &same_param in &["-b", "--number-nonblank"] {
|
||||
for same_param in ["-b", "--number-nonblank"] {
|
||||
new_ucmd!()
|
||||
.args(&[same_param, "-"])
|
||||
.pipe_in("\na\nb\n\n\nc")
|
||||
|
@ -382,7 +382,7 @@ fn test_non_blank_overrides_number() {
|
|||
|
||||
#[test]
|
||||
fn test_squeeze_blank_before_numbering() {
|
||||
for &same_param in &["-s", "--squeeze-blank"] {
|
||||
for same_param in ["-s", "--squeeze-blank"] {
|
||||
new_ucmd!()
|
||||
.args(&[same_param, "-n", "-"])
|
||||
.pipe_in("a\n\n\nb")
|
||||
|
|
|
@ -23,7 +23,7 @@ fn help() {
|
|||
|
||||
#[test]
|
||||
fn reference_errors() {
|
||||
for args in &[
|
||||
for args in [
|
||||
&["--verbose", "--reference"] as &[&str],
|
||||
&["--verbose", "--reference=/dev/null"],
|
||||
&["--verbose", "--reference=/inexistent", "/dev/null"],
|
||||
|
@ -34,7 +34,7 @@ fn reference_errors() {
|
|||
|
||||
#[test]
|
||||
fn recursive_errors() {
|
||||
for args in &[
|
||||
for args in [
|
||||
&["--verbose", "-P"] as &[&str],
|
||||
&["--verbose", "-H"],
|
||||
&["--verbose", "-L"],
|
||||
|
|
|
@ -60,7 +60,7 @@ fn test_1() {
|
|||
#[test]
|
||||
fn test_fail_silently() {
|
||||
if get_effective_gid() != 0 {
|
||||
for opt in &["-f", "--silent", "--quiet", "--sil", "--qui"] {
|
||||
for opt in ["-f", "--silent", "--quiet", "--sil", "--qui"] {
|
||||
new_ucmd!()
|
||||
.arg(opt)
|
||||
.arg("bin")
|
||||
|
@ -74,7 +74,7 @@ fn test_fail_silently() {
|
|||
#[test]
|
||||
fn test_preserve_root() {
|
||||
// It's weird that on OS X, `realpath /etc/..` returns '/private'
|
||||
for d in &[
|
||||
for d in [
|
||||
"/",
|
||||
"/////tmp///../../../../",
|
||||
"../../../../../../../../../../../../../../",
|
||||
|
@ -92,7 +92,7 @@ fn test_preserve_root() {
|
|||
#[test]
|
||||
fn test_preserve_root_symlink() {
|
||||
let file = "test_chgrp_symlink2root";
|
||||
for d in &[
|
||||
for d in [
|
||||
"/",
|
||||
"////tmp//../../../../",
|
||||
"..//../../..//../..//../../../../../../../../",
|
||||
|
@ -299,7 +299,7 @@ fn test_traverse_symlinks() {
|
|||
}
|
||||
let (first_group, second_group) = (groups[0], groups[1]);
|
||||
|
||||
for &(args, traverse_first, traverse_second) in &[
|
||||
for (args, traverse_first, traverse_second) in [
|
||||
(&[][..] as &[&str], false, false),
|
||||
(&["-H"][..], true, false),
|
||||
(&["-P"][..], false, false),
|
||||
|
|
|
@ -532,7 +532,7 @@ fn test_chmod_strip_minus_from_mode() {
|
|||
|
||||
#[test]
|
||||
fn test_chmod_keep_setgid() {
|
||||
for &(from, arg, to) in &[
|
||||
for (from, arg, to) in [
|
||||
(0o7777, "777", 0o46777),
|
||||
(0o7777, "=777", 0o40777),
|
||||
(0o7777, "0777", 0o46777),
|
||||
|
|
|
@ -76,7 +76,7 @@ fn output_delimiter_require_arg() {
|
|||
#[cfg_attr(not(feature = "test_unimplemented"), ignore)]
|
||||
#[test]
|
||||
fn zero_terminated() {
|
||||
for ¶m in &["-z", "--zero-terminated"] {
|
||||
for param in ["-z", "--zero-terminated"] {
|
||||
new_ucmd!()
|
||||
.args(&[param, "a", "b"])
|
||||
.fails()
|
||||
|
|
|
@ -1469,7 +1469,7 @@ fn test_canonicalize_symlink() {
|
|||
|
||||
#[test]
|
||||
fn test_copy_through_just_created_symlink() {
|
||||
for &create_t in &[true, false] {
|
||||
for create_t in [true, false] {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.mkdir("a");
|
||||
at.mkdir("b");
|
||||
|
@ -1606,7 +1606,7 @@ fn test_cp_dir_vs_file() {
|
|||
fn test_cp_overriding_arguments() {
|
||||
let s = TestScenario::new(util_name!());
|
||||
s.fixtures.touch("file1");
|
||||
for (arg1, arg2) in &[
|
||||
for (arg1, arg2) in [
|
||||
#[cfg(not(windows))]
|
||||
("--remove-destination", "--force"),
|
||||
#[cfg(not(windows))]
|
||||
|
|
|
@ -41,7 +41,7 @@ static COMPLEX_SEQUENCE: &TestedSequence = &TestedSequence {
|
|||
|
||||
#[test]
|
||||
fn test_byte_sequence() {
|
||||
for ¶m in &["-b", "--bytes", "--byt"] {
|
||||
for param in ["-b", "--bytes", "--byt"] {
|
||||
for example_seq in EXAMPLE_SEQUENCES {
|
||||
new_ucmd!()
|
||||
.args(&[param, example_seq.sequence, INPUT])
|
||||
|
@ -53,7 +53,7 @@ fn test_byte_sequence() {
|
|||
|
||||
#[test]
|
||||
fn test_char_sequence() {
|
||||
for ¶m in &["-c", "--characters", "--char"] {
|
||||
for param in ["-c", "--characters", "--char"] {
|
||||
for example_seq in EXAMPLE_SEQUENCES {
|
||||
//as of coreutils 8.25 a char range is effectively the same as a byte range; there is no distinct treatment of utf8 chars.
|
||||
new_ucmd!()
|
||||
|
@ -66,7 +66,7 @@ fn test_char_sequence() {
|
|||
|
||||
#[test]
|
||||
fn test_field_sequence() {
|
||||
for ¶m in &["-f", "--fields", "--fie"] {
|
||||
for param in ["-f", "--fields", "--fie"] {
|
||||
for example_seq in EXAMPLE_SEQUENCES {
|
||||
new_ucmd!()
|
||||
.args(&[param, example_seq.sequence, INPUT])
|
||||
|
@ -78,7 +78,7 @@ fn test_field_sequence() {
|
|||
|
||||
#[test]
|
||||
fn test_specify_delimiter() {
|
||||
for ¶m in &["-d", "--delimiter", "--del"] {
|
||||
for param in ["-d", "--delimiter", "--del"] {
|
||||
new_ucmd!()
|
||||
.args(&[param, ":", "-f", COMPLEX_SEQUENCE.sequence, INPUT])
|
||||
.succeeds()
|
||||
|
@ -115,7 +115,7 @@ fn test_output_delimiter() {
|
|||
|
||||
#[test]
|
||||
fn test_complement() {
|
||||
for param in &["--complement", "--com"] {
|
||||
for param in ["--complement", "--com"] {
|
||||
new_ucmd!()
|
||||
.args(&["-d_", param, "-f", "2"])
|
||||
.pipe_in("9_1\n8_2\n7_3")
|
||||
|
@ -135,7 +135,7 @@ fn test_zero_terminated() {
|
|||
|
||||
#[test]
|
||||
fn test_only_delimited() {
|
||||
for param in &["-s", "--only-delimited", "--only-del"] {
|
||||
for param in ["-s", "--only-delimited", "--only-del"] {
|
||||
new_ucmd!()
|
||||
.args(&["-d_", param, "-f", "1"])
|
||||
.pipe_in("91\n82\n7_3")
|
||||
|
|
|
@ -7,7 +7,7 @@ use rust_users::*;
|
|||
|
||||
#[test]
|
||||
fn test_date_email() {
|
||||
for param in &["--rfc-email", "--rfc-e", "-R"] {
|
||||
for param in ["--rfc-email", "--rfc-e", "-R"] {
|
||||
new_ucmd!().arg(param).succeeds();
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ fn test_date_rfc_3339() {
|
|||
let re = Regex::new(rfc_regexp).unwrap();
|
||||
|
||||
// Check that the output matches the regexp
|
||||
for param in &["--rfc-3339", "--rfc-3"] {
|
||||
for param in ["--rfc-3339", "--rfc-3"] {
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(format!("{}=ns", param))
|
||||
|
@ -40,21 +40,21 @@ fn test_date_rfc_3339() {
|
|||
|
||||
#[test]
|
||||
fn test_date_rfc_8601() {
|
||||
for param in &["--iso-8601", "--i"] {
|
||||
for param in ["--iso-8601", "--i"] {
|
||||
new_ucmd!().arg(format!("{}=ns", param)).succeeds();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_rfc_8601_second() {
|
||||
for param in &["--iso-8601", "--i"] {
|
||||
for param in ["--iso-8601", "--i"] {
|
||||
new_ucmd!().arg(format!("{}=second", param)).succeeds();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_utc() {
|
||||
for param in &["--universal", "--utc", "--uni", "--u"] {
|
||||
for param in ["--universal", "--utc", "--uni", "--u"] {
|
||||
new_ucmd!().arg(param).succeeds();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -463,7 +463,7 @@ fn test_zeros_to_stdout() {
|
|||
#[cfg(target_pointer_width = "32")]
|
||||
#[test]
|
||||
fn test_oversized_bs_32_bit() {
|
||||
for bs_param in &["bs", "ibs", "obs", "cbs"] {
|
||||
for bs_param in ["bs", "ibs", "obs", "cbs"] {
|
||||
new_ucmd!()
|
||||
.args(&[format!("{}=5GB", bs_param)])
|
||||
.run()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// spell-checker:ignore udev pcent
|
||||
// spell-checker:ignore udev pcent iuse itotal iused ipcent
|
||||
use crate::common::util::*;
|
||||
|
||||
#[test]
|
||||
|
@ -26,18 +26,117 @@ fn test_df_compatible_si() {
|
|||
new_ucmd!().arg("-aH").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_arguments_override_themselves() {
|
||||
new_ucmd!().args(&["--help", "--help"]).succeeds();
|
||||
new_ucmd!().arg("-aa").succeeds();
|
||||
new_ucmd!()
|
||||
.args(&["--block-size=3000", "--block-size=1000"])
|
||||
.succeeds();
|
||||
new_ucmd!().args(&["--total", "--total"]).succeeds();
|
||||
new_ucmd!().arg("-hh").succeeds();
|
||||
new_ucmd!().arg("-HH").succeeds();
|
||||
new_ucmd!().arg("-ii").succeeds();
|
||||
new_ucmd!().arg("-kk").succeeds();
|
||||
new_ucmd!().arg("-ll").succeeds();
|
||||
new_ucmd!().args(&["--no-sync", "--no-sync"]).succeeds();
|
||||
new_ucmd!().arg("-PP").succeeds();
|
||||
new_ucmd!().args(&["--sync", "--sync"]).succeeds();
|
||||
new_ucmd!().arg("-TT").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_conflicts_overriding() {
|
||||
new_ucmd!().arg("-hH").succeeds();
|
||||
new_ucmd!().arg("-Hh").succeeds();
|
||||
new_ucmd!().args(&["--no-sync", "--sync"]).succeeds();
|
||||
new_ucmd!().args(&["--sync", "--no-sync"]).succeeds();
|
||||
new_ucmd!().args(&["-k", "--block-size=3000"]).succeeds();
|
||||
new_ucmd!().args(&["--block-size=3000", "-k"]).succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_output_arg() {
|
||||
new_ucmd!().args(&["--output=source", "-iPT"]).fails();
|
||||
new_ucmd!().args(&["-iPT", "--output=source"]).fails();
|
||||
new_ucmd!()
|
||||
.args(&["--output=source", "--output=source"])
|
||||
.fails();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_output() {
|
||||
// TODO These should fail because `-total` should have two dashes,
|
||||
// not just one. But they don't fail.
|
||||
if cfg!(target_os = "macos") {
|
||||
new_ucmd!().arg("-H").arg("-total").succeeds().
|
||||
stdout_only("Filesystem Size Used Available Capacity Use% Mounted on \n");
|
||||
let expected = if cfg!(target_os = "macos") {
|
||||
vec![
|
||||
"Filesystem",
|
||||
"Size",
|
||||
"Used",
|
||||
"Available",
|
||||
"Capacity",
|
||||
"Use%",
|
||||
"Mounted",
|
||||
"on",
|
||||
]
|
||||
} else {
|
||||
new_ucmd!().arg("-H").arg("-total").succeeds().stdout_only(
|
||||
"Filesystem Size Used Available Use% Mounted on \n",
|
||||
);
|
||||
}
|
||||
vec![
|
||||
"Filesystem",
|
||||
"Size",
|
||||
"Used",
|
||||
"Available",
|
||||
"Use%",
|
||||
"Mounted",
|
||||
"on",
|
||||
]
|
||||
};
|
||||
let output = new_ucmd!()
|
||||
.arg("-H")
|
||||
.arg("--total")
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
let actual = output.lines().take(1).collect::<Vec<&str>>()[0];
|
||||
let actual = actual.split_whitespace().collect::<Vec<_>>();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_df_output_overridden() {
|
||||
let expected = if cfg!(target_os = "macos") {
|
||||
vec![
|
||||
"Filesystem",
|
||||
"Size",
|
||||
"Used",
|
||||
"Available",
|
||||
"Capacity",
|
||||
"Use%",
|
||||
"Mounted",
|
||||
"on",
|
||||
]
|
||||
} else {
|
||||
vec![
|
||||
"Filesystem",
|
||||
"Size",
|
||||
"Used",
|
||||
"Available",
|
||||
"Use%",
|
||||
"Mounted",
|
||||
"on",
|
||||
]
|
||||
};
|
||||
let output = new_ucmd!()
|
||||
.arg("-hH")
|
||||
.arg("--total")
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
let actual = output.lines().take(1).collect::<Vec<&str>>()[0];
|
||||
let actual = actual.split_whitespace().collect::<Vec<_>>();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_total_option_with_single_dash() {
|
||||
// These should fail because `-total` should have two dashes,
|
||||
// not just one.
|
||||
new_ucmd!().arg("-total").fails();
|
||||
}
|
||||
|
||||
/// Test that the order of rows in the table does not change across executions.
|
||||
|
@ -87,7 +186,17 @@ fn test_output_option_without_equals_sign() {
|
|||
|
||||
#[test]
|
||||
fn test_type_option() {
|
||||
new_ucmd!().args(&["-t", "ext4", "-t", "ext3"]).succeeds();
|
||||
let fs_types = new_ucmd!()
|
||||
.arg("--output=fstype")
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
let fs_type = fs_types.lines().nth(1).unwrap().trim();
|
||||
|
||||
new_ucmd!().args(&["-t", fs_type]).succeeds();
|
||||
new_ucmd!()
|
||||
.args(&["-t", fs_type, "-t", "nonexisting"])
|
||||
.succeeds();
|
||||
new_ucmd!().args(&["-t", "nonexisting"]).fails();
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -95,6 +204,21 @@ fn test_exclude_type_option() {
|
|||
new_ucmd!().args(&["-x", "ext4", "-x", "ext3"]).succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_include_exclude_same_type() {
|
||||
new_ucmd!()
|
||||
.args(&["-t", "ext4", "-x", "ext4"])
|
||||
.fails()
|
||||
.stderr_is("df: file system type 'ext4' both selected and excluded");
|
||||
new_ucmd!()
|
||||
.args(&["-t", "ext4", "-x", "ext4", "-t", "ext3", "-x", "ext3"])
|
||||
.fails()
|
||||
.stderr_is(
|
||||
"df: file system type 'ext4' both selected and excluded\n\
|
||||
df: file system type 'ext3' both selected and excluded",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_total() {
|
||||
// Example output:
|
||||
|
@ -162,6 +286,36 @@ fn test_use_percentage() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_iuse_percentage() {
|
||||
let output = new_ucmd!()
|
||||
.args(&["--total", "--output=itotal,iused,ipcent"])
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
|
||||
// Skip the header line.
|
||||
let lines: Vec<&str> = output.lines().skip(1).collect();
|
||||
|
||||
for line in lines {
|
||||
let mut iter = line.split_whitespace();
|
||||
let reported_inodes = iter.next().unwrap().parse::<f64>().unwrap();
|
||||
let reported_iused = iter.next().unwrap().parse::<f64>().unwrap();
|
||||
let reported_percentage = iter.next().unwrap();
|
||||
|
||||
if reported_percentage == "-" {
|
||||
assert_eq!(0.0, reported_inodes);
|
||||
assert_eq!(0.0, reported_iused);
|
||||
} else {
|
||||
let reported_percentage = reported_percentage[..reported_percentage.len() - 1]
|
||||
.parse::<u8>()
|
||||
.unwrap();
|
||||
let computed_percentage = (100.0 * (reported_iused / reported_inodes)).ceil() as u8;
|
||||
|
||||
assert_eq!(computed_percentage, reported_percentage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_block_size_1024() {
|
||||
fn get_header(block_size: u64) -> String {
|
||||
|
@ -189,23 +343,26 @@ fn test_block_size_1024() {
|
|||
assert_eq!(get_header(34 * 1024 * 1024 * 1024), "34G-blocks");
|
||||
}
|
||||
|
||||
// TODO The spacing does not match GNU df. Also we need to remove
|
||||
// trailing spaces from the heading row.
|
||||
#[test]
|
||||
fn test_output_selects_columns() {
|
||||
let output = new_ucmd!()
|
||||
.args(&["--output=source"])
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
assert_eq!(output.lines().next().unwrap(), "Filesystem ");
|
||||
assert_eq!(output.lines().next().unwrap().trim_end(), "Filesystem");
|
||||
|
||||
let output = new_ucmd!()
|
||||
.args(&["--output=source,target"])
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
assert_eq!(
|
||||
output.lines().next().unwrap(),
|
||||
"Filesystem Mounted on "
|
||||
output
|
||||
.lines()
|
||||
.next()
|
||||
.unwrap()
|
||||
.split_whitespace()
|
||||
.collect::<Vec<_>>(),
|
||||
vec!["Filesystem", "Mounted", "on"]
|
||||
);
|
||||
|
||||
let output = new_ucmd!()
|
||||
|
@ -213,8 +370,13 @@ fn test_output_selects_columns() {
|
|||
.succeeds()
|
||||
.stdout_move_str();
|
||||
assert_eq!(
|
||||
output.lines().next().unwrap(),
|
||||
"Filesystem Mounted on Used "
|
||||
output
|
||||
.lines()
|
||||
.next()
|
||||
.unwrap()
|
||||
.split_whitespace()
|
||||
.collect::<Vec<_>>(),
|
||||
vec!["Filesystem", "Mounted", "on", "Used"]
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -225,12 +387,16 @@ fn test_output_multiple_occurrences() {
|
|||
.succeeds()
|
||||
.stdout_move_str();
|
||||
assert_eq!(
|
||||
output.lines().next().unwrap(),
|
||||
"Filesystem Mounted on "
|
||||
output
|
||||
.lines()
|
||||
.next()
|
||||
.unwrap()
|
||||
.split_whitespace()
|
||||
.collect::<Vec<_>>(),
|
||||
vec!["Filesystem", "Mounted", "on"]
|
||||
);
|
||||
}
|
||||
|
||||
// TODO Fix the spacing.
|
||||
#[test]
|
||||
fn test_output_file_all_filesystems() {
|
||||
// When run with no positional arguments, `df` lets "-" represent
|
||||
|
@ -240,13 +406,12 @@ fn test_output_file_all_filesystems() {
|
|||
.succeeds()
|
||||
.stdout_move_str();
|
||||
let mut lines = output.lines();
|
||||
assert_eq!(lines.next().unwrap(), "File ");
|
||||
assert_eq!(lines.next().unwrap(), "File");
|
||||
for line in lines {
|
||||
assert_eq!(line, "- ");
|
||||
assert_eq!(line, "- ");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Fix the spacing.
|
||||
#[test]
|
||||
fn test_output_file_specific_files() {
|
||||
// Create three files.
|
||||
|
@ -262,15 +427,7 @@ fn test_output_file_specific_files() {
|
|||
.succeeds()
|
||||
.stdout_move_str();
|
||||
let actual: Vec<&str> = output.lines().collect();
|
||||
assert_eq!(
|
||||
actual,
|
||||
vec![
|
||||
"File ",
|
||||
"a ",
|
||||
"b ",
|
||||
"c "
|
||||
]
|
||||
);
|
||||
assert_eq!(actual, vec!["File", "a ", "b ", "c "]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -280,3 +437,16 @@ fn test_output_field_no_more_than_once() {
|
|||
.fails()
|
||||
.usage_error("option --output: field 'target' used more than once");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nonexistent_file() {
|
||||
new_ucmd!()
|
||||
.arg("does-not-exist")
|
||||
.fails()
|
||||
.stderr_only("df: does-not-exist: No such file or directory");
|
||||
new_ucmd!()
|
||||
.args(&["--output=file", "does-not-exist", "."])
|
||||
.fails()
|
||||
.stderr_is("df: does-not-exist: No such file or directory\n")
|
||||
.stdout_is("File\n. \n");
|
||||
}
|
||||
|
|
55
tests/by-util/test_dir.rs
Normal file
55
tests/by-util/test_dir.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
#[cfg(not(windows))]
|
||||
extern crate libc;
|
||||
extern crate regex;
|
||||
#[cfg(not(windows))]
|
||||
extern crate tempfile;
|
||||
#[cfg(unix)]
|
||||
extern crate unix_socket;
|
||||
|
||||
use self::regex::Regex;
|
||||
use crate::common::util::*;
|
||||
|
||||
/*
|
||||
* As dir use the same functions than ls, we don't have to retest them here.
|
||||
* We just test the default and the long output
|
||||
*/
|
||||
|
||||
#[test]
|
||||
fn test_dir() {
|
||||
new_ucmd!().succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_output() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.mkdir("some-dir1");
|
||||
at.touch("some-file1");
|
||||
|
||||
scene.ucmd().succeeds().stdout_contains("some-file1");
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.succeeds()
|
||||
.stdout_does_not_match(&Regex::new("[rwx][^some-file1]").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_long_output() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.mkdir("some-dir1");
|
||||
at.touch("some-file1");
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-l")
|
||||
.succeeds()
|
||||
.stdout_contains("some-file1");
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-l")
|
||||
.succeeds()
|
||||
.stdout_matches(&Regex::new("[rwx][^some-file1]").unwrap());
|
||||
}
|
|
@ -3,7 +3,11 @@
|
|||
// * For the full copyright and license information, please view the LICENSE
|
||||
// * file that was distributed with this source code.
|
||||
|
||||
// spell-checker:ignore (paths) sublink subwords
|
||||
// spell-checker:ignore (paths) sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty
|
||||
#[cfg(not(windows))]
|
||||
use regex::Regex;
|
||||
#[cfg(not(windows))]
|
||||
use std::io::Write;
|
||||
|
||||
use crate::common::util::*;
|
||||
|
||||
|
@ -429,7 +433,7 @@ fn test_du_no_permission() {
|
|||
|
||||
ts.ccmd("chmod").arg("-r").arg(SUB_DIR_LINKS).succeeds();
|
||||
|
||||
let result = ts.ucmd().arg(SUB_DIR_LINKS).run(); // TODO: replace with ".fails()" once `du` is fixed
|
||||
let result = ts.ucmd().arg(SUB_DIR_LINKS).fails();
|
||||
result.stderr_contains(
|
||||
"du: cannot read directory 'subdir/links': Permission denied (os error 13)",
|
||||
);
|
||||
|
@ -449,6 +453,21 @@ fn test_du_no_permission() {
|
|||
_du_no_permission(result.stdout_str());
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
#[cfg(feature = "chmod")]
|
||||
#[test]
|
||||
fn test_du_no_exec_permission() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.mkdir_all("d/no-x/y");
|
||||
|
||||
ts.ccmd("chmod").arg("u=rw").arg("d/no-x").succeeds();
|
||||
|
||||
let result = ts.ucmd().arg("d/no-x").fails();
|
||||
result.stderr_contains("du: cannot access 'd/no-x/y': Permission denied");
|
||||
}
|
||||
|
||||
#[cfg(target_vendor = "apple")]
|
||||
fn _du_no_permission(s: &str) {
|
||||
assert_eq!(s, "0\tsubdir/links\n");
|
||||
|
@ -587,3 +606,171 @@ fn test_du_bytes() {
|
|||
))]
|
||||
result.stdout_contains("21529\t./subdir\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_du_exclude() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.symlink_dir(SUB_DEEPER_DIR, SUB_DIR_LINKS_DEEPER_SYM_DIR);
|
||||
at.mkdir_all(SUB_DIR_LINKS);
|
||||
|
||||
ts.ucmd()
|
||||
.arg("--exclude=subdir")
|
||||
.arg(SUB_DEEPER_DIR)
|
||||
.succeeds()
|
||||
.stdout_contains("subdir/deeper/deeper_dir");
|
||||
ts.ucmd()
|
||||
.arg("--exclude=subdir")
|
||||
.arg("subdir")
|
||||
.succeeds()
|
||||
.stdout_is("");
|
||||
ts.ucmd()
|
||||
.arg("--exclude=subdir")
|
||||
.arg("--verbose")
|
||||
.arg("subdir")
|
||||
.succeeds()
|
||||
.stdout_contains("'subdir' ignored");
|
||||
}
|
||||
|
||||
#[test]
|
||||
// Disable on Windows because we are looking for /
|
||||
// And the tests would be more complex if we have to support \ too
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn test_du_exclude_2() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.mkdir_all("azerty/xcwww/azeaze");
|
||||
|
||||
let result = ts.ucmd().arg("azerty").succeeds();
|
||||
|
||||
let path_regexp = r"(.*)azerty/xcwww/azeaze(.*)azerty/xcwww(.*)azerty";
|
||||
let re = Regex::new(path_regexp).unwrap();
|
||||
assert!(re.is_match(result.stdout_str().replace('\n', "").trim()));
|
||||
|
||||
// Exact match
|
||||
ts.ucmd()
|
||||
.arg("--exclude=azeaze")
|
||||
.arg("azerty")
|
||||
.succeeds()
|
||||
.stdout_does_not_contain("azerty/xcwww/azeaze");
|
||||
// Partial match and NOT a glob
|
||||
ts.ucmd()
|
||||
.arg("--exclude=azeaz")
|
||||
.arg("azerty")
|
||||
.succeeds()
|
||||
.stdout_contains("azerty/xcwww/azeaze");
|
||||
// Partial match and a various glob
|
||||
ts.ucmd()
|
||||
.arg("--exclude=azea?")
|
||||
.arg("azerty")
|
||||
.succeeds()
|
||||
.stdout_contains("azerty/xcwww/azeaze");
|
||||
ts.ucmd()
|
||||
.arg("--exclude=azea{z,b}")
|
||||
.arg("azerty")
|
||||
.succeeds()
|
||||
.stdout_contains("azerty/xcwww/azeaze");
|
||||
ts.ucmd()
|
||||
.arg("--exclude=azea*")
|
||||
.arg("azerty")
|
||||
.succeeds()
|
||||
.stdout_does_not_contain("azerty/xcwww/azeaze");
|
||||
ts.ucmd()
|
||||
.arg("--exclude=azeaz?")
|
||||
.arg("azerty")
|
||||
.succeeds()
|
||||
.stdout_does_not_contain("azerty/xcwww/azeaze");
|
||||
}
|
||||
|
||||
#[test]
|
||||
// Disable on Windows because we are looking for /
|
||||
// And the tests would be more complex if we have to support \ too
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
fn test_du_exclude_mix() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
let mut file1 = at.make_file("file-ignore1");
|
||||
file1.write_all(b"azeaze").unwrap();
|
||||
let mut file2 = at.make_file("file-ignore2");
|
||||
file2.write_all(b"amaz?ng").unwrap();
|
||||
|
||||
at.mkdir_all("azerty/xcwww/azeaze");
|
||||
at.mkdir_all("azerty/xcwww/qzerty");
|
||||
at.mkdir_all("azerty/xcwww/amazing");
|
||||
|
||||
ts.ucmd()
|
||||
.arg("azerty")
|
||||
.succeeds()
|
||||
.stdout_contains("azerty/xcwww/azeaze");
|
||||
ts.ucmd()
|
||||
.arg("--exclude=azeaze")
|
||||
.arg("azerty")
|
||||
.succeeds()
|
||||
.stdout_does_not_contain("azerty/xcwww/azeaze");
|
||||
|
||||
// Just exclude one file name
|
||||
let result = ts.ucmd().arg("--exclude=qzerty").arg("azerty").succeeds();
|
||||
assert!(!result.stdout_str().contains("qzerty"));
|
||||
assert!(result.stdout_str().contains("azerty"));
|
||||
assert!(result.stdout_str().contains("xcwww"));
|
||||
|
||||
// Exclude from file
|
||||
let result = ts
|
||||
.ucmd()
|
||||
.arg("--exclude-from=file-ignore1")
|
||||
.arg("azerty")
|
||||
.succeeds();
|
||||
assert!(!result.stdout_str().contains("azeaze"));
|
||||
assert!(result.stdout_str().contains("qzerty"));
|
||||
assert!(result.stdout_str().contains("xcwww"));
|
||||
|
||||
// Mix two files and string
|
||||
let result = ts
|
||||
.ucmd()
|
||||
.arg("--exclude=qzerty")
|
||||
.arg("--exclude-from=file-ignore1")
|
||||
.arg("--exclude-from=file-ignore2")
|
||||
.arg("azerty")
|
||||
.succeeds();
|
||||
assert!(!result.stdout_str().contains("amazing"));
|
||||
assert!(!result.stdout_str().contains("qzerty"));
|
||||
assert!(!result.stdout_str().contains("azeaze"));
|
||||
assert!(result.stdout_str().contains("xcwww"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_du_exclude_several_components() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.mkdir_all("a/b/c");
|
||||
at.mkdir_all("a/x/y");
|
||||
at.mkdir_all("a/u/y");
|
||||
|
||||
// Exact match
|
||||
let result = ts
|
||||
.ucmd()
|
||||
.arg("--exclude=a/u")
|
||||
.arg("--exclude=a/b")
|
||||
.arg("a")
|
||||
.succeeds();
|
||||
assert!(!result.stdout_str().contains("a/u"));
|
||||
assert!(!result.stdout_str().contains("a/b"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_du_exclude_invalid_syntax() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
|
||||
at.mkdir_all("azerty/xcwww/azeaze");
|
||||
|
||||
ts.ucmd()
|
||||
.arg("--exclude=a[ze")
|
||||
.arg("azerty")
|
||||
.fails()
|
||||
.stderr_contains("du: Invalid exclude syntax");
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ fn test_unset_invalid_variables() {
|
|||
|
||||
// Cannot test input with \0 in it, since output will also contain \0. rlimit::prlimit fails
|
||||
// with this error: Error { kind: InvalidInput, message: "nul byte found in provided data" }
|
||||
for var in &["", "a=b"] {
|
||||
for var in ["", "a=b"] {
|
||||
new_ucmd!().arg("-u").arg(var).run().stderr_only(format!(
|
||||
"env: cannot unset {}: Invalid argument",
|
||||
var.quote()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// spell-checker:ignore checkfile
|
||||
// spell-checker:ignore checkfile, nonames
|
||||
macro_rules! get_hash(
|
||||
($str:expr) => (
|
||||
$str.split(' ').collect::<Vec<&str>>()[0]
|
||||
|
@ -29,6 +29,16 @@ macro_rules! test_digest {
|
|||
get_hash!(ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).pipe_in_fixture("input.txt").succeeds().no_stderr().stdout_str()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nonames() {
|
||||
let ts = TestScenario::new("hashsum");
|
||||
// EXPECTED_FILE has no newline character at the end
|
||||
assert_eq!(format!("{0}\n{0}\n", ts.fixtures.read(EXPECTED_FILE)),
|
||||
ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("--no-names").arg("input.txt").arg("-").pipe_in_fixture("input.txt")
|
||||
.succeeds().no_stderr().stdout_str()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check() {
|
||||
let ts = TestScenario::new("hashsum");
|
||||
|
|
|
@ -49,7 +49,7 @@ fn test_id_single_user() {
|
|||
.code_is(exp_result.code());
|
||||
|
||||
// u/g/G z/n
|
||||
for &opt in &["--user", "--group", "--groups"] {
|
||||
for opt in ["--user", "--group", "--groups"] {
|
||||
let mut args = vec![opt];
|
||||
args.extend_from_slice(&test_users);
|
||||
exp_result = unwrap_or_return!(expected_result(&ts, &args));
|
||||
|
@ -108,7 +108,7 @@ fn test_id_single_user_non_existing() {
|
|||
#[cfg(unix)]
|
||||
fn test_id_name() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for &opt in &["--user", "--group", "--groups"] {
|
||||
for opt in ["--user", "--group", "--groups"] {
|
||||
let args = [opt, "--name"];
|
||||
let result = ts.ucmd().args(&args).run();
|
||||
let exp_result = unwrap_or_return!(expected_result(&ts, &args));
|
||||
|
@ -127,7 +127,7 @@ fn test_id_name() {
|
|||
#[cfg(unix)]
|
||||
fn test_id_real() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for &opt in &["--user", "--group", "--groups"] {
|
||||
for opt in ["--user", "--group", "--groups"] {
|
||||
let args = [opt, "--real"];
|
||||
let result = ts.ucmd().args(&args).run();
|
||||
let exp_result = unwrap_or_return!(expected_result(&ts, &args));
|
||||
|
@ -188,7 +188,7 @@ fn test_id_multiple_users() {
|
|||
.code_is(exp_result.code());
|
||||
|
||||
// u/g/G z/n
|
||||
for &opt in &["--user", "--group", "--groups"] {
|
||||
for opt in ["--user", "--group", "--groups"] {
|
||||
let mut args = vec![opt];
|
||||
args.extend_from_slice(&test_users);
|
||||
exp_result = unwrap_or_return!(expected_result(&ts, &args));
|
||||
|
@ -256,7 +256,7 @@ fn test_id_multiple_users_non_existing() {
|
|||
.code_is(exp_result.code());
|
||||
|
||||
// u/g/G z/n
|
||||
for &opt in &["--user", "--group", "--groups"] {
|
||||
for opt in ["--user", "--group", "--groups"] {
|
||||
let mut args = vec![opt];
|
||||
args.extend_from_slice(&test_users);
|
||||
exp_result = unwrap_or_return!(expected_result(&ts, &args));
|
||||
|
@ -297,14 +297,14 @@ fn test_id_multiple_users_non_existing() {
|
|||
#[cfg(unix)]
|
||||
fn test_id_default_format() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for &opt1 in &["--name", "--real"] {
|
||||
for opt1 in ["--name", "--real"] {
|
||||
// id: cannot print only names or real IDs in default format
|
||||
let args = [opt1];
|
||||
ts.ucmd()
|
||||
.args(&args)
|
||||
.fails()
|
||||
.stderr_only(unwrap_or_return!(expected_result(&ts, &args)).stderr_str());
|
||||
for &opt2 in &["--user", "--group", "--groups"] {
|
||||
for opt2 in ["--user", "--group", "--groups"] {
|
||||
// u/g/G n/r
|
||||
let args = [opt2, opt1];
|
||||
let result = ts.ucmd().args(&args).run();
|
||||
|
@ -315,7 +315,7 @@ fn test_id_default_format() {
|
|||
.code_is(exp_result.code());
|
||||
}
|
||||
}
|
||||
for &opt2 in &["--user", "--group", "--groups"] {
|
||||
for opt2 in ["--user", "--group", "--groups"] {
|
||||
// u/g/G
|
||||
let args = [opt2];
|
||||
ts.ucmd()
|
||||
|
@ -329,20 +329,20 @@ fn test_id_default_format() {
|
|||
#[cfg(unix)]
|
||||
fn test_id_zero() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for z_flag in &["-z", "--zero"] {
|
||||
for z_flag in ["-z", "--zero"] {
|
||||
// id: option --zero not permitted in default format
|
||||
ts.ucmd()
|
||||
.args(&[z_flag])
|
||||
.fails()
|
||||
.stderr_only(unwrap_or_return!(expected_result(&ts, &[z_flag])).stderr_str());
|
||||
for &opt1 in &["--name", "--real"] {
|
||||
for opt1 in ["--name", "--real"] {
|
||||
// id: cannot print only names or real IDs in default format
|
||||
let args = [opt1, z_flag];
|
||||
ts.ucmd()
|
||||
.args(&args)
|
||||
.fails()
|
||||
.stderr_only(unwrap_or_return!(expected_result(&ts, &args)).stderr_str());
|
||||
for &opt2 in &["--user", "--group", "--groups"] {
|
||||
for opt2 in ["--user", "--group", "--groups"] {
|
||||
// u/g/G n/r z
|
||||
let args = [opt2, z_flag, opt1];
|
||||
let result = ts.ucmd().args(&args).run();
|
||||
|
@ -353,7 +353,7 @@ fn test_id_zero() {
|
|||
.code_is(exp_result.code());
|
||||
}
|
||||
}
|
||||
for &opt2 in &["--user", "--group", "--groups"] {
|
||||
for opt2 in ["--user", "--group", "--groups"] {
|
||||
// u/g/G z
|
||||
let args = [opt2, z_flag];
|
||||
ts.ucmd()
|
||||
|
@ -373,18 +373,18 @@ fn test_id_context() {
|
|||
return;
|
||||
}
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for c_flag in &["-Z", "--context"] {
|
||||
for c_flag in ["-Z", "--context"] {
|
||||
ts.ucmd()
|
||||
.args(&[c_flag])
|
||||
.succeeds()
|
||||
.stdout_only(unwrap_or_return!(expected_result(&ts, &[c_flag])).stdout_str());
|
||||
for &z_flag in &["-z", "--zero"] {
|
||||
for z_flag in ["-z", "--zero"] {
|
||||
let args = [c_flag, z_flag];
|
||||
ts.ucmd()
|
||||
.args(&args)
|
||||
.succeeds()
|
||||
.stdout_only(unwrap_or_return!(expected_result(&ts, &args)).stdout_str());
|
||||
for &opt1 in &["--name", "--real"] {
|
||||
for opt1 in ["--name", "--real"] {
|
||||
// id: cannot print only names or real IDs in default format
|
||||
let args = [opt1, c_flag];
|
||||
ts.ucmd()
|
||||
|
@ -396,7 +396,7 @@ fn test_id_context() {
|
|||
.args(&args)
|
||||
.succeeds()
|
||||
.stdout_only(unwrap_or_return!(expected_result(&ts, &args)).stdout_str());
|
||||
for &opt2 in &["--user", "--group", "--groups"] {
|
||||
for opt2 in ["--user", "--group", "--groups"] {
|
||||
// u/g/G n/r z Z
|
||||
// for now, we print clap's standard response for "conflicts_with" instead of:
|
||||
// id: cannot print "only" of more than one choice
|
||||
|
@ -409,7 +409,7 @@ fn test_id_context() {
|
|||
// .code_is(exp_result.code());
|
||||
}
|
||||
}
|
||||
for &opt2 in &["--user", "--group", "--groups"] {
|
||||
for opt2 in ["--user", "--group", "--groups"] {
|
||||
// u/g/G z Z
|
||||
// for now, we print clap's standard response for "conflicts_with" instead of:
|
||||
// id: cannot print "only" of more than one choice
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// spell-checker:ignore (words) helloworld objdump
|
||||
// spell-checker:ignore (words) helloworld objdump n'source
|
||||
|
||||
use crate::common::util::*;
|
||||
use filetime::FileTime;
|
||||
|
@ -607,7 +607,11 @@ fn test_install_and_strip_with_program() {
|
|||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_install_and_strip_with_invalid_program() {
|
||||
new_ucmd!()
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-s")
|
||||
.arg("--strip-program")
|
||||
.arg("/bin/date")
|
||||
|
@ -615,12 +619,17 @@ fn test_install_and_strip_with_invalid_program() {
|
|||
.arg(STRIP_TARGET_FILE)
|
||||
.fails()
|
||||
.stderr_contains("strip program failed");
|
||||
assert!(!at.file_exists(STRIP_TARGET_FILE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_install_and_strip_with_non_existent_program() {
|
||||
new_ucmd!()
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-s")
|
||||
.arg("--strip-program")
|
||||
.arg("/usr/bin/non_existent_program")
|
||||
|
@ -628,6 +637,7 @@ fn test_install_and_strip_with_non_existent_program() {
|
|||
.arg(STRIP_TARGET_FILE)
|
||||
.fails()
|
||||
.stderr_contains("No such file or directory");
|
||||
assert!(!at.file_exists(STRIP_TARGET_FILE));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1164,3 +1174,29 @@ fn test_install_dir_dot() {
|
|||
assert!(at.dir_exists("dir4/cal"));
|
||||
assert!(at.dir_exists("dir5/cali"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_install_dir_req_verbose() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
let file_1 = "source_file1";
|
||||
let dest_dir = "sub4";
|
||||
at.touch(file_1);
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-Dv")
|
||||
.arg(file_1)
|
||||
.arg("sub3/a/b/c/file")
|
||||
.succeeds()
|
||||
.stdout_contains("install: creating directory 'sub3'\ninstall: creating directory 'sub3/a'\ninstall: creating directory 'sub3/a/b'\ninstall: creating directory 'sub3/a/b/c'\n'source_file1' -> 'sub3/a/b/c/file'");
|
||||
|
||||
at.mkdir(dest_dir);
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-Dv")
|
||||
.arg(file_1)
|
||||
.arg("sub4/a/b/c/file")
|
||||
.succeeds()
|
||||
.stdout_contains("install: creating directory 'sub4/a'\ninstall: creating directory 'sub4/a/b'\ninstall: creating directory 'sub4/a/b/c'\n'source_file1' -> 'sub4/a/b/c/file'");
|
||||
}
|
||||
|
|
|
@ -604,7 +604,7 @@ fn test_ls_width() {
|
|||
at.touch(&at.plus_as_string("test-width-3"));
|
||||
at.touch(&at.plus_as_string("test-width-4"));
|
||||
|
||||
for option in &[
|
||||
for option in [
|
||||
"-w 100",
|
||||
"-w=100",
|
||||
"--width=100",
|
||||
|
@ -619,7 +619,7 @@ fn test_ls_width() {
|
|||
.stdout_only("test-width-1 test-width-2 test-width-3 test-width-4\n");
|
||||
}
|
||||
|
||||
for option in &["-w 50", "-w=50", "--width=50", "--width 50", "--wid=50"] {
|
||||
for option in ["-w 50", "-w=50", "--width=50", "--width 50", "--wid=50"] {
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&option.split(' ').collect::<Vec<_>>())
|
||||
|
@ -628,7 +628,7 @@ fn test_ls_width() {
|
|||
.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", "--wid=25"] {
|
||||
for option in ["-w 25", "-w=25", "--width=25", "--width 25", "--wid=25"] {
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&option.split(' ').collect::<Vec<_>>())
|
||||
|
@ -637,7 +637,7 @@ fn test_ls_width() {
|
|||
.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", "--wid=0"] {
|
||||
for option in ["-w 0", "-w=0", "--width=0", "--width 0", "--wid=0"] {
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&option.split(' ').collect::<Vec<_>>())
|
||||
|
@ -653,7 +653,7 @@ fn test_ls_width() {
|
|||
.fails()
|
||||
.stderr_contains("invalid line width");
|
||||
|
||||
for option in &["-w 1a", "-w=1a", "--width=1a", "--width 1a", "--wid 1a"] {
|
||||
for option in ["-w 1a", "-w=1a", "--width=1a", "--width 1a", "--wid 1a"] {
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&option.split(' ').collect::<Vec<_>>())
|
||||
|
@ -894,7 +894,7 @@ fn test_ls_long_symlink_color() {
|
|||
(Some([0, 0]), "ln-file1", None, "dir1/file1"),
|
||||
(Some([1, 1]), "ln-dir-invalid", Some([1, 1]), "dir1/dir2"),
|
||||
(Some([0, 0]), "ln-root", Some([0, 1]), "/"),
|
||||
(Some([0, 0]), "ln-up2", Some([0, 1]), "../.."),
|
||||
(Some([0, 0]), "ln-up2", None, "../.."),
|
||||
];
|
||||
|
||||
// We are only interested in lines or the ls output that are symlinks. These start with "lrwx".
|
||||
|
@ -912,6 +912,8 @@ fn test_ls_long_symlink_color() {
|
|||
while let Some((i, name, target)) = get_index_name_target(&mut result_lines) {
|
||||
// The unwraps within capture_colored_string will panic if the name/target's color
|
||||
// format is invalid.
|
||||
dbg!(&name);
|
||||
dbg!(&target);
|
||||
let (matched_name_color, matched_name) = capture_colored_string(&name);
|
||||
let (matched_target_color, matched_target) = capture_colored_string(&target);
|
||||
|
||||
|
@ -934,6 +936,7 @@ fn test_ls_long_symlink_color() {
|
|||
// Keep in mind an expected color `Option<&str>` of None can mean either that we
|
||||
// don't expect any color here, as in `expected_output[2], or don't know what specific
|
||||
// color to expect yet, as in expected_output[0:1].
|
||||
dbg!(&colors);
|
||||
assert_names_and_colors_are_equal(
|
||||
matched_name_color,
|
||||
expected_name_color,
|
||||
|
@ -1088,9 +1091,9 @@ fn test_ls_long_total_size() {
|
|||
let result = scene.ucmd().arg(arg).succeeds();
|
||||
result.stdout_contains(expected_prints["long_vanilla"]);
|
||||
|
||||
for arg2 in &["-h", "--human-readable", "--si"] {
|
||||
for arg2 in ["-h", "--human-readable", "--si"] {
|
||||
let result = scene.ucmd().arg(arg).arg(arg2).succeeds();
|
||||
result.stdout_contains(if *arg2 == "--si" {
|
||||
result.stdout_contains(if arg2 == "--si" {
|
||||
expected_prints["long_si"]
|
||||
} else {
|
||||
expected_prints["long_human_readable"]
|
||||
|
@ -1158,7 +1161,7 @@ fn test_ls_long_formats() {
|
|||
.stdout_matches(&re_three_num);
|
||||
}
|
||||
|
||||
for arg in &[
|
||||
for arg in [
|
||||
"-l", // only group and owner
|
||||
"-g --author", // only author and group
|
||||
"-o --author", // only author and owner
|
||||
|
@ -1184,7 +1187,7 @@ fn test_ls_long_formats() {
|
|||
}
|
||||
}
|
||||
|
||||
for arg in &[
|
||||
for arg in [
|
||||
"-g", // only group
|
||||
"-gl", // only group
|
||||
"-o", // only owner
|
||||
|
@ -1213,7 +1216,7 @@ fn test_ls_long_formats() {
|
|||
}
|
||||
}
|
||||
|
||||
for arg in &[
|
||||
for arg in [
|
||||
"-og",
|
||||
"-ogl",
|
||||
"-lgo",
|
||||
|
@ -1255,7 +1258,7 @@ fn test_ls_oneline() {
|
|||
|
||||
// Bit of a weird situation: in the tests oneline and columns have the same output,
|
||||
// except on Windows.
|
||||
for option in &["-1", "--format=single-column"] {
|
||||
for option in ["-1", "--format=single-column"] {
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(option)
|
||||
|
@ -1376,7 +1379,7 @@ fn test_ls_long_ctime() {
|
|||
|
||||
at.touch("test-long-ctime-1");
|
||||
|
||||
for arg in &["-c", "--time=ctime", "--time=status"] {
|
||||
for arg in ["-c", "--time=ctime", "--time=status"] {
|
||||
let result = scene.ucmd().arg("-l").arg(arg).succeeds();
|
||||
|
||||
// Should show the time on Unix, but question marks on windows.
|
||||
|
@ -1537,7 +1540,7 @@ fn test_ls_order_time() {
|
|||
|
||||
// 3 was accessed last in the read
|
||||
// So the order should be 2 3 4 1
|
||||
for arg in &["-u", "--time=atime", "--time=access", "--time=use"] {
|
||||
for arg in ["-u", "--time=atime", "--time=access", "--time=use"] {
|
||||
let result = scene.ucmd().arg("-t").arg(arg).succeeds();
|
||||
at.open("test-3").metadata().unwrap().accessed().unwrap();
|
||||
at.open("test-4").metadata().unwrap().accessed().unwrap();
|
||||
|
@ -1656,7 +1659,7 @@ fn test_ls_color() {
|
|||
assert!(!result.stdout_str().contains(z_with_colors));
|
||||
|
||||
// Color should be enabled
|
||||
for param in &["--color", "--col", "--color=always", "--col=always"] {
|
||||
for param in ["--color", "--col", "--color=always", "--col=always"] {
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(param)
|
||||
|
@ -2034,7 +2037,7 @@ fn test_ls_success_on_c_drv_root_windows() {
|
|||
fn test_ls_version_sort() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
for filename in &[
|
||||
for filename in [
|
||||
"a2",
|
||||
"b1",
|
||||
"b20",
|
||||
|
@ -2130,7 +2133,7 @@ fn test_ls_quoting_style() {
|
|||
.succeeds()
|
||||
.stdout_only("'one'$'\\n''two'\n");
|
||||
|
||||
for (arg, correct) in &[
|
||||
for (arg, correct) in [
|
||||
("--quoting-style=literal", "one?two"),
|
||||
("-N", "one?two"),
|
||||
("--literal", "one?two"),
|
||||
|
@ -2154,7 +2157,7 @@ fn test_ls_quoting_style() {
|
|||
.stdout_only(format!("{}\n", correct));
|
||||
}
|
||||
|
||||
for (arg, correct) in &[
|
||||
for (arg, correct) in [
|
||||
("--quoting-style=literal", "one\ntwo"),
|
||||
("-N", "one\ntwo"),
|
||||
("--literal", "one\ntwo"),
|
||||
|
@ -2170,7 +2173,7 @@ fn test_ls_quoting_style() {
|
|||
.stdout_only(format!("{}\n", correct));
|
||||
}
|
||||
|
||||
for (arg, correct) in &[
|
||||
for (arg, correct) in [
|
||||
("--quoting-style=literal", "one\\two"),
|
||||
("-N", "one\\two"),
|
||||
("--quoting-style=c", "\"one\\\\two\""),
|
||||
|
@ -2195,7 +2198,7 @@ fn test_ls_quoting_style() {
|
|||
// Tests for a character that forces quotation in shell-style escaping
|
||||
// after a character in a dollar expression
|
||||
at.touch("one\n&two");
|
||||
for (arg, correct) in &[
|
||||
for (arg, correct) in [
|
||||
("--quoting-style=shell-escape", "'one'$'\\n''&two'"),
|
||||
("--quoting-style=shell-escape-always", "'one'$'\\n''&two'"),
|
||||
] {
|
||||
|
@ -2215,7 +2218,7 @@ fn test_ls_quoting_style() {
|
|||
.succeeds()
|
||||
.stdout_only("'one two'\n");
|
||||
|
||||
for (arg, correct) in &[
|
||||
for (arg, correct) in [
|
||||
("--quoting-style=literal", "one two"),
|
||||
("-N", "one two"),
|
||||
("--literal", "one two"),
|
||||
|
@ -2241,7 +2244,7 @@ fn test_ls_quoting_style() {
|
|||
|
||||
scene.ucmd().arg("one").succeeds().stdout_only("one\n");
|
||||
|
||||
for (arg, correct) in &[
|
||||
for (arg, correct) in [
|
||||
("--quoting-style=literal", "one"),
|
||||
("-N", "one"),
|
||||
("--quoting-style=c", "\"one\""),
|
||||
|
@ -2649,7 +2652,7 @@ fn test_ls_deref_command_line_dir() {
|
|||
fn test_ls_sort_extension() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
for filename in &[
|
||||
for filename in [
|
||||
"file1",
|
||||
"file2",
|
||||
"anotherFile",
|
||||
|
@ -2831,7 +2834,7 @@ fn test_ls_context2() {
|
|||
return;
|
||||
}
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for c_flag in &["-Z", "--context"] {
|
||||
for c_flag in ["-Z", "--context"] {
|
||||
ts.ucmd()
|
||||
.args(&[c_flag, &"/"])
|
||||
.succeeds()
|
||||
|
@ -2851,7 +2854,7 @@ fn test_ls_context_format() {
|
|||
// NOTE:
|
||||
// --format=long/verbose matches the output of GNU's ls for --context
|
||||
// except for the size count which may differ to the size count reported by GNU's ls.
|
||||
for word in &[
|
||||
for word in [
|
||||
"across",
|
||||
"commas",
|
||||
"horizontal",
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
use crate::common::util::*;
|
||||
#[cfg(not(windows))]
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
#[cfg(not(windows))]
|
||||
extern crate libc;
|
||||
#[cfg(not(windows))]
|
||||
use self::libc::{mode_t, umask};
|
||||
|
||||
static TEST_DIR1: &str = "mkdir_test1";
|
||||
static TEST_DIR2: &str = "mkdir_test2";
|
||||
|
@ -13,6 +17,8 @@ static TEST_DIR8: &str = "mkdir_test8/mkdir_test8_1/mkdir_test8_2";
|
|||
static TEST_DIR9: &str = "mkdir_test9/../mkdir_test9_1/../mkdir_test9_2";
|
||||
static TEST_DIR10: &str = "mkdir_test10/.";
|
||||
static TEST_DIR11: &str = "mkdir_test11/..";
|
||||
#[cfg(not(windows))]
|
||||
static TEST_DIR12: &str = "mkdir_test12";
|
||||
|
||||
#[test]
|
||||
fn test_mkdir_mkdir() {
|
||||
|
@ -151,3 +157,26 @@ fn test_mkdir_trailing_dot() {
|
|||
let result = scene2.cmd("ls").arg("-al").run();
|
||||
println!("ls dest {}", result.stdout_str());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_umask_compliance() {
|
||||
fn test_single_case(umask_set: mode_t) {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
let original_umask = unsafe { umask(umask_set) };
|
||||
|
||||
ucmd.arg(TEST_DIR12).succeeds();
|
||||
let perms = at.metadata(TEST_DIR12).permissions().mode() as mode_t;
|
||||
|
||||
assert_eq!(perms, (!umask_set & 0o0777) + 0o40000); // before compare, add the set GUID, UID bits
|
||||
unsafe {
|
||||
umask(original_umask);
|
||||
} // set umask back to original
|
||||
}
|
||||
|
||||
for i in 0o0..0o027 {
|
||||
// tests all permission combinations
|
||||
test_single_case(i as mode_t);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -800,6 +800,47 @@ fn test_mv_permission_error() {
|
|||
.stderr_contains("Permission denied");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_interactive_error() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
let dir = "test_mv_errors_dir";
|
||||
let file_a = "test_mv_errors_file_a";
|
||||
at.mkdir(dir);
|
||||
at.touch(file_a);
|
||||
|
||||
// $ at.mkdir dir && at.touch file
|
||||
// $ mv -i dir file
|
||||
// err == mv: cannot overwrite non-directory 'file' with directory 'dir'
|
||||
assert!(!scene
|
||||
.ucmd()
|
||||
.arg("-i")
|
||||
.arg(dir)
|
||||
.arg(file_a)
|
||||
.pipe_in("y")
|
||||
.fails()
|
||||
.stderr_str()
|
||||
.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mv_info_self() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
let dir1 = "dir1";
|
||||
let dir2 = "dir2";
|
||||
at.mkdir(dir1);
|
||||
at.mkdir(dir2);
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg(dir1)
|
||||
.arg(dir2)
|
||||
.arg(dir2)
|
||||
.fails()
|
||||
.stderr_contains("mv: cannot move 'dir2' to a subdirectory of itself, 'dir2/dir2'");
|
||||
}
|
||||
|
||||
// Todo:
|
||||
|
||||
// $ at.touch a b
|
||||
|
|
|
@ -42,7 +42,7 @@ fn test_padding_with_overflow() {
|
|||
#[test]
|
||||
fn test_sections_and_styles() {
|
||||
// spell-checker:disable
|
||||
for &(fixture, output) in &[
|
||||
for (fixture, output) in [
|
||||
(
|
||||
"section.txt",
|
||||
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 \
|
||||
|
|
|
@ -484,7 +484,7 @@ fn test_delimiter_with_padding_and_fields() {
|
|||
|
||||
#[test]
|
||||
fn test_round() {
|
||||
for (method, exp) in &[
|
||||
for (method, exp) in [
|
||||
("from-zero", ["9.1K", "-9.1K", "9.1K", "-9.1K"]),
|
||||
("towards-zero", ["9.0K", "-9.0K", "9.0K", "-9.0K"]),
|
||||
("up", ["9.1K", "-9.0K", "9.1K", "-9.0K"]),
|
||||
|
|
|
@ -70,12 +70,12 @@ fn test_2files() {
|
|||
let file1 = tmpdir.join("test1");
|
||||
let file2 = tmpdir.join("test2");
|
||||
|
||||
for &(n, a) in &[(1, "a"), (2, "b")] {
|
||||
for (n, a) in [(1, "a"), (2, "b")] {
|
||||
println!("number: {} letter:{}", n, a);
|
||||
}
|
||||
|
||||
// spell-checker:disable-next-line
|
||||
for &(path, data) in &[(&file1, "abcdefghijklmnop"), (&file2, "qrstuvwxyz\n")] {
|
||||
for (path, data) in [(&file1, "abcdefghijklmnop"), (&file2, "qrstuvwxyz\n")] {
|
||||
let mut f = File::create(&path).unwrap();
|
||||
assert!(
|
||||
f.write_all(data.as_bytes()).is_ok(),
|
||||
|
@ -127,7 +127,7 @@ fn test_from_mixed() {
|
|||
|
||||
// spell-checker:disable-next-line
|
||||
let (data1, data2, data3) = ("abcdefg", "hijklmnop", "qrstuvwxyz\n");
|
||||
for &(path, data) in &[(&file1, data1), (&file3, data3)] {
|
||||
for (path, data) in [(&file1, data1), (&file3, data3)] {
|
||||
let mut f = File::create(&path).unwrap();
|
||||
assert!(
|
||||
f.write_all(data.as_bytes()).is_ok(),
|
||||
|
|
|
@ -82,8 +82,8 @@ static EXAMPLE_DATA: &[TestData] = &[
|
|||
|
||||
#[test]
|
||||
fn test_combine_pairs_of_lines() {
|
||||
for &s in &["-s", "--serial"] {
|
||||
for &d in &["-d", "--delimiters"] {
|
||||
for s in ["-s", "--serial"] {
|
||||
for d in ["-d", "--delimiters"] {
|
||||
new_ucmd!()
|
||||
.args(&[s, d, "\t\n", "html_colors.txt"])
|
||||
.run()
|
||||
|
@ -94,7 +94,7 @@ fn test_combine_pairs_of_lines() {
|
|||
|
||||
#[test]
|
||||
fn test_multi_stdin() {
|
||||
for &d in &["-d", "--delimiters"] {
|
||||
for d in ["-d", "--delimiters"] {
|
||||
new_ucmd!()
|
||||
.args(&[d, "\t\n", "-", "-"])
|
||||
.pipe_in_fixture("html_colors.txt")
|
||||
|
|
|
@ -69,7 +69,7 @@ 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 header = "new file";
|
||||
for args in &[&["-h", header][..], &["--header=new file"][..]] {
|
||||
for args in [&["-h", header][..], &["--header=new file"][..]] {
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
|
@ -87,7 +87,7 @@ fn test_with_long_header_option() {
|
|||
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";
|
||||
for &arg in &["-d", "--double-space"] {
|
||||
for arg in ["-d", "--double-space"] {
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
|
@ -183,7 +183,7 @@ 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";
|
||||
for &arg in &["--pages=15", "+15"] {
|
||||
for arg in ["--pages=15", "+15"] {
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
|
@ -194,7 +194,7 @@ fn test_with_page_range() {
|
|||
&[("{last_modified_time}", &value)],
|
||||
);
|
||||
}
|
||||
for &arg in &["--pages=15:17", "+15:17"] {
|
||||
for arg in ["--pages=15:17", "+15:17"] {
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
|
@ -222,7 +222,7 @@ fn test_with_no_header_trailer_option() {
|
|||
#[test]
|
||||
fn test_with_page_length_option() {
|
||||
let test_file_path = "test.log";
|
||||
for (arg, expected) in &[
|
||||
for (arg, expected) in [
|
||||
("100", "test_page_length.log.expected"),
|
||||
("5", "test_page_length1.log.expected"),
|
||||
] {
|
||||
|
@ -265,7 +265,7 @@ fn test_with_stdin() {
|
|||
fn test_with_column() {
|
||||
let test_file_path = "column.log";
|
||||
let expected_test_file_path = "column.log.expected";
|
||||
for arg in &["-3", "--column=3"] {
|
||||
for arg in ["-3", "--column=3"] {
|
||||
let mut scenario = new_ucmd!();
|
||||
let value = file_last_modified_time(&scenario, test_file_path);
|
||||
scenario
|
||||
|
@ -293,7 +293,7 @@ fn test_with_column_across_option() {
|
|||
#[test]
|
||||
fn test_with_column_across_option_and_column_separator() {
|
||||
let test_file_path = "column.log";
|
||||
for (arg, expected) in &[
|
||||
for (arg, expected) in [
|
||||
("-s|", "column_across_sep.log.expected"),
|
||||
("-Sdivide", "column_across_sep1.log.expected"),
|
||||
] {
|
||||
|
|
|
@ -26,7 +26,7 @@ fn test_deleted_dir() {
|
|||
let output = Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(format!(
|
||||
"cd '{}'; mkdir foo; cd foo; rmdir ../foo; exec {} {}",
|
||||
"cd '{}'; mkdir foo; cd foo; rmdir ../foo; exec '{}' {}",
|
||||
at.root_dir_resolved(),
|
||||
ts.bin_path.to_str().unwrap(),
|
||||
ts.util_name,
|
||||
|
|
|
@ -22,11 +22,11 @@ fn help() {
|
|||
fn print() {
|
||||
new_ucmd!().succeeds();
|
||||
|
||||
for &flag in &["-c", "--compute"] {
|
||||
for flag in ["-c", "--compute"] {
|
||||
new_ucmd!().arg(flag).succeeds();
|
||||
}
|
||||
|
||||
for &flag in &[
|
||||
for flag in [
|
||||
"-t", "--type", "-u", "--user", "-r", "--role", "-l", "--range",
|
||||
] {
|
||||
new_ucmd!().args(&[flag, "example"]).succeeds();
|
||||
|
@ -57,7 +57,7 @@ fn invalid() {
|
|||
// TODO: Enable this code once the issue is fixed in the clap version we're using.
|
||||
//new_ucmd!().arg("--compute=example").fails().code_is(1);
|
||||
|
||||
for &flag in &[
|
||||
for flag in [
|
||||
"-t", "--type", "-u", "--user", "-r", "--role", "-l", "--range",
|
||||
] {
|
||||
new_ucmd!().arg(flag).fails().code_is(1);
|
||||
|
@ -119,7 +119,7 @@ fn custom_context() {
|
|||
let args = &["--compute", "--range=s0", "/bin/true"];
|
||||
new_ucmd!().args(args).succeeds();
|
||||
|
||||
for &(ctx, u, r) in &[
|
||||
for (ctx, u, r) in [
|
||||
("unconfined_u:unconfined_r:unconfined_t:s0", u_ud, r_ud),
|
||||
("system_u:unconfined_r:unconfined_t:s0", "system_u", r_ud),
|
||||
("unconfined_u:system_r:unconfined_t:s0", u_ud, "system_r"),
|
||||
|
|
|
@ -220,7 +220,7 @@ fn test_random_shuffle_contains_all_lines() {
|
|||
|
||||
#[test]
|
||||
fn test_random_shuffle_two_runs_not_the_same() {
|
||||
for arg in &["-R", "-k1,1R"] {
|
||||
for arg in ["-R", "-k1,1R"] {
|
||||
// check to verify that two random shuffles are not equal; this has the
|
||||
// potential to fail in the very unlikely event that the random order is the same
|
||||
// as the starting order, or if both random sorts end up having the same order.
|
||||
|
@ -407,7 +407,7 @@ fn test_mixed_floats_ints_chars_numeric_stable() {
|
|||
|
||||
#[test]
|
||||
fn test_numeric_floats_and_ints2() {
|
||||
for numeric_sort_param in &["-n", "--numeric-sort"] {
|
||||
for numeric_sort_param in ["-n", "--numeric-sort"] {
|
||||
let input = "1.444\n8.013\n1\n-8\n1.04\n-1";
|
||||
new_ucmd!()
|
||||
.arg(numeric_sort_param)
|
||||
|
@ -419,7 +419,7 @@ fn test_numeric_floats_and_ints2() {
|
|||
|
||||
#[test]
|
||||
fn test_numeric_floats2() {
|
||||
for numeric_sort_param in &["-n", "--numeric-sort"] {
|
||||
for numeric_sort_param in ["-n", "--numeric-sort"] {
|
||||
let input = "1.444\n8.013\n1.58590\n-8.90880\n1.040000000\n-.05";
|
||||
new_ucmd!()
|
||||
.arg(numeric_sort_param)
|
||||
|
@ -439,7 +439,7 @@ fn test_numeric_floats_with_nan2() {
|
|||
|
||||
#[test]
|
||||
fn test_human_block_sizes2() {
|
||||
for human_numeric_sort_param in &["-h", "--human-numeric-sort", "--sort=human-numeric"] {
|
||||
for human_numeric_sort_param in ["-h", "--human-numeric-sort", "--sort=human-numeric"] {
|
||||
let input = "8981K\n909991M\n-8T\n21G\n0.8M";
|
||||
new_ucmd!()
|
||||
.arg(human_numeric_sort_param)
|
||||
|
@ -461,7 +461,7 @@ fn test_human_numeric_zero_stable() {
|
|||
|
||||
#[test]
|
||||
fn test_month_default2() {
|
||||
for month_sort_param in &["-M", "--month-sort", "--sort=month"] {
|
||||
for month_sort_param in ["-M", "--month-sort", "--sort=month"] {
|
||||
let input = "JAn\nMAY\n000may\nJun\nFeb";
|
||||
new_ucmd!()
|
||||
.arg(month_sort_param)
|
||||
|
@ -555,7 +555,7 @@ fn test_keys_invalid_char_zero() {
|
|||
#[test]
|
||||
fn test_keys_with_options() {
|
||||
let input = "aa 3 cc\ndd 1 ff\ngg 2 cc\n";
|
||||
for param in &[
|
||||
for param in [
|
||||
&["-k", "2,2n"][..],
|
||||
&["-k", "2n,2"][..],
|
||||
&["-k", "2,2", "-n"][..],
|
||||
|
@ -571,7 +571,7 @@ fn test_keys_with_options() {
|
|||
#[test]
|
||||
fn test_keys_with_options_blanks_start() {
|
||||
let input = "aa 3 cc\ndd 1 ff\ngg 2 cc\n";
|
||||
for param in &[&["-k", "2b,2"][..], &["-k", "2,2", "-b"][..]] {
|
||||
for param in [&["-k", "2b,2"][..], &["-k", "2,2", "-b"][..]] {
|
||||
new_ucmd!()
|
||||
.args(param)
|
||||
.pipe_in(input)
|
||||
|
@ -761,7 +761,7 @@ fn test_pipe() {
|
|||
|
||||
#[test]
|
||||
fn test_check() {
|
||||
for diagnose_arg in &["-c", "--check", "--check=diagnose-first"] {
|
||||
for diagnose_arg in ["-c", "--check", "--check=diagnose-first"] {
|
||||
new_ucmd!()
|
||||
.arg(diagnose_arg)
|
||||
.arg("check_fail.txt")
|
||||
|
@ -779,7 +779,7 @@ fn test_check() {
|
|||
|
||||
#[test]
|
||||
fn test_check_silent() {
|
||||
for silent_arg in &["-C", "--check=silent", "--check=quiet"] {
|
||||
for silent_arg in ["-C", "--check=silent", "--check=quiet"] {
|
||||
new_ucmd!()
|
||||
.arg(silent_arg)
|
||||
.arg("check_fail.txt")
|
||||
|
@ -803,7 +803,7 @@ fn test_check_unique() {
|
|||
#[test]
|
||||
fn test_dictionary_and_nonprinting_conflicts() {
|
||||
let conflicting_args = ["n", "h", "g", "M"];
|
||||
for restricted_arg in &["d", "i"] {
|
||||
for restricted_arg in ["d", "i"] {
|
||||
for conflicting_arg in &conflicting_args {
|
||||
new_ucmd!()
|
||||
.arg(&format!("-{}{}", restricted_arg, conflicting_arg))
|
||||
|
|
|
@ -236,7 +236,7 @@ fn test_symlinks() {
|
|||
|
||||
let mut tested: bool = false;
|
||||
// arbitrarily chosen symlinks with hope that the CI environment provides at least one of them
|
||||
for file in &[
|
||||
for file in [
|
||||
"/bin/sh",
|
||||
"/bin/sudoedit",
|
||||
"/usr/bin/ex",
|
||||
|
|
|
@ -676,7 +676,7 @@ fn test_bytes_for_funny_files() {
|
|||
// gnu/tests/tail-2/tail-c.sh
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
for &file in &["/proc/version", "/sys/kernel/profiling"] {
|
||||
for file in ["/proc/version", "/sys/kernel/profiling"] {
|
||||
if !at.file_exists(file) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ fn test_tee_processing_multiple_operands() {
|
|||
// POSIX says: "Processing of at least 13 file operands shall be supported."
|
||||
|
||||
let content = "tee_sample_content";
|
||||
for &n in &[1, 2, 12, 13] {
|
||||
for n in [1, 2, 12, 13] {
|
||||
let files = (1..=n).map(|x| x.to_string()).collect::<Vec<_>>();
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ fn test_command_with_args() {
|
|||
|
||||
#[test]
|
||||
fn test_verbose() {
|
||||
for &verbose_flag in &["-v", "--verbose"] {
|
||||
for verbose_flag in ["-v", "--verbose"] {
|
||||
new_ucmd!()
|
||||
.args(&[verbose_flag, ".1", "sleep", "10"])
|
||||
.fails()
|
||||
|
|
|
@ -333,7 +333,7 @@ fn test_touch_reference() {
|
|||
at.touch(file_a);
|
||||
set_file_times(&at, file_a, start_of_year, start_of_year);
|
||||
assert!(at.file_exists(file_a));
|
||||
for &opt in &["-r", "--ref", "--reference"] {
|
||||
for opt in ["-r", "--ref", "--reference"] {
|
||||
scenario
|
||||
.ccmd("touch")
|
||||
.args(&[opt, file_a, file_b])
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// spell-checker:ignore nabcd
|
||||
use crate::common::util::*;
|
||||
|
||||
static INPUT: &str = "sorted.txt";
|
||||
|
@ -194,3 +195,713 @@ fn test_group_separate() {
|
|||
.run()
|
||||
.stdout_is_fixture("group.expected");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_case2() {
|
||||
new_ucmd!().pipe_in("a\na\n").run().stdout_is("a\n");
|
||||
}
|
||||
|
||||
struct TestCase {
|
||||
name: &'static str,
|
||||
args: &'static [&'static str],
|
||||
input: &'static str,
|
||||
stdout: Option<&'static str>,
|
||||
stderr: Option<&'static str>,
|
||||
exit: Option<i32>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gnu_tests() {
|
||||
let cases = [
|
||||
TestCase {
|
||||
name: "1",
|
||||
args: &[],
|
||||
input: "",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "2",
|
||||
args: &[],
|
||||
input: "a\na\n",
|
||||
stdout: Some("a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "3",
|
||||
args: &[],
|
||||
input: "a\na",
|
||||
stdout: Some("a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "4",
|
||||
args: &[],
|
||||
input: "a\nb",
|
||||
stdout: Some("a\nb\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "5",
|
||||
args: &[],
|
||||
input: "a\na\nb",
|
||||
stdout: Some("a\nb\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "6",
|
||||
args: &[],
|
||||
input: "b\na\na\n",
|
||||
stdout: Some("b\na\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "7",
|
||||
args: &[],
|
||||
input: "a\nb\nc\n",
|
||||
stdout: Some("a\nb\nc\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "2z",
|
||||
args: &["-z"],
|
||||
input: "a\na\n",
|
||||
stdout: Some("a\na\n\0"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "3z",
|
||||
args: &["-z"],
|
||||
input: "a\na",
|
||||
stdout: Some("a\na\0"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "4z",
|
||||
args: &["-z"],
|
||||
input: "a\nb",
|
||||
stdout: Some("a\nb\0"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "5z",
|
||||
args: &["-z"],
|
||||
input: "a\na\nb",
|
||||
stdout: Some("a\na\nb\0"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "10z",
|
||||
args: &["-z", "-f1"],
|
||||
input: "a\nb\n\0c\nb\n\0",
|
||||
stdout: Some("a\nb\n\0"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "20z",
|
||||
args: &["-dz"],
|
||||
input: "a\na\n",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "8",
|
||||
args: &[],
|
||||
input: "ö\nv\n",
|
||||
stdout: Some("ö\nv\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "9",
|
||||
args: &["-u"],
|
||||
input: "a\na\n",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "10",
|
||||
args: &["-u"],
|
||||
input: "a\nb\n",
|
||||
stdout: Some("a\nb\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "11",
|
||||
args: &["-u"],
|
||||
input: "a\nb\na\n",
|
||||
stdout: Some("a\nb\na\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "12",
|
||||
args: &["-u"],
|
||||
input: "a\na\n",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "13",
|
||||
args: &["-u"],
|
||||
input: "a\na\n",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "20",
|
||||
args: &["-d"],
|
||||
input: "a\na\n",
|
||||
stdout: Some("a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "21",
|
||||
args: &["-d"],
|
||||
input: "a\nb\n",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "22",
|
||||
args: &["-d"],
|
||||
input: "a\nb\na\n",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "23",
|
||||
args: &["-d"],
|
||||
input: "a\na\nb\n",
|
||||
stdout: Some("a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
// // Obsolete syntax for "-f 1"
|
||||
// TestCase {
|
||||
// name: "obs30",
|
||||
// args: &["-1"],
|
||||
// input: "a a\nb a\n",
|
||||
// stdout: Some("a a\n"),
|
||||
// stderr: None,
|
||||
// exit: None,
|
||||
// },
|
||||
TestCase {
|
||||
name: "31",
|
||||
args: &["-f", "1"],
|
||||
input: "a a\nb a\n",
|
||||
stdout: Some("a a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "32",
|
||||
args: &["-f", "1"],
|
||||
input: "a a\nb b\n",
|
||||
stdout: Some("a a\nb b\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "33",
|
||||
args: &["-f", "1"],
|
||||
input: "a a a\nb a c\n",
|
||||
stdout: Some("a a a\nb a c\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "34",
|
||||
args: &["-f", "1"],
|
||||
input: "b a\na a\n",
|
||||
stdout: Some("b a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "35",
|
||||
args: &["-f", "2"],
|
||||
input: "a a c\nb a c\n",
|
||||
stdout: Some("a a c\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
// // Obsolete syntax for "-s 1"
|
||||
// TestCase {
|
||||
// name: "obs-plus40",
|
||||
// args: &["+1"],
|
||||
// input: "aaa\naaa\n",
|
||||
// stdout: Some("aaa\n"),
|
||||
// stderr: None,
|
||||
// exit: None,
|
||||
// },
|
||||
// TestCase {
|
||||
// name: "obs-plus41",
|
||||
// args: &["+1"],
|
||||
// input: "baa\naaa\n",
|
||||
// stdout: Some("baa\n"),
|
||||
// stderr: None,
|
||||
// exit: None,
|
||||
// },
|
||||
TestCase {
|
||||
name: "42",
|
||||
args: &["-s", "1"],
|
||||
input: "aaa\naaa\n",
|
||||
stdout: Some("aaa\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "43",
|
||||
args: &["-s", "2"],
|
||||
input: "baa\naaa\n",
|
||||
stdout: Some("baa\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
// // Obsolete syntax for "-s 1"
|
||||
// TestCase {
|
||||
// name: "obs-plus44",
|
||||
// args: &["+1", "--"],
|
||||
// input: "aaa\naaa\n",
|
||||
// stdout: Some("aaa\n"),
|
||||
// stderr: None,
|
||||
// exit: None,
|
||||
// },
|
||||
// TestCase {
|
||||
// name: "obs-plus45",
|
||||
// args: &["+1", "--"],
|
||||
// input: "baa\naaa\n",
|
||||
// stdout: Some("baa\n"),
|
||||
// stderr: None,
|
||||
// exit: None,
|
||||
// },
|
||||
TestCase {
|
||||
name: "50",
|
||||
args: &["-f", "1", "-s", "1"],
|
||||
input: "a aaa\nb ab\n",
|
||||
stdout: Some("a aaa\nb ab\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "51",
|
||||
args: &["-f", "1", "-s", "1"],
|
||||
input: "a aaa\nb aaa\n",
|
||||
stdout: Some("a aaa\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "52",
|
||||
args: &["-s", "1", "-f", "1"],
|
||||
input: "a aaa\nb ab\n",
|
||||
stdout: Some("a aaa\nb ab\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "53",
|
||||
args: &["-s", "1", "-f", "1"],
|
||||
input: "a aaa\nb aaa\n",
|
||||
stdout: Some("a aaa\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "54",
|
||||
args: &["-s", "4"],
|
||||
input: "abc\nabcd\n",
|
||||
stdout: Some("abc\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "55",
|
||||
args: &["-s", "0"],
|
||||
input: "abc\nabcd\n",
|
||||
stdout: Some("abc\nabcd\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "56",
|
||||
args: &["-s", "0"],
|
||||
input: "abc\n",
|
||||
stdout: Some("abc\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "57",
|
||||
args: &["-w", "0"],
|
||||
input: "abc\nabcd\n",
|
||||
stdout: Some("abc\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "60",
|
||||
args: &["-w", "1"],
|
||||
input: "a a\nb a\n",
|
||||
stdout: Some("a a\nb a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "61",
|
||||
args: &["-w", "3"],
|
||||
input: "a a\nb a\n",
|
||||
stdout: Some("a a\nb a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "62",
|
||||
args: &["-w", "1", "-f", "1"],
|
||||
input: "a a a\nb a c\n",
|
||||
stdout: Some("a a a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "63",
|
||||
args: &["-f", "1", "-w", "1"],
|
||||
input: "a a a\nb a c\n",
|
||||
stdout: Some("a a a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "64",
|
||||
args: &["-f", "1", "-w", "4"],
|
||||
input: "a a a\nb a c\n",
|
||||
stdout: Some("a a a\nb a c\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "65",
|
||||
args: &["-f", "1", "-w", "3"],
|
||||
input: "a a a\nb a c\n",
|
||||
stdout: Some("a a a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "90",
|
||||
args: &[],
|
||||
input: "a\0a\na\n",
|
||||
stdout: Some("a\0a\na\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "91",
|
||||
args: &[],
|
||||
input: "a\ta\na a\n",
|
||||
stdout: Some("a\ta\na a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "92",
|
||||
args: &["-f", "1"],
|
||||
input: "a\ta\na a\n",
|
||||
stdout: Some("a\ta\na a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "93",
|
||||
args: &["-f", "2"],
|
||||
input: "a\ta a\na a a\n",
|
||||
stdout: Some("a\ta a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "94",
|
||||
args: &["-f", "1"],
|
||||
input: "a\ta\na\ta\n",
|
||||
stdout: Some("a\ta\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "101",
|
||||
args: &["-c"],
|
||||
input: "a\nb\n",
|
||||
stdout: Some(" 1 a\n 1 b\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "102",
|
||||
args: &["-c"],
|
||||
input: "a\na\n",
|
||||
stdout: Some(" 2 a\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "110",
|
||||
args: &["-D"],
|
||||
input: "a\na\n",
|
||||
stdout: Some("a\na\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "111",
|
||||
args: &["-D", "-w1"],
|
||||
input: "a a\na b\n",
|
||||
stdout: Some("a a\na b\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "112",
|
||||
args: &["-D", "-c"],
|
||||
input: "a a\na b\n",
|
||||
stdout: Some(""),
|
||||
stderr: Some("uniq: printing all duplicated lines and repeat counts is meaningless"),
|
||||
exit: Some(1),
|
||||
},
|
||||
TestCase {
|
||||
name: "113",
|
||||
args: &["--all-repeated=separate"],
|
||||
input: "a\na\n",
|
||||
stdout: Some("a\na\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "114",
|
||||
args: &["--all-repeated=separate"],
|
||||
input: "a\na\nb\nc\nc\n",
|
||||
stdout: Some("a\na\n\nc\nc\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "115",
|
||||
args: &["--all-repeated=separate"],
|
||||
input: "a\na\nb\nb\nc\n",
|
||||
stdout: Some("a\na\n\nb\nb\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "116",
|
||||
args: &["--all-repeated=prepend"],
|
||||
input: "a\na\n",
|
||||
stdout: Some("\na\na\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "117",
|
||||
args: &["--all-repeated=prepend"],
|
||||
input: "a\na\nb\nc\nc\n",
|
||||
stdout: Some("\na\na\n\nc\nc\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "118",
|
||||
args: &["--all-repeated=prepend"],
|
||||
input: "a\nb\n",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
// \x08 is the backspace char
|
||||
TestCase {
|
||||
name: "120",
|
||||
args: &["-d", "-u"],
|
||||
input: "a\na\n\x08",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "123",
|
||||
args: &["--zero-terminated"],
|
||||
input: "a\na\nb",
|
||||
stdout: Some("a\na\nb\0"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "124",
|
||||
args: &["--zero-terminated"],
|
||||
input: "a\0a\0b",
|
||||
stdout: Some("a\0b\0"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "125",
|
||||
args: &[],
|
||||
input: "A\na\n",
|
||||
stdout: Some("A\na\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "126",
|
||||
args: &["-i"],
|
||||
input: "A\na\n",
|
||||
stdout: Some("A\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "127",
|
||||
args: &["--ignore-case"],
|
||||
input: "A\na\n",
|
||||
stdout: Some("A\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "128",
|
||||
args: &["--group=prepend"],
|
||||
input: "a\na\nb\n",
|
||||
stdout: Some("\na\na\n\nb\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "129",
|
||||
args: &["--group=append"],
|
||||
input: "a\na\nb\n",
|
||||
stdout: Some("a\na\n\nb\n\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "130",
|
||||
args: &["--group=separate"],
|
||||
input: "a\na\nb\n",
|
||||
stdout: Some("a\na\n\nb\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "131",
|
||||
args: &["--group"],
|
||||
input: "a\na\nb\n",
|
||||
stdout: Some("a\na\n\nb\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "132",
|
||||
args: &["--group=both"],
|
||||
input: "a\na\nb\n",
|
||||
stdout: Some("\na\na\n\nb\n\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "133",
|
||||
args: &["--group=prepend"],
|
||||
input: "a\na\n",
|
||||
stdout: Some("\na\na\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "134",
|
||||
args: &["--group=append"],
|
||||
input: "a\na\n",
|
||||
stdout: Some("a\na\n\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "135",
|
||||
args: &["--group=separate"],
|
||||
input: "a\na\n",
|
||||
stdout: Some("a\na\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "136",
|
||||
args: &["--group"],
|
||||
input: "a\na\n",
|
||||
stdout: Some("a\na\n"),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "137",
|
||||
args: &["--group=prepend"],
|
||||
input: "",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "138",
|
||||
args: &["--group=append"],
|
||||
input: "",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "139",
|
||||
args: &["--group=separate"],
|
||||
input: "",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
TestCase {
|
||||
name: "140",
|
||||
args: &["--group=both"],
|
||||
input: "",
|
||||
stdout: Some(""),
|
||||
stderr: None,
|
||||
exit: None,
|
||||
},
|
||||
];
|
||||
|
||||
for case in cases {
|
||||
eprintln!("Test {}", case.name);
|
||||
let result = new_ucmd!().args(case.args).run_piped_stdin(case.input);
|
||||
if let Some(stdout) = case.stdout {
|
||||
result.stdout_is(stdout);
|
||||
}
|
||||
if let Some(stderr) = case.stderr {
|
||||
result.stderr_contains(stderr);
|
||||
}
|
||||
if let Some(exit) = case.exit {
|
||||
result.code_is(exit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
55
tests/by-util/test_vdir.rs
Normal file
55
tests/by-util/test_vdir.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
#[cfg(not(windows))]
|
||||
extern crate libc;
|
||||
extern crate regex;
|
||||
#[cfg(not(windows))]
|
||||
extern crate tempfile;
|
||||
#[cfg(unix)]
|
||||
extern crate unix_socket;
|
||||
|
||||
use self::regex::Regex;
|
||||
use crate::common::util::*;
|
||||
|
||||
/*
|
||||
* As vdir use the same functions than ls, we don't have to retest them here.
|
||||
* We just test the default and the column output
|
||||
*/
|
||||
|
||||
#[test]
|
||||
fn test_vdir() {
|
||||
new_ucmd!().succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_output() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.mkdir("some-dir1");
|
||||
at.touch("some-file1");
|
||||
|
||||
scene.ucmd().succeeds().stdout_contains("some-file1");
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.succeeds()
|
||||
.stdout_matches(&Regex::new("[rwx][^some-file1]").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_column_output() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
at.mkdir("some-dir1");
|
||||
at.touch("some-file1");
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-C")
|
||||
.succeeds()
|
||||
.stdout_contains("some-file1");
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-C")
|
||||
.succeeds()
|
||||
.stdout_does_not_match(&Regex::new("[rwx][^some-file1]").unwrap());
|
||||
}
|
|
@ -7,7 +7,7 @@ use crate::common::util::*;
|
|||
|
||||
#[test]
|
||||
fn test_count_bytes_large_stdin() {
|
||||
for &n in &[
|
||||
for n in [
|
||||
0,
|
||||
1,
|
||||
42,
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::common::util::*;
|
|||
#[ignore = "issue #3219"]
|
||||
fn test_count() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for opt in &["-q", "--count", "--c"] {
|
||||
for opt in ["-q", "--count", "--c"] {
|
||||
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
|
||||
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ fn test_count() {
|
|||
#[test]
|
||||
fn test_boot() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for opt in &["-b", "--boot", "--b"] {
|
||||
for opt in ["-b", "--boot", "--b"] {
|
||||
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
|
||||
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ fn test_boot() {
|
|||
#[ignore = "issue #3219"]
|
||||
fn test_heading() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for opt in &["-H", "--heading", "--head"] {
|
||||
for opt in ["-H", "--heading", "--head"] {
|
||||
// allow whitespace variation
|
||||
// * minor whitespace differences occur between platform built-in outputs;
|
||||
// specifically number of TABs between "TIME" and "COMMENT" may be variant
|
||||
|
@ -52,7 +52,7 @@ fn test_heading() {
|
|||
#[ignore = "issue #3219"]
|
||||
fn test_short() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for opt in &["-s", "--short", "--s"] {
|
||||
for opt in ["-s", "--short", "--s"] {
|
||||
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
|
||||
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ fn test_short() {
|
|||
#[test]
|
||||
fn test_login() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for opt in &["-l", "--login", "--log"] {
|
||||
for opt in ["-l", "--login", "--log"] {
|
||||
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
|
||||
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ fn test_m() {
|
|||
#[test]
|
||||
fn test_process() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for opt in &["-p", "--process", "--p"] {
|
||||
for opt in ["-p", "--process", "--p"] {
|
||||
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
|
||||
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ fn test_process() {
|
|||
#[test]
|
||||
fn test_runlevel() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for opt in &["-r", "--runlevel", "--r"] {
|
||||
for opt in ["-r", "--runlevel", "--r"] {
|
||||
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
|
||||
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||
|
||||
|
@ -103,7 +103,7 @@ fn test_runlevel() {
|
|||
#[test]
|
||||
fn test_time() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for opt in &["-t", "--time", "--t"] {
|
||||
for opt in ["-t", "--time", "--t"] {
|
||||
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
|
||||
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ fn test_mesg() {
|
|||
// --writable
|
||||
// same as -T
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for opt in &[
|
||||
for opt in [
|
||||
"-T",
|
||||
"-w",
|
||||
"--mesg",
|
||||
|
@ -157,7 +157,7 @@ fn test_too_many_args() {
|
|||
#[ignore = "issue #3219"]
|
||||
fn test_users() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for opt in &["-u", "--users", "--us"] {
|
||||
for opt in ["-u", "--users", "--us"] {
|
||||
let actual = ts.ucmd().arg(opt).succeeds().stdout_move_str();
|
||||
let expect = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
|
||||
println!("actual: {:?}", actual);
|
||||
|
@ -192,7 +192,7 @@ fn test_lookup() {
|
|||
#[test]
|
||||
fn test_dead() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for opt in &["-d", "--dead", "--de"] {
|
||||
for opt in ["-d", "--dead", "--de"] {
|
||||
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
|
||||
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ fn test_all() {
|
|||
}
|
||||
|
||||
let ts = TestScenario::new(util_name!());
|
||||
for opt in &["-a", "--all", "--a"] {
|
||||
for opt in ["-a", "--all", "--a"] {
|
||||
let expected_stdout = unwrap_or_return!(expected_result(&ts, &[opt])).stdout_move_str();
|
||||
ts.ucmd().arg(opt).succeeds().stdout_is(expected_stdout);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ fn test_long_input() {
|
|||
fn test_piped_to_dev_full() {
|
||||
use std::fs::OpenOptions;
|
||||
|
||||
for &append in &[true, false] {
|
||||
for append in [true, false] {
|
||||
{
|
||||
let dev_full = OpenOptions::new()
|
||||
.write(true)
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
// * For the full copyright and license information, please view the LICENSE
|
||||
// * file that was distributed with this source code.
|
||||
|
||||
//spell-checker: ignore (linux) rlimit prlimit Rlim coreutil ggroups
|
||||
//spell-checker: ignore (linux) rlimit prlimit coreutil ggroups
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
#[cfg(target_os = "linux")]
|
||||
use rlimit::{prlimit, rlim};
|
||||
use rlimit::prlimit;
|
||||
#[cfg(unix)]
|
||||
use std::borrow::Cow;
|
||||
use std::env;
|
||||
|
@ -221,7 +221,7 @@ impl CmdResult {
|
|||
assert!(
|
||||
self.stdout.is_empty(),
|
||||
"Expected stdout to be empty, but it's:\n{}",
|
||||
self.stderr_str()
|
||||
self.stdout_str()
|
||||
);
|
||||
self
|
||||
}
|
||||
|
@ -893,7 +893,7 @@ pub struct UCommand {
|
|||
stderr: Option<Stdio>,
|
||||
bytes_into_stdin: Option<Vec<u8>>,
|
||||
#[cfg(target_os = "linux")]
|
||||
limits: Vec<(rlimit::Resource, rlim, rlim)>,
|
||||
limits: Vec<(rlimit::Resource, u64, u64)>,
|
||||
}
|
||||
|
||||
impl UCommand {
|
||||
|
@ -1046,8 +1046,8 @@ impl UCommand {
|
|||
pub fn with_limit(
|
||||
&mut self,
|
||||
resource: rlimit::Resource,
|
||||
soft_limit: rlim,
|
||||
hard_limit: rlim,
|
||||
soft_limit: u64,
|
||||
hard_limit: u64,
|
||||
) -> &mut Self {
|
||||
self.limits.push((resource, soft_limit, hard_limit));
|
||||
self
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue