mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 06:42:42 +00:00
Merge branch 'main' into printf-move-strings-to-md-files
This commit is contained in:
commit
c988e712a1
3 changed files with 43 additions and 12 deletions
|
@ -12,6 +12,7 @@ use std::borrow::Borrow;
|
|||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::Path;
|
||||
|
||||
use clap::{crate_version, Arg, ArgAction, Command};
|
||||
use uucore::display::Quotable;
|
||||
|
@ -42,7 +43,6 @@ pub enum OutputFmt {
|
|||
}
|
||||
|
||||
pub fn guess_syntax() -> OutputFmt {
|
||||
use std::path::Path;
|
||||
match env::var("SHELL") {
|
||||
Ok(ref s) if !s.is_empty() => {
|
||||
let shell_path: &Path = s.as_ref();
|
||||
|
@ -138,15 +138,26 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
let fin = BufReader::new(std::io::stdin());
|
||||
result = parse(fin.lines().filter_map(Result::ok), &out_format, files[0]);
|
||||
} else {
|
||||
match File::open(files[0]) {
|
||||
let path = Path::new(files[0]);
|
||||
if path.is_dir() {
|
||||
return Err(USimpleError::new(
|
||||
2,
|
||||
format!("expected file, got directory {}", path.quote()),
|
||||
));
|
||||
}
|
||||
match File::open(path) {
|
||||
Ok(f) => {
|
||||
let fin = BufReader::new(f);
|
||||
result = parse(fin.lines().filter_map(Result::ok), &out_format, files[0]);
|
||||
result = parse(
|
||||
fin.lines().map_while(Result::ok),
|
||||
&out_format,
|
||||
&path.to_string_lossy(),
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(USimpleError::new(
|
||||
1,
|
||||
format!("{}: {}", files[0].maybe_quote(), e),
|
||||
format!("{}: {}", path.maybe_quote(), e),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,3 +221,13 @@ fn test_helper(file_name: &str, term: &str) {
|
|||
.run()
|
||||
.stdout_is_fixture(format!("{file_name}.sh.expected"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dircolors_for_dir_as_file() {
|
||||
let result = new_ucmd!().args(&["-c", "/"]).fails();
|
||||
result.no_stdout();
|
||||
assert_eq!(
|
||||
result.stderr_str().trim(),
|
||||
"dircolors: expected file, got directory '/'",
|
||||
);
|
||||
}
|
||||
|
|
|
@ -475,9 +475,11 @@ fn test_total_auto() {
|
|||
new_ucmd!()
|
||||
.args(&["lorem_ipsum.txt", "moby_dick.txt", "--total=auto"])
|
||||
.run()
|
||||
.stdout_is(
|
||||
" 13 109 772 lorem_ipsum.txt\n 18 204 1115 moby_dick.txt\n 31 313 1887 total\n",
|
||||
);
|
||||
.stdout_is(concat!(
|
||||
" 13 109 772 lorem_ipsum.txt\n",
|
||||
" 18 204 1115 moby_dick.txt\n",
|
||||
" 31 313 1887 total\n",
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -485,14 +487,19 @@ fn test_total_always() {
|
|||
new_ucmd!()
|
||||
.args(&["lorem_ipsum.txt", "--total=always"])
|
||||
.run()
|
||||
.stdout_is(" 13 109 772 lorem_ipsum.txt\n 13 109 772 total\n");
|
||||
.stdout_is(concat!(
|
||||
" 13 109 772 lorem_ipsum.txt\n",
|
||||
" 13 109 772 total\n",
|
||||
));
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["lorem_ipsum.txt", "moby_dick.txt", "--total=always"])
|
||||
.run()
|
||||
.stdout_is(
|
||||
" 13 109 772 lorem_ipsum.txt\n 18 204 1115 moby_dick.txt\n 31 313 1887 total\n",
|
||||
);
|
||||
.stdout_is(concat!(
|
||||
" 13 109 772 lorem_ipsum.txt\n",
|
||||
" 18 204 1115 moby_dick.txt\n",
|
||||
" 31 313 1887 total\n",
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -505,7 +512,10 @@ fn test_total_never() {
|
|||
new_ucmd!()
|
||||
.args(&["lorem_ipsum.txt", "moby_dick.txt", "--total=never"])
|
||||
.run()
|
||||
.stdout_is(" 13 109 772 lorem_ipsum.txt\n 18 204 1115 moby_dick.txt\n");
|
||||
.stdout_is(concat!(
|
||||
" 13 109 772 lorem_ipsum.txt\n",
|
||||
" 18 204 1115 moby_dick.txt\n",
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue