This fixes cases where "not not <command>" is supposed to return
only the error codes 0 or 1, but after
efee57925c3f46c74c6697,
it passed the original error code through.
This was visible on AIX in the shtest-output-printing.py testcase,
where 'wc' returns 2, while it returns 1 on other platforms, and the
test required "not not" to normalize it to 1.
assert isinstance(cmd, ShUtil.Pipeline)
procs = []
- negate_procs = []
+ proc_not_counts = []
default_stdin = subprocess.PIPE
stderrTempFiles = []
opened_files = []
stderr = stderr,
env = cmd_shenv.env,
close_fds = kUseCloseFDs))
- negate_procs.append((not_count % 2) != 0)
+ proc_not_counts.append(not_count)
# Let the helper know about this process
timeoutHelper.addProcess(procs[-1])
except OSError as e:
# Detect Ctrl-C in subprocess.
if res == -signal.SIGINT:
raise KeyboardInterrupt
- if negate_procs[i]:
+ if proc_not_counts[i] % 2:
res = not res
+ elif proc_not_counts[i] > 1:
+ res = 1 if res != 0 else 0
# Ensure the resulting output is always of string type.
try:
--- /dev/null
+#!/usr/bin/env python
+
+import print_environment
+import sys
+
+print_environment.execute()
+sys.exit(2)
--- /dev/null
+# Check that "not not" either returns 0 or 1, even if the original
+# program exited with a different code.
+
+# RUN: not not %{python} fail2.py
# Make sure not and env commands are included in printed commands.
-# CHECK: -- Testing: 16 tests{{.*}}
+# CHECK: -- Testing: 17 tests{{.*}}
# CHECK: FAIL: shtest-not :: exclamation-args-nested-none.txt {{.*}}
# CHECK: $ "!" "!" "!"
# CHECK: $ "not" "not" "--crash" "env" "-u" "BAR" "not" "env" "-u" "FOO" "BAR=1" "{{[^"]*}}" "pass.py"
+# CHECK: FAIL: shtest-not :: not-calls-fail2.txt {{.*}}
+# CHECK-NEXT: {{.*}} TEST 'shtest-not :: not-calls-fail2.txt' FAILED {{.*}}
+# CHECK-NEXT: Script:
+# CHECK-NEXT: --
+# CHECK: --
+# CHECK-NEXT: Exit Code: 1
+
# CHECK: FAIL: shtest-not :: not-calls-mkdir.txt {{.*}}
# CHECK: $ "not" "mkdir" {{.*}}
# CHECK: $ "not" "--crash" "mkdir" "foobar"
# CHECK: error: command failed with exit status: {{.*}}
# CHECK: Passed: 1
-# CHECK: Failed: 15
+# CHECK: Failed: 16
# CHECK-NOT: {{.}}