mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
Fix clippy warnings
This commit is contained in:
parent
9db91285bd
commit
b3680a5baf
6 changed files with 29 additions and 38 deletions
|
@ -321,13 +321,12 @@ impl AtPath {
|
||||||
|
|
||||||
pub fn cleanup(&self, path: &'static str) {
|
pub fn cleanup(&self, path: &'static str) {
|
||||||
let p = &self.plus(path);
|
let p = &self.plus(path);
|
||||||
match fs::metadata(p) {
|
if let Ok(m) = fs::metadata(p) {
|
||||||
Ok(m) => if m.is_file() {
|
if m.is_file() {
|
||||||
fs::remove_file(&p).unwrap();
|
fs::remove_file(&p).unwrap();
|
||||||
} else {
|
} else {
|
||||||
fs::remove_dir(&p).unwrap();
|
fs::remove_dir(&p).unwrap();
|
||||||
},
|
}
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,21 +375,20 @@ impl TestScenario {
|
||||||
// directory, use Cargo's OUT_DIR to find path to executable.
|
// directory, use Cargo's OUT_DIR to find path to executable.
|
||||||
// This allows tests to be run using profiles other than debug.
|
// This allows tests to be run using profiles other than debug.
|
||||||
let target_dir = path_concat!(env::var("OUT_DIR").unwrap(), "..", "..", "..", PROGNAME);
|
let target_dir = path_concat!(env::var("OUT_DIR").unwrap(), "..", "..", "..", PROGNAME);
|
||||||
PathBuf::from(AtPath::new(&Path::new(&target_dir)).root_dir_resolved())
|
PathBuf::from(AtPath::new(Path::new(&target_dir)).root_dir_resolved())
|
||||||
},
|
},
|
||||||
util_name: String::from(util_name),
|
util_name: String::from(util_name),
|
||||||
fixtures: AtPath::new(&tmpd.as_ref().path()),
|
fixtures: AtPath::new(tmpd.as_ref().path()),
|
||||||
tmpd: tmpd,
|
tmpd: tmpd,
|
||||||
};
|
};
|
||||||
let mut fixture_path_builder = env::current_dir().unwrap();
|
let mut fixture_path_builder = env::current_dir().unwrap();
|
||||||
fixture_path_builder.push(TESTS_DIR);
|
fixture_path_builder.push(TESTS_DIR);
|
||||||
fixture_path_builder.push(FIXTURES_DIR);
|
fixture_path_builder.push(FIXTURES_DIR);
|
||||||
fixture_path_builder.push(util_name);
|
fixture_path_builder.push(util_name);
|
||||||
match fs::metadata(&fixture_path_builder) {
|
if let Ok(m) = fs::metadata(&fixture_path_builder) {
|
||||||
Ok(m) => if m.is_dir() {
|
if m.is_dir() {
|
||||||
recursive_copy(&fixture_path_builder, &ts.fixtures.subdir).unwrap();
|
recursive_copy(&fixture_path_builder, &ts.fixtures.subdir).unwrap();
|
||||||
},
|
}
|
||||||
Err(_) => {}
|
|
||||||
}
|
}
|
||||||
ts
|
ts
|
||||||
}
|
}
|
||||||
|
@ -418,7 +416,7 @@ impl TestScenario {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A UCommand is a wrapper around an individual Command that provides several additional features
|
/// A `UCommand` is a wrapper around an individual Command that provides several additional features
|
||||||
/// 1. it has convenience functions that are more ergonomic to use for piping in stdin, spawning the command
|
/// 1. it has convenience functions that are more ergonomic to use for piping in stdin, spawning the command
|
||||||
/// and asserting on the results.
|
/// and asserting on the results.
|
||||||
/// 2. it tracks arguments provided so that in test cases which may provide variations of an arg in loops
|
/// 2. it tracks arguments provided so that in test cases which may provide variations of an arg in loops
|
||||||
|
@ -542,7 +540,7 @@ impl UCommand {
|
||||||
.unwrap_or_else(
|
.unwrap_or_else(
|
||||||
|| panic!(
|
|| panic!(
|
||||||
"Could not take child process stdin"))
|
"Could not take child process stdin"))
|
||||||
.write_all(&input)
|
.write_all(input)
|
||||||
.unwrap_or_else(|e| panic!("{}", e));
|
.unwrap_or_else(|e| panic!("{}", e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ fn test_output_multi_files_print_all_chars() {
|
||||||
fn test_stdin_show_nonprinting() {
|
fn test_stdin_show_nonprinting() {
|
||||||
for same_param in vec!["-v", "--show-nonprinting"] {
|
for same_param in vec!["-v", "--show-nonprinting"] {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&vec![same_param])
|
.args(&[same_param])
|
||||||
.pipe_in("\t\0\n")
|
.pipe_in("\t\0\n")
|
||||||
.succeeds()
|
.succeeds()
|
||||||
.stdout_only("\t^@");
|
.stdout_only("\t^@");
|
||||||
|
|
|
@ -35,7 +35,7 @@ fn test_padding_with_overflow() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_sections_and_styles() {
|
fn test_sections_and_styles() {
|
||||||
for &(fixture, output) in [("section.txt",
|
for &(fixture, output) in &[("section.txt",
|
||||||
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 \
|
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 \
|
||||||
|BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 \
|
|BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 \
|
||||||
|NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n"),
|
|NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n"),
|
||||||
|
@ -44,7 +44,7 @@ fn test_sections_and_styles() {
|
||||||
|\n\n\n\n\n5 |\n6 |Followed by 5x empty\n\n\n\n\n7 |\n8 \
|
|\n\n\n\n\n5 |\n6 |Followed by 5x empty\n\n\n\n\n7 |\n8 \
|
||||||
|Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 \
|
|Followed by 4x empty\n\n\n\n\n9 |Nonempty\n10 |Nonempty\n11 \
|
||||||
|Nonempty.\n")]
|
|Nonempty.\n")]
|
||||||
.iter() {
|
{
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.args(&["-s", "|", "-n", "ln", "-w", "3", "-b", "a", "-l", "5", fixture])
|
.args(&["-s", "|", "-n", "ln", "-w", "3", "-b", "a", "-l", "5", fixture])
|
||||||
.run()
|
.run()
|
||||||
|
|
|
@ -29,9 +29,8 @@ fn test_file() {
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut f = File::create(&file).unwrap();
|
let mut f = File::create(&file).unwrap();
|
||||||
match f.write_all(b"abcdefghijklmnopqrstuvwxyz\n") {
|
if f.write_all(b"abcdefghijklmnopqrstuvwxyz\n").is_err() {
|
||||||
Err(_) => panic!("Test setup failed - could not write file"),
|
panic!("Test setup failed - could not write file");
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,15 +51,14 @@ fn test_2files() {
|
||||||
let file1 = tmpdir.join("test1");
|
let file1 = tmpdir.join("test1");
|
||||||
let file2 = tmpdir.join("test2");
|
let file2 = tmpdir.join("test2");
|
||||||
|
|
||||||
for &(n,a) in [(1,"a"), (2,"b")].iter() {
|
for &(n,a) in &[(1,"a"), (2,"b")] {
|
||||||
println!("number: {} letter:{}", n, a);
|
println!("number: {} letter:{}", n, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
let mut f = File::create(&path).unwrap();
|
||||||
match f.write_all(data.as_bytes()) {
|
if f.write_all(data.as_bytes()).is_err() {
|
||||||
Err(_) => panic!("Test setup failed - could not write file"),
|
panic!("Test setup failed - could not write file");
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,9 +106,8 @@ fn test_from_mixed() {
|
||||||
let (data1, data2, data3) = ("abcdefg","hijklmnop","qrstuvwxyz\n");
|
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();
|
let mut f = File::create(&path).unwrap();
|
||||||
match f.write_all(data.as_bytes()) {
|
if f.write_all(data.as_bytes()).is_err() {
|
||||||
Err(_) => panic!("Test setup failed - could not write file"),
|
panic!("Test setup failed - could not write file");
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl Glob {
|
||||||
let mut files = self.collect();
|
let mut files = self.collect();
|
||||||
files.sort();
|
files.sort();
|
||||||
let mut data: Vec<u8> = vec![];
|
let mut data: Vec<u8> = vec![];
|
||||||
for name in files.iter() {
|
for name in &files {
|
||||||
data.extend(self.directory.read(name).into_bytes());
|
data.extend(self.directory.read(name).into_bytes());
|
||||||
}
|
}
|
||||||
data
|
data
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
use common::util::*;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_count() {
|
fn test_count() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue