Skip to content

Commit 07022ee

Browse files
committed
feat: Show unexpected stderr in umask panic message
Because `gix_testtools::umask()` is only suitable for use in tests, where signaling an error with a panic is typically acceptable, it panics rather than returning an `Error` to indicate errors. To avoid leading to the use of a potentially inaccurate umask value, it treats as an error any departure from the typical output of the `umask` command: in addition to treating a nonzero exit status as an error, it also treats anything it cannot strictly parse on stdout as an error, as well as anything at all written to stderr as an error. The latter is to avoid a situation where a warning is printed that is could be significant to some umask use cases. Warnings from `umask` are rare, as well as from the shell that is used as an intermediary for running the command (since no external `umask` command need exist and, often, does not) when it is used just to run `umask`. When they do occur, they are sometimes from the dynamic linker, such as a warning about a shared library listed in the `LD_PRELOAD` environment variable that cannot be used by the shell program. To understand and distinguish such errors, it is useful to show the text that was sent to stderr, since tests are sometimes run in environments that are nontrivial to reproduce otherwise. For example, running tests with `cross` produces an environment that is not in all respects the same as what one gets with `docker exec -it <container>`, even if `<container>` is the same still-running container being used to run the tests. This modifies `gix_testtools::umask()` so that when it panics due anything being written to stderr, it shows what was written.
1 parent 1b25974 commit 07022ee

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tests/tools/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ pub fn umask() -> u32 {
992992
.output()
993993
.expect("can execute `sh -c umask`");
994994
assert!(output.status.success(), "`sh -c umask` failed");
995-
assert!(output.stderr.is_empty(), "`sh -c umask` unexpected message");
995+
assert_eq!(output.stderr.as_bstr(), "", "`sh -c umask` unexpected message");
996996
let text = output.stdout.to_str().expect("valid Unicode").trim();
997997
u32::from_str_radix(text, 8).expect("parses as octal number")
998998
}

0 commit comments

Comments
 (0)