diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index cab9da227..fb490888a 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -33,7 +33,7 @@ use std::time::{Duration, UNIX_EPOCH}; use std::{error::Error, fmt::Display}; use uucore::display::{print_verbatim, Quotable}; use uucore::error::FromIo; -use uucore::error::{UError, UResult}; +use uucore::error::{set_exit_code, UError, UResult}; use uucore::parse_glob; use uucore::parse_size::{parse_size, ParseSizeError}; use uucore::{ @@ -655,6 +655,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { path_string.maybe_quote(), "No such file or directory" ); + set_exit_code(1); } } diff --git a/tests/by-util/test_du.rs b/tests/by-util/test_du.rs index d69eaaf99..73be82bf9 100644 --- a/tests/by-util/test_du.rs +++ b/tests/by-util/test_du.rs @@ -6,7 +6,6 @@ // spell-checker:ignore (paths) sublink subwords azerty azeaze xcwww azeaz amaz azea qzerty tazerty #[cfg(not(windows))] use regex::Regex; -#[cfg(not(windows))] use std::io::Write; #[cfg(any(target_os = "linux", target_os = "android"))] @@ -851,3 +850,27 @@ fn test_du_exclude_invalid_syntax() { .fails() .stderr_contains("du: Invalid exclude syntax"); } + +#[test] +fn test_du_symlink_fail() { + let ts = TestScenario::new(util_name!()); + let at = &ts.fixtures; + + at.symlink_file("non-existing.txt", "target.txt"); + + ts.ucmd().arg("-L").arg("target.txt").fails().code_is(1); +} + +#[test] +fn test_du_symlink_multiple_fail() { + let ts = TestScenario::new(util_name!()); + let at = &ts.fixtures; + + at.symlink_file("non-existing.txt", "target.txt"); + let mut file1 = at.make_file("file1"); + file1.write_all(b"azeaze").unwrap(); + + let result = ts.ucmd().arg("-L").arg("target.txt").arg("file1").fails(); + assert_eq!(result.code(), 1); + result.stdout_contains("4\tfile1\n"); +}