mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
comm: generate an error if the input is a directory
tested by tests/misc/read-errors
This commit is contained in:
parent
37fb0a02f8
commit
0cae322dfa
2 changed files with 38 additions and 3 deletions
|
@ -6,9 +6,8 @@
|
|||
// spell-checker:ignore (ToDO) delim mkdelim
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fs::File;
|
||||
use std::fs::{metadata, File};
|
||||
use std::io::{self, stdin, BufRead, BufReader, Stdin};
|
||||
use std::path::Path;
|
||||
use uucore::error::{FromIo, UResult, USimpleError};
|
||||
use uucore::line_ending::LineEnding;
|
||||
use uucore::{format_usage, help_about, help_usage};
|
||||
|
@ -130,7 +129,10 @@ fn open_file(name: &str, line_ending: LineEnding) -> io::Result<LineReader> {
|
|||
if name == "-" {
|
||||
Ok(LineReader::new(Input::Stdin(stdin()), line_ending))
|
||||
} else {
|
||||
let f = File::open(Path::new(name))?;
|
||||
if metadata(name)?.is_dir() {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "Is a directory"));
|
||||
}
|
||||
let f = File::open(name)?;
|
||||
Ok(LineReader::new(
|
||||
Input::FileIn(BufReader::new(f)),
|
||||
line_ending,
|
||||
|
|
|
@ -292,3 +292,36 @@ fn test_no_such_file() {
|
|||
.fails()
|
||||
.stderr_only("comm: bogus_file_1: No such file or directory\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_dir() {
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&[".", "."])
|
||||
.fails()
|
||||
.stderr_only("comm: .: Is a directory\n");
|
||||
|
||||
at.mkdir("dir");
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&["dir", "."])
|
||||
.fails()
|
||||
.stderr_only("comm: dir: Is a directory\n");
|
||||
|
||||
at.touch("file");
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&[".", "file"])
|
||||
.fails()
|
||||
.stderr_only("comm: .: Is a directory\n");
|
||||
|
||||
at.touch("file");
|
||||
scene
|
||||
.ucmd()
|
||||
.args(&["file", "."])
|
||||
.fails()
|
||||
.stderr_only("comm: .: Is a directory\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue