From 7aa50a040a51a4016efcf81862105f94443b4d1f Mon Sep 17 00:00:00 2001 From: alex-eg Date: Mon, 19 Oct 2026 10:23:59 +0300 Subject: [PATCH] refuse a second input file It was never read, and nothing said so. --- sexc.scm | 15 +++++++++------ tests/exit-code/check.scm | 12 ++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/sexc.scm b/sexc.scm index 694e6e4..f01ccd9 100644 --- a/sexc.scm +++ b/sexc.scm @@ -150,11 +150,14 @@ (map string->symbol (string-split (cdr entry) ","))) (filter (lambda (entry) (eq? (car entry) 'features)) args))) -(define (get-input-file args) - (let ((rest-args (get-rest-args args))) - (if (null? rest-args) - 'stdin - (car rest-args)))) +(define (get-input-file args dash?) + (let ((inputs (append (if dash? (list "-") (list)) (get-rest-args args)))) + (cond ((null? inputs) 'stdin) + ;; any after the first were never read, and nothing said so + ((pair? (cdr inputs)) + (apply error "sexc compiles one input file at a time; given" inputs)) + (dash? 'stdin) + (else (car inputs))))) (define (stdout-output? output) (or (eq? output 'default) (equal? output "-"))) @@ -270,7 +273,7 @@ status, which is ours to pass on." (output (get-arg args 'output 'default)) (help (help-arg? args)) - (input (if (stdin-dash? raw-args) 'stdin (get-input-file args))) + (input (get-input-file args (stdin-dash? raw-args))) (current-dir (current-directory))) (call/cc (lambda (return) diff --git a/tests/exit-code/check.scm b/tests/exit-code/check.scm index 8bc9621..9240502 100644 --- a/tests/exit-code/check.scm +++ b/tests/exit-code/check.scm @@ -77,6 +77,18 @@ (and (zero? (car run)) (substring-index "main" (cadr run)) #t))) (change-directory scratch) +;;; the second was never read, and nothing said so +(test-assert "a second input is refused" + (let ((run (sexc-run #f hello hello "-C" "-o" "-"))) + (and (not (zero? (car run))) + (substring-index "one input file at a time" (caddr run)) + #t))) +(test-assert "stdin besides a file too" + (let ((run (sexc-run hello-source "-" hello "-C" "-o" "-"))) + (and (not (zero? (car run))) + (substring-index "one input file at a time" (caddr run)) + #t))) + (test "-o - is refused for an executable" #f (sexc-succeeds? hello "-o" "-"))