From 7db773fdb71b15353e9c15c908867d308b887a7b Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Thu, 25 Jun 2026 17:19:39 +0100 Subject: lang: Raise &ccwl-violation when loading non-existent source files. --- ccwl/lang.scm | 25 ++++++++++++++++++------- tests/lang.scm | 6 ++++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ccwl/lang.scm b/ccwl/lang.scm index c9ebae3..1189287 100644 --- a/ccwl/lang.scm +++ b/ccwl/lang.scm @@ -66,11 +66,22 @@ it." (condition-irritants c))))) (read-syntax port))) -(define (ccwl-load file) +(define (ccwl-load-helper file file-syntax) + "Load ccwl source @var{file}. @var{file-syntax} is the syntax object +wrapping @var{file}." + (if (file-exists? file) + (let ((source-path (canonicalize-path file))) + ;; Change directory before loading source file. The source + ;; file may reference other files with paths relative to its + ;; directory. + (call-with-current-directory (dirname source-path) + (lambda () + (load source-path ccwl-read)))) + (raise-continuable + (condition (ccwl-violation file-syntax) + (formatted-message "File ~a does not exist" + file))))) + +(define-syntax-rule (ccwl-load file) "Load ccwl source @var{file}." - (let ((source-path (canonicalize-path file))) - ;; Change directory before loading source file. The source file - ;; may reference other files with paths relative to its directory. - (call-with-current-directory (dirname source-path) - (lambda () - (load source-path ccwl-read))))) + (ccwl-load-helper file #'file)) diff --git a/tests/lang.scm b/tests/lang.scm index 247f2e1..d8a891b 100644 --- a/tests/lang.scm +++ b/tests/lang.scm @@ -17,6 +17,8 @@ ;;; along with ccwl. If not, see . (use-modules (srfi srfi-64) + (test-utils utils) + (ccwl conditions) (ccwl lang)) (test-begin "lang") @@ -24,4 +26,8 @@ (test-assert "load source file referencing external CWL workflow relative to it" (ccwl-load "test-data/external-cwl-workflow.scm")) +(test-condition "loading non-existent source file must raise a &ccwl-violation" + ccwl-violation? + (ccwl-load "/non-existent/file.scm")) + (test-end "lang") -- cgit 1.4.1