From 5e774d8f08d9a89352873289d856d0d5c2a47f41 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 16 Oct 2023 15:19:27 +0100 Subject: ccwl: Check if inputs in command definitions are defined. * ccwl/ccwl.scm (command): Check if inputs used in #:run arguments of command definitions are actually defined. * tests/ccwl.scm ("command definitions with undefined inputs in their #:run arguments must raise a &ccwl-violation condition", "command definitions with undefined prefix inputs in their #:run arguments must raise a &ccwl-violation condition"): New tests. --- ccwl/ccwl.scm | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'ccwl') 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)))) -- cgit v1.2.3