Skip to content

Commit d09adfd

Browse files
committed
[lit] Handle plain negations directly in the internal shell
Keep running "not --crash" via the external "not" executable, but for plain negations, and for cases that use the shell "!" operator, just skip that argument and invert the return code. The libcxx tests only use the shell operator "!" for negations, never the "not" executable, because libcxx tests can be run without having a fully built llvm tree available providing the "not" executable. This allows using the internal shell for libcxx tests. Differential Revision: https://reviews.llvm.org/D98859
1 parent a1d6c65 commit d09adfd

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

llvm/utils/lit/lit/TestRunner.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
608608
assert isinstance(cmd, ShUtil.Pipeline)
609609

610610
procs = []
611+
negate_procs = []
611612
default_stdin = subprocess.PIPE
612613
stderrTempFiles = []
613614
opened_files = []
@@ -653,6 +654,12 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
653654
if not args:
654655
raise InternalShellError(j, "Error: 'not' requires a"
655656
" subcommand")
657+
elif args[0] == '!':
658+
not_args.append(args.pop(0))
659+
not_count += 1
660+
if not args:
661+
raise InternalShellError(j, "Error: '!' requires a"
662+
" subcommand")
656663
else:
657664
break
658665

@@ -699,7 +706,15 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
699706
# the assumptions that (1) environment variables are not intended to be
700707
# relevant to 'not' commands and (2) the 'env' command should always
701708
# blindly pass along the status it receives from any command it calls.
702-
args = not_args + args
709+
710+
# For plain negations, either 'not' without '--crash', or the shell
711+
# operator '!', leave them out from the command to execute and
712+
# invert the result code afterwards.
713+
if not_crash:
714+
args = not_args + args
715+
not_count = 0
716+
else:
717+
not_args = []
703718

704719
stdin, stdout, stderr = processRedirects(j, default_stdin, cmd_shenv,
705720
opened_files)
@@ -763,6 +778,7 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
763778
stderr = stderr,
764779
env = cmd_shenv.env,
765780
close_fds = kUseCloseFDs))
781+
negate_procs.append((not_count % 2) != 0)
766782
# Let the helper know about this process
767783
timeoutHelper.addProcess(procs[-1])
768784
except OSError as e:
@@ -815,6 +831,8 @@ def _executeShCmd(cmd, shenv, results, timeoutHelper):
815831
# Detect Ctrl-C in subprocess.
816832
if res == -signal.SIGINT:
817833
raise KeyboardInterrupt
834+
if negate_procs[i]:
835+
res = not res
818836

819837
# Ensure the resulting output is always of string type.
820838
try:

0 commit comments

Comments
 (0)