llvm.org GIT mirror llvm / 0fb951d
[lit] Check for accidental external command calls This patch extends lit's test suite to check that lit's internal shell doesn't accidentally execute internal commands as external commands. It does so by putting fake failing versions of those commands in `PATH` while the entire lit test suite is running. Without the fixes in D65697 but with its tests, this approach catches accidental external `env` calls. Reviewed By: probinson Differential Revision: https://reviews.llvm.org/D66293 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@369309 91177308-0d34-0410-b5e6-96231b3b80d8 Joel E. Denny 29 days ago
8 changed file(s) with 48 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 #!/usr/bin/env python
1
2 import fake_external
3
4 fake_external.execute(__file__)
0 #!/usr/bin/env python
1
2 import fake_external
3
4 fake_external.execute(__file__)
0 #!/usr/bin/env python
1
2 import fake_external
3
4 fake_external.execute(__file__)
0 #!/usr/bin/env python
1
2 import fake_external
3
4 fake_external.execute(__file__)
0 import os
1 import sys
2
3 def execute(fileName):
4 sys.stderr.write("error: external '{}' command called unexpectedly\n"
5 .format(os.path.basename(fileName)));
6 sys.exit(1)
0 #!/usr/bin/env python
1
2 import fake_external
3
4 fake_external.execute(__file__)
0 #!/usr/bin/env python
1
2 import fake_external
3
4 fake_external.execute(__file__)
7474 if not llvm_config:
7575 if sys.platform.startswith('win') or sys.platform.startswith('cygwin'):
7676 config.available_features.add('system-windows')
77
78 # For each of lit's internal shell commands ('env', 'cd', 'diff', etc.), put
79 # a fake command that always fails at the start of PATH. This helps us check
80 # that we always use lit's internal version rather than some external version
81 # that might not be present or behave correctly on all platforms. Don't do
82 # this for 'echo' because an external version is used when it appears in a
83 # pipeline. Don't do this for ':' because it doesn't appear to be a valid file
84 # name under Windows.
85 test_bin = os.path.join(os.path.dirname(__file__), 'Inputs', 'fake-externals')
86 config.environment['PATH'] = os.path.pathsep.join((test_bin,
87 config.environment['PATH']))