From 72bf39a27bae47c2c510f399ea66ae49c6ab3631 Mon Sep 17 00:00:00 2001 From: Hans Dijkema Date: Tue, 18 Aug 2026 13:47:29 +0200 Subject: [PATCH] Btter tests for the package index --- CHANGELOG | 8 ++++++ README.md | 2 +- info.rkt | 5 ++-- tests/coreutils.rkt | 22 ++++++++--------- tests/rash-smoke.rkt | 59 +++++++++++++++++++++++++++++++++----------- 5 files changed, 66 insertions(+), 30 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b44e3a3..28dfbd3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,11 @@ +0.2.9 + +- Make package-build tests independent of the directory from which raco test is invoked. +- Run Rash smoke tests in an isolated temporary directory and capture expected command output. +- Keep successful tests silent under raco test --drdr; unexpected failures still escape normally. +- Isolate environment-variable tests with current-environment-variables instead of mutating the process environment. +- Declare linea explicitly as a build dependency because the Rash test modules use its reader. + 0.2.7 - Fix package setup regression in the Racket test suite after the raco command/procedure split. diff --git a/README.md b/README.md index 302fedb..8b18f95 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Portable Unix-style core utilities for Rash, implemented in Racket. -Version 0.2.7 includes text/pipeline tools (`head`, `tail`, `wc`, `sort`, `uniq`, +Version 0.2.9 includes text/pipeline tools (`head`, `tail`, `wc`, `sort`, `uniq`, `cut`, `tee`, `tr`), path and filesystem helpers (`basename`, `dirname`, `realpath`, `readlink`, `stat`, `du`, `df`, `mktemp`), environment commands (`printenv`, `env`), and `date` backed by Gregor. diff --git a/info.rkt b/info.rkt index baa45a7..c442194 100644 --- a/info.rkt +++ b/info.rkt @@ -1,7 +1,7 @@ #lang info (define pkg-authors '(hnmdijkema)) -(define version "0.2.7") +(define version "0.2.9") (define license 'MIT) (define collection "rash-coreutils") (define pkg-desc @@ -17,5 +17,4 @@ '("racket-doc" "rackunit-lib" "scribble-lib" - "linea" - "rash")) + "linea")) \ No newline at end of file diff --git a/tests/coreutils.rkt b/tests/coreutils.rkt index 3608b33..8e791d9 100644 --- a/tests/coreutils.rkt +++ b/tests/coreutils.rkt @@ -119,7 +119,6 @@ (check-true (regexp-match? #rx"a[/\\]b" (capture-output coreutils-dirname "a/b/c.txt"))) - (define saved-env (getenv "RASH_COREUTILS_TEST")) (define env-output (parameterize ([current-coreutils-command-runner (λ (command) @@ -134,18 +133,17 @@ 'RASH_COREUTILS_VALUE))) (check-equal? env-output "42\n") - (dynamic-wind - void - (λ () - (putenv "RASH_COREUTILS_TEST" "before") - (check-equal? (capture-output coreutils-printenv "RASH_COREUTILS_TEST") - "before\n")) - (λ () - (if saved-env - (putenv "RASH_COREUTILS_TEST" saved-env) - (putenv "RASH_COREUTILS_TEST" #f)))) + (define test-environment + (environment-variables-copy (current-environment-variables))) + (environment-variables-set! + test-environment + #"RASH_COREUTILS_TEST" + #"before") + (parameterize ([current-environment-variables test-environment]) + (check-equal? (capture-output coreutils-printenv "RASH_COREUTILS_TEST") + "before\n")) - (check-true (regexp-match? #rx"[0-9]{4}-[0-9]{2}-[0-9]{2}T" + (check-true (regexp-match? #px"[0-9]{4}-[0-9]{2}-[0-9]{2}T" (capture-output coreutils-date "--iso"))) (check-exn diff --git a/tests/rash-smoke.rkt b/tests/rash-smoke.rkt index b3a92e7..861b5aa 100644 --- a/tests/rash-smoke.rkt +++ b/tests/rash-smoke.rkt @@ -1,21 +1,52 @@ #lang rash -(require rash-coreutils) +(require rackunit + racket/file + racket/port + rash-coreutils) -mkdir -p rash-coreutils-smoke/a +(define test-root + (make-temporary-file "rash-coreutils-smoke-~a" 'directory)) +(define output + (open-output-string)) +(define errors + (open-output-string)) -echo hello from rash-coreutils -ls -l rash-coreutils-smoke -ls *.rkt -ls #px"^info[.]rkt$" +(dynamic-wind + void + (λ () + (parameterize ([current-directory test-root] + [current-output-port output] + [current-error-port errors]) + { + (call-with-output-file "info.rkt" + #:exists 'truncate + (λ (out) + (display "#lang racket/base\n" out))) -(define x 42) -env RASH_COREUTILS_VALUE=(values x) printenv RASH_COREUTILS_VALUE + mkdir -p rash-coreutils-smoke/a -echo one two three | wc -w -echo c b a | sort + echo hello from rash-coreutils + ls -l rash-coreutils-smoke + ls *.rkt + ls #px"^info[.]rkt$" -date --iso -raco help -help -rm -r rash-coreutils-smoke + (define x 42) + env RASH_COREUTILS_VALUE=(values x) printenv RASH_COREUTILS_VALUE + + echo one two three | wc -w + date --iso + rm -r rash-coreutils-smoke + + (check-false (directory-exists? "rash-coreutils-smoke")) + }) + (check-equal? (get-output-string errors) "") + (define text (get-output-string output)) + (check-true (regexp-match? #rx"hello from rash-coreutils" text)) + (check-true (regexp-match? #rx"info[.]rkt" text)) + (check-true (regexp-match? #rx"42" text)) + (check-true (regexp-match? #rx"\n3\n" text)) + (check-true (regexp-match? #px"[0-9]{4}-[0-9]{2}-[0-9]{2}T" text))) + (λ () + (when (directory-exists? test-root) + (delete-directory/files test-root))))