diff --git a/sexc.scm b/sexc.scm index f217262..694e6e4 100644 --- a/sexc.scm +++ b/sexc.scm @@ -168,8 +168,12 @@ (define (write-to-file-or-stdout output what) (if (stdout-output? output) (what) - (with-output-to-file output - (fn (what))))) + ;; a failure part way through leaves none of the file, which make + ;; would take for done + (handle-exceptions exn + (begin (delete-file* output) (abort exn)) + (with-output-to-file output + (fn (what)))))) (define (emit-c-or-sex sex-forms output args) (write-to-file-or-stdout output diff --git a/tests/exit-code/check.scm b/tests/exit-code/check.scm index 9b6315f..8bc9621 100644 --- a/tests/exit-code/check.scm +++ b/tests/exit-code/check.scm @@ -3,7 +3,8 @@ ;;; Each needs a process to show itself, so none fits the unit suite: ;;; sexc has to fail when cc fails -- exiting 0 after a failed compile ;;; makes every driver, sextest included, read it as success -- it has to -;;; clean up its temporary .c when its own emission throws, and it has to +;;; clean up its temporary .c, and any output it began, when its own +;;; emission throws, and it has to ;;; refuse `-o -' for an executable, which cc would write to a file named ;;; `-'. ;;; @@ -58,6 +59,12 @@ (sexc-succeeds? "nested-pointer.sex" "-o" out) (glob (make-pathname scratch "*.c")))) +;; and none of a file it was writing out, which make would take for done +(test "a failed emission leaves no part of its output" #f + (begin + (sexc-succeeds? "nested-pointer.sex" "-C" "-o" (make-pathname scratch "out.c")) + (file-exists? (make-pathname scratch "out.c")))) + (test "a failed cc fails sexc" #f (sexc-succeeds? "hello.sex" "-o" out "--" "-no-such-cc-flag"))