#lang racket/base (require rackunit racket/path racket/file racket/port "../private/coreutils.rkt" "../private/extended.rkt" "../private/dispatcher.rkt" "../private/help.rkt" "../private/racket-tools.rkt" "../private/env-support.rkt") (define (capture-output procedure . args) (with-output-to-string (λ () (apply procedure args)))) (define (capture-filter input procedure . args) (parameterize ([current-input-port (open-input-string input)]) (apply capture-output procedure args))) (define test-root (make-temporary-file "rash-coreutils-~a" 'directory)) (dynamic-wind void (λ () (parameterize ([current-directory test-root]) (coreutils-mkdir "a") (check-true (directory-exists? "a")) (coreutils-mkdir "-p" "b/c") (check-true (directory-exists? "b/c")) (coreutils-touch "one.txt") (check-true (file-exists? "one.txt")) (call-with-output-file "one.txt" #:exists 'truncate (λ (out) (display "hello\n" out))) (check-equal? (capture-output coreutils-cat "one.txt") "hello\n") (coreutils-cp "one.txt" "two.txt") (check-true (file-exists? "two.txt")) (coreutils-mv "two.txt" "three.txt") (check-false (file-exists? "two.txt")) (check-true (file-exists? "three.txt")) (check-equal? (capture-output coreutils-echo "hello" "world") "hello world\n") (check-true (regexp-match? #rx"one[.]txt" (capture-output coreutils-ls))) (define long-listing (capture-output coreutils-ls "-l")) (check-true (regexp-match? #rx"[-] +[0-9]+ +one[.]txt" long-listing)) (coreutils-touch ".hidden") (define long-all-listing (capture-output coreutils-ls "-la")) (check-true (regexp-match? #rx"[-] +[0-9]+ +[.]hidden" long-all-listing)) (coreutils-touch "info1.rkt") (coreutils-touch "info22.rkt") (coreutils-touch "other.rkt") (define regexp-arguments (expand-coreutils-arguments (list #px"^info[0-9]+[.]rkt$"))) (check-equal? (sort (map (λ (path) (path->string (file-name-from-path path))) regexp-arguments) string