summaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit+github@google.com>2024-03-14 14:29:54 (GMT)
committerDavid 'Digit' Turner <digit+github@google.com>2024-03-14 14:32:48 (GMT)
commit58851eb9eb9c5c177cf299deb4c03efea00d2051 (patch)
treefaf4f273bd544623421051d3c64bde3aa28d3012 /misc
parentab510c7a8cccbea0ea2c82531dc23893b551d55e (diff)
downloadNinja-58851eb9eb9c5c177cf299deb4c03efea00d2051.zip
Ninja-58851eb9eb9c5c177cf299deb4c03efea00d2051.tar.gz
Ninja-58851eb9eb9c5c177cf299deb4c03efea00d2051.tar.bz2
Minor fix to output_test.py
Do not use os.chdir() to change the current directory inside the run() function, as doing this prevents the temporary directory from being removed. Moreover, this breaks pytest invocations when adding new regression test scripts in this directory (as done in other forks). + Use dict.pop() to undefine environment variables in `default_env` dictionary.
Diffstat (limited to 'misc')
-rwxr-xr-xmisc/output_test.py15
1 files changed, 6 insertions, 9 deletions
diff --git a/misc/output_test.py b/misc/output_test.py
index a094482..78848cb 100755
--- a/misc/output_test.py
+++ b/misc/output_test.py
@@ -13,29 +13,26 @@ import tempfile
import unittest
default_env = dict(os.environ)
-if 'NINJA_STATUS' in default_env:
- del default_env['NINJA_STATUS']
-if 'CLICOLOR_FORCE' in default_env:
- del default_env['CLICOLOR_FORCE']
+default_env.pop('NINJA_STATUS', None)
+default_env.pop('CLICOLOR_FORCE', None)
default_env['TERM'] = ''
NINJA_PATH = os.path.abspath('./ninja')
def run(build_ninja, flags='', pipe=False, env=default_env):
with tempfile.TemporaryDirectory() as d:
- os.chdir(d)
- with open('build.ninja', 'w') as f:
+ with open(os.path.join(d, 'build.ninja'), 'w') as f:
f.write(build_ninja)
f.flush()
ninja_cmd = '{} {}'.format(NINJA_PATH, flags)
try:
if pipe:
- output = subprocess.check_output([ninja_cmd], shell=True, env=env)
+ output = subprocess.check_output([ninja_cmd], shell=True, cwd=d, env=env)
elif platform.system() == 'Darwin':
output = subprocess.check_output(['script', '-q', '/dev/null', 'bash', '-c', ninja_cmd],
- env=env)
+ cwd=d, env=env)
else:
output = subprocess.check_output(['script', '-qfec', ninja_cmd, '/dev/null'],
- env=env)
+ cwd=d, env=env)
except subprocess.CalledProcessError as err:
sys.stdout.buffer.write(err.output)
raise err