git: 76797b9b6ed4 - main - atf-check: Add shortcut for not-exit:0

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Wed, 11 Nov 2026 20:36:14 UTC
The branch main has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=76797b9b6ed4f2fe4ebb08fede0f19a88f985494

commit 76797b9b6ed4f2fe4ebb08fede0f19a88f985494
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-11-11 20:35:44 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-11-11 20:35:44 +0000

    atf-check: Add shortcut for not-exit:0
    
    Allow the command to be preceded by an exclamation point, which changes
    the default expected result to a clean exit with a non-zero exit code.
    
    MFC after:      1 week
    Sponsored by:   Klara, Inc.
    Reviewed by:    ngie
    Differential Revision:  https://reviews.freebsd.org/D58099
---
 contrib/atf/atf-sh/atf-check.1       | 18 ++++++++++++++++--
 contrib/atf/atf-sh/atf-check.cpp     | 10 +++++++++-
 contrib/atf/atf-sh/atf-check_test.sh |  6 ++++++
 contrib/atf/atf-sh/atf_check_test.sh | 12 ++++++++++++
 4 files changed, 43 insertions(+), 3 deletions(-)

diff --git a/contrib/atf/atf-sh/atf-check.1 b/contrib/atf/atf-sh/atf-check.1
index 18d000a8750c..8c4fb94f5c11 100644
--- a/contrib/atf/atf-sh/atf-check.1
+++ b/contrib/atf/atf-sh/atf-check.1
@@ -22,7 +22,7 @@
 .\" IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 .\" IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-.Dd August 13, 2026
+.Dd September 24, 2026
 .Dt ATF-CHECK 1
 .Os
 .Sh NAME
@@ -35,6 +35,7 @@
 .Op Fl e Ar action:arg ...
 .Op Fl x
 .Op Fl r Ar timeout[:interval]
+.Op \&!
 .Ar command
 .Sh DESCRIPTION
 .Nm
@@ -60,6 +61,19 @@ acts as if it was run with
 .Ar empty
 .Fl e
 .Ar empty .
+If
+.Ar command
+is preceded by
+.Sq \&! ,
+it will default to
+.Fl s
+.Ar not-exit:0
+instead of
+.Fl s
+.Ar exit:0 .
+Multiple checks for the same output channel are allowed and, if specified,
+their results will be combined as a logical and (meaning that the output must
+match all the provided checks).
 .Pp
 .Fl o
 .Ar empty
@@ -159,7 +173,7 @@ directly:
 atf_check true
 
 # Typical usage if failure is expected
-atf_check -s not-exit:0 false
+atf_check ! false
 
 # Checking stdout/stderr
 echo foobar >expout
diff --git a/contrib/atf/atf-sh/atf-check.cpp b/contrib/atf/atf-sh/atf-check.cpp
index 819ff7e9c82b..67d2b479c710 100644
--- a/contrib/atf/atf-sh/atf-check.cpp
+++ b/contrib/atf/atf-sh/atf-check.cpp
@@ -910,13 +910,21 @@ atf_check::process_option(int ch, const char* arg)
 int
 atf_check::main(void)
 {
+    bool negate = false;
+
+    while (m_argc > 0 && strcmp(m_argv[0], "!") == 0) {
+        negate = !negate;
+        m_argc--;
+        m_argv++;
+    }
+
     if (m_argc < 1)
         throw atf::application::usage_error("No command specified");
 
     int status = EXIT_FAILURE;
 
     if (m_status_checks.empty()) {
-        m_status_checks.push_back(status_check(sc_exit, false, EXIT_SUCCESS,
+        m_status_checks.push_back(status_check(sc_exit, negate, EXIT_SUCCESS,
             false));
     } else if (m_status_checks.size() > 1) {
         // TODO: Remove this restriction.
diff --git a/contrib/atf/atf-sh/atf-check_test.sh b/contrib/atf/atf-sh/atf-check_test.sh
index 3d2e78438640..11f622ea8316 100644
--- a/contrib/atf/atf-sh/atf-check_test.sh
+++ b/contrib/atf/atf-sh/atf-check_test.sh
@@ -90,11 +90,17 @@ sflag_exit_body()
     h_pass 'false' -s not-exit:0
     h_pass 'exit 255' -s exit:255
     h_pass 'exit 0' -s not-exit:255
+    h_pass 'false' !
+    h_pass 'true' ! !
+    h_pass 'false' ! ! !
 
     h_fail 'exit 256' -s exit:256
     h_fail 'exit -1' -s exit:-1
     h_fail 'true' -s not-exit:256
     h_fail 'true' -s not-exit:-1
+    h_fail 'true' !
+    h_fail 'false' ! !
+    h_fail 'true' ! ! !
 
     h_pass 'true' -s exit
     h_pass 'false' -s exit
diff --git a/contrib/atf/atf-sh/atf_check_test.sh b/contrib/atf/atf-sh/atf_check_test.sh
index 6fe2bb775274..3495473f83fd 100644
--- a/contrib/atf/atf-sh/atf_check_test.sh
+++ b/contrib/atf/atf-sh/atf_check_test.sh
@@ -207,6 +207,17 @@ flush_stdout_on_death_body()
         || atf_fail 'Second command not in output'
 }
 
+atf_test_case negate
+negate_body()
+{
+	atf_check true
+	atf_check ! false
+	atf_check ! ! true
+	atf_check ! ! ! false
+	atf_check true !
+	atf_check -o inline:'!\n' echo !
+}
+
 atf_init_test_cases()
 {
     atf_add_test_case info_ok
@@ -216,6 +227,7 @@ atf_init_test_cases()
     atf_add_test_case null_stderr
     atf_add_test_case equal
     atf_add_test_case flush_stdout_on_death
+    atf_add_test_case negate
 }
 
 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4