forked from alex-eg/sex
read a lone - as stdin
getopt-long read it as an option it did not know, and died.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
(import scheme
|
||||
(chicken base)
|
||||
(chicken file)
|
||||
(chicken io)
|
||||
(chicken pathname)
|
||||
(chicken process)
|
||||
(chicken process-context)
|
||||
@@ -33,6 +34,18 @@
|
||||
(define out (make-pathname scratch "out"))
|
||||
(set-environment-variable! "TMPDIR" scratch)
|
||||
|
||||
;;; (status stdout stderr) of sexc run with ARGS, and INPUT, when one
|
||||
;;; is given, on its stdin
|
||||
(define (sexc-run input . args)
|
||||
(let ((proc (process* sexc args)))
|
||||
(when input (display input (process-input-port proc)))
|
||||
(close-output-port (process-input-port proc))
|
||||
(let* ((text (lambda (s) (if (eof-object? s) "" s)))
|
||||
(out (text (read-string #f (process-output-port proc))))
|
||||
(err (text (read-string #f (process-error-port proc)))))
|
||||
(process-wait proc)
|
||||
(list (process-exit-status proc) out err))))
|
||||
|
||||
;;; Whether sexc exits 0 when run with ARGS, saying nothing of it
|
||||
(define (sexc-succeeds? . args)
|
||||
(zero? (system (string-append (string-intersperse (map qs (cons sexc args)))
|
||||
@@ -52,6 +65,12 @@
|
||||
(sexc-succeeds? "hello.sex" "-o" out "--" "-no-such-cc-flag"))
|
||||
|
||||
(define hello (make-pathname (current-directory) "hello.sex"))
|
||||
(define hello-source (call-with-input-file hello (lambda (p) (read-string #f p))))
|
||||
|
||||
;;; getopt-long read a lone `-' as an option it did not know, and died
|
||||
(test-assert "- is stdin"
|
||||
(let ((run (sexc-run hello-source "-" "-C" "-o" "-")))
|
||||
(and (zero? (car run)) (substring-index "main" (cadr run)) #t)))
|
||||
(change-directory scratch)
|
||||
|
||||
(test "-o - is refused for an executable" #f
|
||||
|
||||
Reference in New Issue
Block a user