From 31d0328abebcae98b21b57cecfc255ec6442e157 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 6 Nov 2023 11:01:43 +0000 Subject: ccwl: Error out if #:other parameters are not serializable to YAML. * ccwl/ccwl.scm (ensure-yaml-serializable): New function. (input, output, command): Use ensure-yaml-serializable. * tests/ccwl.scm ("inputs with #:other parameters that fail to evaluate must raise a &ccwl-violation condition", "outputs with #:other parameters that fail to evaluate must raise a &ccwl-violation condition", "commands with #:other parameters that fail to evaluate must raise a &ccwl-violation condition"): New tests. --- ccwl/ccwl.scm | 13 +++++++++++++ tests/ccwl.scm | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/ccwl/ccwl.scm b/ccwl/ccwl.scm index f3ff1f8..793facd 100644 --- a/ccwl/ccwl.scm +++ b/ccwl/ccwl.scm @@ -35,6 +35,7 @@ #:use-module (ice-9 match) #:use-module (ccwl conditions) #:use-module (ccwl utils) + #:use-module (ccwl yaml) #:use-module (yaml) #:export (command? command @@ -95,6 +96,15 @@ (make-unspecified-default) unspecified-default?) +(define (ensure-yaml-serializable tree) + "Raise an exception unless @var{tree} is serializable to YAML." + ;; TODO: If tree is a quoted expression, emit a warning. + (unless (false-if-exception + (scm->yaml-string (syntax->datum tree))) + (raise-exception + (condition (ccwl-violation tree) + (formatted-message "#:other parameter not serializable to YAML"))))) + (define (input input-spec) "Return syntax to build an object from INPUT-SPEC." (syntax-case input-spec () @@ -136,6 +146,7 @@ (condition (ccwl-violation stage?) (formatted-message "Invalid #:stage? parameter ~a. #:stage? must either be #t or #f." (syntax->datum stage?))))) + (ensure-yaml-serializable other) (let ((position #f) (prefix #f)) #`(make-input '#,id '#,type #,label @@ -191,6 +202,7 @@ (condition (ccwl-violation output-spec) (formatted-message "Output has no identifier"))))))) (apply (syntax-lambda** (id #:key (type #'File) binding source (other #'())) + (ensure-yaml-serializable other) #`(make-output '#,id '#,type #,binding #,source '#,other)) #'(id args ...)))) (id (identifier? #'id) (output #'(id))) @@ -368,6 +380,7 @@ identifiers defined in the commands." (condition (ccwl-violation x) (formatted-message "Missing ~a key in command definition" #:run)))) + (ensure-yaml-serializable other) #`(make-command (list #,@(map (lambda (input-spec) (let ((id (input-spec-id input-spec))) diff --git a/tests/ccwl.scm b/tests/ccwl.scm index d8100c5..117f93f 100644 --- a/tests/ccwl.scm +++ b/tests/ccwl.scm @@ -285,4 +285,36 @@ #:run "cat" file)) #f))) +(test-assert "inputs with #:other parameters that fail to evaluate must raise a &ccwl-violation condition" + (guard (exception + (else (and (ccwl-violation? exception) + (string=? (formatted-message-format exception) + "#:other parameter not serializable to YAML")))) + (begin (macroexpand + '(command #:inputs (file #:type File + #:other '((secondaryFiles . ".fai"))) + #:run "cat" file)) + #f))) + +(test-assert "outputs with #:other parameters that fail to evaluate must raise a &ccwl-violation condition" + (guard (exception + (else (and (ccwl-violation? exception) + (string=? (formatted-message-format exception) + "#:other parameter not serializable to YAML")))) + (begin (macroexpand + '(command #:outputs (file #:type File + #:other '((secondaryFiles . ".fai"))) + #:run "cat" file)) + #f))) + +(test-assert "commands with #:other parameters that fail to evaluate must raise a &ccwl-violation condition" + (guard (exception + (else (and (ccwl-violation? exception) + (string=? (formatted-message-format exception) + "#:other parameter not serializable to YAML")))) + (begin (macroexpand + '(command #:run "cat" file + #:other '((secondaryFiles . ".fai")))) + #f))) + (test-end "ccwl") -- cgit v1.2.3