mirror of
https://github.com/uutils/coreutils
synced 2024-11-15 09:27:21 +00:00
Merge pull request #6090 from sylvestre/csplit2
csplit: adjust the error message to match GNU's
This commit is contained in:
commit
2f4969c0e9
3 changed files with 20 additions and 3 deletions
|
@ -89,7 +89,7 @@ impl CsplitOptions {
|
|||
/// more than once.
|
||||
pub fn csplit<T>(
|
||||
options: &CsplitOptions,
|
||||
patterns: Vec<patterns::Pattern>,
|
||||
patterns: Vec<String>,
|
||||
input: T,
|
||||
) -> Result<(), CsplitError>
|
||||
where
|
||||
|
@ -97,6 +97,7 @@ where
|
|||
{
|
||||
let mut input_iter = InputSplitter::new(input.lines().enumerate());
|
||||
let mut split_writer = SplitWriter::new(options);
|
||||
let patterns: Vec<patterns::Pattern> = patterns::get_patterns(&patterns[..])?;
|
||||
let ret = do_csplit(&mut split_writer, patterns, &mut input_iter);
|
||||
|
||||
// consume the rest
|
||||
|
@ -563,7 +564,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
.unwrap()
|
||||
.map(|s| s.to_string())
|
||||
.collect();
|
||||
let patterns = patterns::get_patterns(&patterns[..])?;
|
||||
let options = CsplitOptions::new(&matches);
|
||||
if file_name == "-" {
|
||||
let stdin = io::stdin();
|
||||
|
|
|
@ -21,7 +21,7 @@ pub enum CsplitError {
|
|||
MatchNotFound(String),
|
||||
#[error("{}: match not found on repetition {}", ._0.quote(), _1)]
|
||||
MatchNotFoundOnRepetition(String, usize),
|
||||
#[error("line number must be greater than zero")]
|
||||
#[error("0: line number must be greater than zero")]
|
||||
LineNumberIsZero,
|
||||
#[error("line number '{}' is smaller than preceding line number, {}", _0, _1)]
|
||||
LineNumberSmallerThanPrevious(usize, usize),
|
||||
|
|
|
@ -1359,3 +1359,20 @@ fn precision_format() {
|
|||
assert_eq!(at.read("xx 0x001"), generate(10, 51));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_error() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.touch("in");
|
||||
ucmd.args(&["in", "0"])
|
||||
.fails()
|
||||
.stderr_contains("0: line number must be greater");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_such_file() {
|
||||
let (_, mut ucmd) = at_and_ucmd!();
|
||||
ucmd.args(&["in", "0"])
|
||||
.fails()
|
||||
.stderr_contains("cannot access 'in': No such file or directory");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue