From 4f33a375cda8c515db6eb81cd54007fe850dd2cb Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Fri, 5 Jan 2024 20:55:54 +0100 Subject: [PATCH] factor: handle the '< .' arg --- src/uu/factor/src/cli.rs | 15 ++++++++++++--- tests/by-util/test_factor.rs | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/uu/factor/src/cli.rs b/src/uu/factor/src/cli.rs index 63a0632a3..d01ca625c 100644 --- a/src/uu/factor/src/cli.rs +++ b/src/uu/factor/src/cli.rs @@ -73,9 +73,18 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let stdin = stdin(); let lines = stdin.lock().lines(); for line in lines { - for number in line.unwrap().split_whitespace() { - print_factors_str(number, &mut w, print_exponents) - .map_err_context(|| "write error".into())?; + match line { + Ok(line) => { + for number in line.split_whitespace() { + print_factors_str(number, &mut w, print_exponents) + .map_err_context(|| "write error".into())?; + } + } + Err(e) => { + set_exit_code(1); + show_error!("error reading input: {}", e); + return Ok(()); + } } } } diff --git a/tests/by-util/test_factor.rs b/tests/by-util/test_factor.rs index 3326a1ace..57a2dae09 100644 --- a/tests/by-util/test_factor.rs +++ b/tests/by-util/test_factor.rs @@ -1258,3 +1258,8 @@ const PRIMES50: &[u64] = &[ 1125899906841623, 1125899906841613, ]; + +#[test] +fn fails_on_directory() { + new_ucmd!().pipe_in(".").fails(); +}