From 821f5d09e9eb41cd38989dc91de958c77157fdee Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 17 Aug 2024 01:51:25 -0600 Subject: [PATCH 1/4] fop(1), hru(1), intcmp(1), mm(1), rpn(1), swab(1): fixes conditional compilation --- src/fop.rs | 2 +- src/hru.rs | 2 +- src/intcmp.rs | 2 +- src/mm.rs | 8 ++++---- src/rpn.rs | 2 +- src/swab.rs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/fop.rs b/src/fop.rs index 66b7e82..7c8424e 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -39,7 +39,7 @@ fn main() { let mut d = '\u{1E}'.to_string(); /* ASCII record separator */ let mut optind = 1; - if cfg!(target_os="openbsd") { + #[cfg(target_os="openbsd")] { let promises = Promises::new("stdio proc exec"); if let Err(e) = pledge(Some(promises), None) { eprintln!("{}: {}", argv[0], e.strerror()); diff --git a/src/hru.rs b/src/hru.rs index c6009a7..e07ec39 100644 --- a/src/hru.rs +++ b/src/hru.rs @@ -86,7 +86,7 @@ fn main() -> ExitCode { return ExitCode::from(EX_USAGE as u8); } - if cfg!(target_os="openbsd") { + #[cfg(target_os="openbsd")] { let promises = Promises::new("stdio"); if let Err(e) = pledge(Some(promises), None) { eprintln!("{}: {}", argv[0], e.strerror()); diff --git a/src/intcmp.rs b/src/intcmp.rs index a7c045d..456f268 100644 --- a/src/intcmp.rs +++ b/src/intcmp.rs @@ -42,7 +42,7 @@ fn usage(s: &str) -> ExitCode { fn main() -> ExitCode { let argv = args().collect::>(); - if cfg!(target_os="openbsd") { + #[cfg(target_os="openbsd")] { let promises = Promises::new("stdio"); if let Err(e) = pledge(Some(promises), None) { eprintln!("{}: {}", argv[0], e.strerror()); diff --git a/src/mm.rs b/src/mm.rs index b99bf9e..755c382 100644 --- a/src/mm.rs +++ b/src/mm.rs @@ -51,7 +51,7 @@ fn main() -> ExitCode { let argv = args().collect::>(); let usage = format!("Usage: {} [-aetu] [-i input] [-o output]", argv[0]); - if cfg!(target_os="openbsd") { + #[cfg(target_os="openbsd")] { let promises = Promises::new("rpath stdio unveil"); if let Err(e) = pledge(Some(promises), None) { eprintln!("{}: {}", argv[0], e.strerror()); @@ -77,7 +77,7 @@ fn main() -> ExitCode { Ok("i") => { /* add inputs */ let input = opt.arg().unwrap(); - if cfg!(target_os="openbsd") { + #[cfg(target_os="openbsd")] { let perms = UnveilPerms::new(vec!['r']); if let Err(e) = unveil(Some(&input), Some(perms)) { eprintln!("{}: {}", argv[0], e.strerror()); @@ -91,7 +91,7 @@ fn main() -> ExitCode { Ok("o") => { /* add output */ let output = opt.arg().unwrap(); - if cfg!(target_os="openbsd") { + #[cfg(target_os="openbsd")] { let perms = UnveilPerms::new(vec!['w', 'c']); if let Err(e) = unveil(Some(&output), Some(perms)) { eprintln!("{}: {}", argv[0], e.strerror()); @@ -124,7 +124,7 @@ fn main() -> ExitCode { } } - if cfg!(target_os="openbsd") { + #[cfg(target_os="openbsd")] { if let Err(e) = unveil(None, None) { eprintln!("{}: {}", argv[0], e.strerror()); return ExitCode::from(EX_OSERR as u8); diff --git a/src/rpn.rs b/src/rpn.rs index e4f725d..7669efb 100644 --- a/src/rpn.rs +++ b/src/rpn.rs @@ -198,7 +198,7 @@ fn round_precise(value: &f64, precision: usize) -> f64 { fn main() -> ExitCode { let argv = args().collect::>(); - if cfg!(target_os="openbsd") { + #[cfg(target_os="openbsd")] { let promises = Promises::new("stdio"); if let Err(e) = pledge(Some(promises), None) { eprintln!("{}: {}", argv[0], e.strerror()); diff --git a/src/swab.rs b/src/swab.rs index 27ce9a5..4dc86de 100644 --- a/src/swab.rs +++ b/src/swab.rs @@ -54,7 +54,7 @@ fn usage(s: &str) -> ExitCode { fn main() -> ExitCode { let argv = args().collect::>(); - if cfg!(target_os="openbsd") { + #[cfg(target_os="openbsd")] { let promises = Promises::new("stdio"); if let Err(e) = pledge(Some(promises), None) { return oserr(&argv[0], e); From 71d4d6ba05ee79f38ec7a3779a0e5579159b567a Mon Sep 17 00:00:00 2001 From: emma Date: Sat, 17 Aug 2024 01:57:16 -0600 Subject: [PATCH 2/4] tests: bonsai/dj.mk, bonsai/rpn.mk: fixes testing on linux --- tests/bonsai/dj.mk | 2 +- tests/bonsai/rpn.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bonsai/dj.mk b/tests/bonsai/dj.mk index bf8adf3..2b4ef6b 100755 --- a/tests/bonsai/dj.mk +++ b/tests/bonsai/dj.mk @@ -19,7 +19,7 @@ dj_tests: dj_help dj_full dj_null # dj_skip_stdin dj_full: $(BIN)/dj /dev/full case "$$(uname)" in \ Linux) \ - $(BIN)/dj -Hi /dev/zero -o /dev/full 2>&1 \ + ! $(BIN)/dj -Hi /dev/zero -o /dev/full 2>&1 \ | tee /dev/stderr \ | xargs -I out test '1+0 > 0+0; 1024 > 0' = out \ ;; \ diff --git a/tests/bonsai/rpn.mk b/tests/bonsai/rpn.mk index 3619692..6fecab9 100755 --- a/tests/bonsai/rpn.mk +++ b/tests/bonsai/rpn.mk @@ -30,7 +30,7 @@ rpn_mul: $(BIN)/rpn .PHONY: rpn_div rpn_div: $(BIN)/rpn test "$$($(BIN)/rpn 12 5 /)" = 2.4 - test "$$($(BIN)/rpn 3 0 /)" -eq inf + test "$$($(BIN)/rpn 3 0 /)" = inf .PHONY: rpn_mod rpn_mod: $(BIN)/rpn From 334433536b6d1c9e4525c5f6f3d850c63951bad6 Mon Sep 17 00:00:00 2001 From: DTB Date: Wed, 21 Aug 2024 21:57:10 -0600 Subject: [PATCH 3/4] tests: bonsai/npc.mk: fix harrowing ordeal of a Linux error --- tests/bonsai/npc.mk | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/bonsai/npc.mk b/tests/bonsai/npc.mk index 8b10fdf..8b7f8ea 100755 --- a/tests/bonsai/npc.mk +++ b/tests/bonsai/npc.mk @@ -32,11 +32,30 @@ npc_ascii: npc_ascii_controls npc_ascii_symbols npc_ascii_uppers # \ .PHONY: npc_ascii_controls # (control characters) npc_ascii_controls: + # The following test prints the bytes 0x00 (inclusive) through 0x20 + # (exclusive) and pipes them through npc(1). npc(1) should then replace all + # non-printing, non-space (in the isspace(3p) sense) characters with their + # graphical carat-char counterparts (see the npc(1) man page). The head(1p) + # invocation then strips off everything past the first line (or past the + # first newline byte, 0x0A) and xargs(1p) is used to test(1p) the output + # against the known good answer. + + # Immediately before that newline, 0x09 is printed - in ASCII, the + # horizontal tab. If xargs' -I option is used, tr(1p) should used to delete + # that tab. If the tab is left as part of input, OpenBSD's xargs(1) + # implementation has been observed to strip it along with the other + # trailing whitespace (the newline), but Busybox's and GNU's xargs(1) + # implementations have been observed to leave the tab in. All three + # implementations strip off the trailing tab if `-I` is not used. The POSIX + # specification for `-I` is ambiguous as to which behavior is correct. + # This comment is the result of much bewilderment and debugging. + # ASCII 0x00 to 0x0a (before the newline, due to xargs(1p) issues) awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); }' \ | $(BIN)/npc \ | head -n 1 \ - | xargs -I out test "^@^A^B^C^D^E^F^G^H" = out + | tr -d '\t' \ + | xargs test "^@^A^B^C^D^E^F^G^H" = # ASCII 0x0a (otherwise the head|tail sequence won't work) to 0x1f awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); print }' \ From 579ff65b67518f61a3658942a5df517533004f2f Mon Sep 17 00:00:00 2001 From: DTB Date: Wed, 21 Aug 2024 21:59:22 -0600 Subject: [PATCH 4/4] tests: bonsai/npc.mk: drop redundant tab removal --- tests/bonsai/npc.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/bonsai/npc.mk b/tests/bonsai/npc.mk index 8b7f8ea..b028c4d 100755 --- a/tests/bonsai/npc.mk +++ b/tests/bonsai/npc.mk @@ -54,7 +54,6 @@ npc_ascii_controls: awk 'BEGIN{ for (i = 0; i < 32; ++i) printf("%c", i); }' \ | $(BIN)/npc \ | head -n 1 \ - | tr -d '\t' \ | xargs test "^@^A^B^C^D^E^F^G^H" = # ASCII 0x0a (otherwise the head|tail sequence won't work) to 0x1f