refuse a second input file

It was never read, and nothing said so.
This commit is contained in:
2026-10-19 10:23:59 +03:00
parent 65d29ee158
commit cc33e6abd8
2 changed files with 21 additions and 6 deletions

View File

@@ -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)

View File

@@ -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" "-"))