From d9122d7b68202f341619aa0eda51392b2f0149a4 Mon Sep 17 00:00:00 2001 From: Timothy Sample Date: Fri, 7 Jun 2019 19:39:03 -0400 Subject: [PATCH] Use 'sh:exit' for 'errexit'. * gash/shell.scm (errexit): Exit using 'sh:exit'. * tests/unit/shell.scm: Make sure exit handlers are called on 'errexit'. --- gash/shell.scm | 2 +- tests/unit/shell.scm | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gash/shell.scm b/gash/shell.scm index b2703c3..fa31557 100644 --- a/gash/shell.scm +++ b/gash/shell.scm @@ -55,7 +55,7 @@ (define (errexit) (unless (or (zero? (get-status)) (ignore-errexit?)) (when (getopt 'errexit) - (exit (get-status))))) + (sh:exit)))) (define (install-current-ports!) "Install all current ports into their usual file descriptors. For diff --git a/tests/unit/shell.scm b/tests/unit/shell.scm index e45f7f2..638f85f 100644 --- a/tests/unit/shell.scm +++ b/tests/unit/shell.scm @@ -447,4 +447,20 @@ (sh:exec utility))) (call-with-input-file foo get-string-all))))) + +;;; Errexit. + +(test-assert "Exit traps are still called on errexit" + (call-with-prompt default-prompt-tag + (lambda () + (set-atexit! (lambda () (abort-to-prompt default-prompt-tag))) + (setopt! 'errexit #t) + (call-with-temporary-directory + (lambda (directory) + (let ((utility (string-append directory "/false"))) + (make-script utility + (exit EXIT_FAILURE)) + (sh:exec utility))))) + (lambda (k) #t))) + (test-end)