From 83282adfb9ada61246471b4944b5736cdd99e336 Mon Sep 17 00:00:00 2001 From: alex-eg Date: Mon, 19 Oct 2026 10:23:59 +0300 Subject: [PATCH] leave none of an output a failure stopped writing A failed -C -o left the file truncated, which make would take for done. --- sexc.scm | 8 ++++++-- tests/exit-code/check.scm | 9 ++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/sexc.scm b/sexc.scm index a7af373..812556c 100644 --- a/sexc.scm +++ b/sexc.scm @@ -164,8 +164,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 2160bb3..5d8a431 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 ;;; `-'. ;;; @@ -61,6 +62,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"))