From d4f58ffa198e905b2d93ca1c791d50d7b60e457a Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 2 Dec 2018 09:51:41 +0100 Subject: [PATCH] test: 04-word-at-word. --- check.sh | 1 + gash/script.scm | 23 +++++++++++++---------- test/04-echo-word-at-word.sh | 1 + test/04-echo-word-at-word.stdout | 1 + 4 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 test/04-echo-word-at-word.sh create mode 100644 test/04-echo-word-at-word.stdout diff --git a/check.sh b/check.sh index 9a430d2..4d0cd40 100755 --- a/check.sh +++ b/check.sh @@ -32,6 +32,7 @@ tests=' 04-echo-var 04-echo-equal 04-echo-word-at +04-echo-word-at-word 05-assignment 05-assignment-echo diff --git a/gash/script.scm b/gash/script.scm index d909a30..6bc44ad 100644 --- a/gash/script.scm +++ b/gash/script.scm @@ -80,6 +80,10 @@ (run ast))) (define (command . args) + (define (flatten o) + (match o + ((h t ...) (append (flatten h) (append-map flatten t))) + (_ (list o)))) (define (exec command) (cond ((procedure? command) command) ((assoc-ref %functions (car command)) @@ -98,16 +102,15 @@ (else (lambda () #t)))) (when (> %debug-level 1) (format (current-error-port) "command: ~s\n" args)) - (match args - (((or "." "source") file-name) - (let* ((string (with-input-from-file file-name read-string)) - (ast (parse-string string))) - (run ast) - 0)) - (((? string?) ..1) (exec (append-map glob args))) - (((and (or (? string?)) c) ... ((and (? string?) a) ...)) - (apply command (append c a))) - (_ (exec (append-map glob args))))) + (let ((args (flatten args))) + (match args + (((or "." "source") file-name) + (let* ((string (with-input-from-file file-name read-string)) + (ast (parse-string string))) + (run ast) + 0)) + (((? string?) ..1) (exec (append-map glob args))) + (_ (exec (append-map glob args)))))) (define (glob? pattern) (and (string? pattern) (string-match "\\?|\\*" pattern))) diff --git a/test/04-echo-word-at-word.sh b/test/04-echo-word-at-word.sh new file mode 100644 index 0000000..9f90b61 --- /dev/null +++ b/test/04-echo-word-at-word.sh @@ -0,0 +1 @@ +echo command $@ plus diff --git a/test/04-echo-word-at-word.stdout b/test/04-echo-word-at-word.stdout new file mode 100644 index 0000000..802f789 --- /dev/null +++ b/test/04-echo-word-at-word.stdout @@ -0,0 +1 @@ +command -s --long file0 file1 plus