diff options
-rw-r--r-- | ccwl/ccwl.scm | 47 | ||||
-rw-r--r-- | tests/ccwl.scm | 20 |
2 files changed, 51 insertions, 16 deletions
diff --git a/ccwl/ccwl.scm b/ccwl/ccwl.scm index 05cb6e6..a319105 100644 --- a/ccwl/ccwl.scm +++ b/ccwl/ccwl.scm @@ -319,22 +319,37 @@ RUN-ARGS. If such an input is not present in RUN-ARGS, return #f." #,(run-arg-prefix id run)))) inputs)) (list #,@(map output outputs)) - (list #,@(map (lambda (x) - (syntax-case x () - ;; Replace input symbol with quoted symbol. - (input (identifier? #'input) - #''input) - ;; Leave string as is. - (string-arg (string? (syntax->datum #'string-arg)) - #'string-arg) - ;; Replace prefixed input symbol with - ;; quoted symbol. - ((prefix input) (and (string? (syntax->datum #'prefix)) - (identifier? #'input)) - #''input) - (_ (error "Invalid command element:" - (syntax->datum x))))) - run)) + (list #,@(let ((ensure-input-is-defined + ;; Ensure that specified input is + ;; defined in #:inputs of command + ;; definition. + (lambda (input) + (unless (memq (syntax->datum input) + (map input-spec-id inputs)) + (raise-exception + (condition (ccwl-violation input) + (formatted-message "Undefined input ~a" + (syntax->datum input)))))))) + (map (lambda (x) + (syntax-case x () + ;; Replace input symbol with quoted symbol. + (input (identifier? #'input) + (begin + (ensure-input-is-defined #'input) + #''input)) + ;; Leave string as is. + (string-arg (string? (syntax->datum #'string-arg)) + #'string-arg) + ;; Replace prefixed input symbol with + ;; quoted symbol. + ((prefix input) (and (string? (syntax->datum #'prefix)) + (identifier? #'input)) + (begin + (ensure-input-is-defined #'input) + #''input)) + (_ (error "Invalid command element:" + (syntax->datum x))))) + run))) #,(and stdin #`'#,stdin) #,(if (and stderr (not (string? (syntax->datum stderr)))) diff --git a/tests/ccwl.scm b/tests/ccwl.scm index 2f3f88d..334633b 100644 --- a/tests/ccwl.scm +++ b/tests/ccwl.scm @@ -232,4 +232,24 @@ #:stdout captured-stdout)) #f))) +(test-assert "command definitions with undefined inputs in their #:run arguments must raise a &ccwl-violation condition" + (guard (exception + (else (and (ccwl-violation? exception) + (string=? (formatted-message-format exception) + "Undefined input ~a")))) + (begin (macroexpand + '(command #:inputs (number #:type int) + #:run "echo" n)) + #f))) + +(test-assert "command definitions with undefined prefix inputs in their #:run arguments must raise a &ccwl-violation condition" + (guard (exception + (else (and (ccwl-violation? exception) + (string=? (formatted-message-format exception) + "Undefined input ~a")))) + (begin (macroexpand + '(command #:inputs (number #:type int) + #:run "echo" ("-x" n))) + #f))) + (test-end "ccwl") |