Initial import

This commit is contained in:
2026-08-17 23:19:13 +02:00
parent 8210aa8e63
commit 1d546c3d6f
20 changed files with 1799 additions and 1 deletions
+3
View File
@@ -0,0 +1,3 @@
#lang rash
(require rash-coreutils)
+166
View File
@@ -0,0 +1,166 @@
#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<?)
(list "info1.rkt" "info22.rkt"))
(define regexp-listing
(with-output-to-string
(λ ()
(dispatch-coreutils-command
'ls
#px"^info[0-9]+[.]rkt$"))))
(check-true (regexp-match? #rx"info1[.]rkt" regexp-listing))
(check-true (regexp-match? #rx"info22[.]rkt" regexp-listing))
(check-false (regexp-match? #rx"other[.]rkt" regexp-listing))
(define multiple-file-listing
(capture-output coreutils-ls "info1.rkt" "info22.rkt"))
(check-equal? multiple-file-listing
"info1.rkt\ninfo22.rkt\n")
(check-equal? (coreutils-help-search-term 'ls) "rash-coreutils-ls")
(check-equal? (coreutils-help-search-term 'directory-list)
"directory-list")
(check-equal? (coreutils-help-search-term 'raco) "rash-coreutils-raco")
(check-true (path? (find-raco-executable)))
(check-true (procedure? coreutils-raco))
(call-with-output-file "lines.txt"
#:exists 'truncate
(λ (out)
(display "one\ntwo\nthree\n" out)))
(check-equal? (capture-output coreutils-head "-n" "2" "lines.txt")
"one\ntwo\n")
(check-equal? (capture-output coreutils-tail "-n" "1" "lines.txt")
"three\n")
(check-equal? (capture-output coreutils-wc "-l" "lines.txt")
"3\n")
(check-equal? (capture-output coreutils-basename "a/b/c.txt")
"c.txt\n")
(check-equal? (capture-filter "abcde\n" coreutils-tr "a-z" "A-Z")
"ABCDE\n")
(check-equal? (capture-filter "a1b2c3\n" coreutils-tr "-d" "0-9")
"abc\n")
(check-equal? (capture-filter "a b\n" coreutils-tr "-s" " ")
"a b\n")
(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)
(and (equal? command '(printenv RASH_COREUTILS_VALUE))
(begin
(coreutils-printenv 'RASH_COREUTILS_VALUE)
#t)))])
(capture-output
coreutils-env
(environment-assignment "RASH_COREUTILS_VALUE" 42)
'printenv
'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))))
(check-true (regexp-match? #rx"[0-9]{4}-[0-9]{2}-[0-9]{2}T"
(capture-output coreutils-date "--iso")))
(check-exn
exn:fail?
(λ ()
(expand-coreutils-arguments (list #px"^does-not-exist$"))))
(coreutils-rm "three.txt")
(check-false (file-exists? "three.txt"))
(coreutils-rm "-r" "b")
(check-false (directory-exists? "b"))
(coreutils-rmdir "a")
(check-false (directory-exists? "a"))))
(λ ()
(when (directory-exists? test-root)
(delete-directory/files test-root))))
+21
View File
@@ -0,0 +1,21 @@
#lang rash
(require rash-coreutils)
mkdir -p rash-coreutils-smoke/a
echo hello from rash-coreutils
ls -l rash-coreutils-smoke
ls *.rkt
ls #px"^info[.]rkt$"
(define x 42)
env RASH_COREUTILS_VALUE=(values x) printenv RASH_COREUTILS_VALUE
echo one two three | wc -w
echo c b a | sort
date --iso
raco help
help
rm -r rash-coreutils-smoke