mirror of
https://github.com/uutils/coreutils
synced 2024-11-05 14:21:32 +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) {
|
||||
let p = &self.plus(path);
|
||||
match fs::metadata(p) {
|
||||
Ok(m) => if m.is_file() {
|
||||
if let Ok(m) = fs::metadata(p) {
|
||||
if m.is_file() {
|
||||
fs::remove_file(&p).unwrap();
|
||||
} else {
|
||||
fs::remove_dir(&p).unwrap();
|
||||
},
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -376,21 +375,20 @@ impl TestScenario {
|
|||
// directory, use Cargo's OUT_DIR to find path to executable.
|
||||
// This allows tests to be run using profiles other than debug.
|
||||
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),
|
||||
fixtures: AtPath::new(&tmpd.as_ref().path()),
|
||||
fixtures: AtPath::new(tmpd.as_ref().path()),
|
||||
tmpd: tmpd,
|
||||
};
|
||||
let mut fixture_path_builder = env::current_dir().unwrap();
|
||||
fixture_path_builder.push(TESTS_DIR);
|
||||
fixture_path_builder.push(FIXTURES_DIR);
|
||||
fixture_path_builder.push(util_name);
|
||||
match fs::metadata(&fixture_path_builder) {
|
||||
Ok(m) => if m.is_dir() {
|
||||
if let Ok(m) = fs::metadata(&fixture_path_builder) {
|
||||
if m.is_dir() {
|
||||
recursive_copy(&fixture_path_builder, &ts.fixtures.subdir).unwrap();
|
||||
},
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
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
|
||||
/// and asserting on the results.
|
||||
/// 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(
|
||||
|| panic!(
|
||||
"Could not take child process stdin"))
|
||||
.write_all(&input)
|
||||
.write_all(input)
|
||||
.unwrap_or_else(|e| panic!("{}", e));
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ fn test_output_multi_files_print_all_chars() {
|
|||
fn test_stdin_show_nonprinting() {
|
||||
for same_param in vec!["-v", "--show-nonprinting"] {
|
||||
new_ucmd!()
|
||||
.args(&vec![same_param])
|
||||
.args(&[same_param])
|
||||
.pipe_in("\t\0\n")
|
||||
.succeeds()
|
||||
.stdout_only("\t^@");
|
||||
|
|
|
@ -35,16 +35,16 @@ fn test_padding_with_overflow() {
|
|||
|
||||
#[test]
|
||||
fn test_sections_and_styles() {
|
||||
for &(fixture, output) in [("section.txt",
|
||||
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 \
|
||||
|BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 \
|
||||
|NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n"),
|
||||
("joinblanklines.txt",
|
||||
"1 |Nonempty\n2 |Nonempty\n3 |Followed by 10x empty\n\n\n\n\n4 \
|
||||
|\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 \
|
||||
|Nonempty.\n")]
|
||||
.iter() {
|
||||
for &(fixture, output) in &[("section.txt",
|
||||
"\nHEADER1\nHEADER2\n\n1 |BODY1\n2 \
|
||||
|BODY2\n\nFOOTER1\nFOOTER2\n\nNEXTHEADER1\nNEXTHEADER2\n\n1 \
|
||||
|NEXTBODY1\n2 |NEXTBODY2\n\nNEXTFOOTER1\nNEXTFOOTER2\n"),
|
||||
("joinblanklines.txt",
|
||||
"1 |Nonempty\n2 |Nonempty\n3 |Followed by 10x empty\n\n\n\n\n4 \
|
||||
|\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 \
|
||||
|Nonempty.\n")]
|
||||
{
|
||||
new_ucmd!()
|
||||
.args(&["-s", "|", "-n", "ln", "-w", "3", "-b", "a", "-l", "5", fixture])
|
||||
.run()
|
||||
|
|
|
@ -29,9 +29,8 @@ fn test_file() {
|
|||
|
||||
{
|
||||
let mut f = File::create(&file).unwrap();
|
||||
match f.write_all(b"abcdefghijklmnopqrstuvwxyz\n") {
|
||||
Err(_) => panic!("Test setup failed - could not write file"),
|
||||
_ => {}
|
||||
if f.write_all(b"abcdefghijklmnopqrstuvwxyz\n").is_err() {
|
||||
panic!("Test setup failed - could not write file");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,15 +51,14 @@ fn test_2files() {
|
|||
let file1 = tmpdir.join("test1");
|
||||
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);
|
||||
}
|
||||
|
||||
for &(path,data)in &[(&file1, "abcdefghijklmnop"),(&file2, "qrstuvwxyz\n")] {
|
||||
let mut f = File::create(&path).unwrap();
|
||||
match f.write_all(data.as_bytes()) {
|
||||
Err(_) => panic!("Test setup failed - could not write file"),
|
||||
_ => {}
|
||||
if f.write_all(data.as_bytes()).is_err() {
|
||||
panic!("Test setup failed - could not write file");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,9 +106,8 @@ fn test_from_mixed() {
|
|||
let (data1, data2, data3) = ("abcdefg","hijklmnop","qrstuvwxyz\n");
|
||||
for &(path,data)in &[(&file1, data1),(&file3, data3)] {
|
||||
let mut f = File::create(&path).unwrap();
|
||||
match f.write_all(data.as_bytes()) {
|
||||
Err(_) => panic!("Test setup failed - could not write file"),
|
||||
_ => {}
|
||||
if f.write_all(data.as_bytes()).is_err() {
|
||||
panic!("Test setup failed - could not write file");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ impl Glob {
|
|||
let mut files = self.collect();
|
||||
files.sort();
|
||||
let mut data: Vec<u8> = vec![];
|
||||
for name in files.iter() {
|
||||
for name in &files {
|
||||
data.extend(self.directory.read(name).into_bytes());
|
||||
}
|
||||
data
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
use common::util::*;
|
||||
|
||||
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn test_count() {
|
||||
|
|
Loading…
Reference in a new issue