From 65b34a12c04c48efeb572be2c4c77b23de684b9f Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Tue, 28 Dec 2021 16:38:53 +0100 Subject: [PATCH] Declare that two "not" keywords cancel each other out "not not return 34" exits with 34, not 1. This behavior is pretty surprising but benign. I think it's very unlikely that anyone relies on the opposite behavior, because using two "not" decorators in one job is weird, and code that compares not's raw exit code is rare. The behavior doesn't match our docs, but it's not worth changing the docs because that would confuse newcomers. Add a test to cement the behavior and a comment to explain this is intentional. I considered adding the comment at parse_execution_context_t::populate_not_process where this behavior is implemented but the field defintion seems even better, because I expect programmers to read that first. Closes #8377 --- src/proc.h | 1 + tests/checks/not.fish | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 tests/checks/not.fish diff --git a/src/proc.h b/src/proc.h index ec28b2388..7a589c50c 100644 --- a/src/proc.h +++ b/src/proc.h @@ -403,6 +403,7 @@ class job_t : noncopyable_t { bool notified_of_stop{false}; /// Whether the exit status should be negated. This flag can only be set by the not builtin. + /// Two "not" prefixes on a single job cancel each other out. bool negate{false}; /// This job is disowned, and should be removed from the active jobs list. diff --git a/tests/checks/not.fish b/tests/checks/not.fish new file mode 100644 index 000000000..77a03c419 --- /dev/null +++ b/tests/checks/not.fish @@ -0,0 +1,10 @@ +#RUN: %fish %s + +not true +echo $status +# CHECK: 1 + +# Two "not" prefixes on a single job cancel each other out. +not not sh -c 'exit 34' +echo $status +# CHECK: 34