diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/README.md | 1 | ||||
-rw-r--r-- | test/parse/force-color.txt | 14 | ||||
-rwxr-xr-x | test/run-tests.py | 19 |
3 files changed, 28 insertions, 6 deletions
diff --git a/test/README.md b/test/README.md index 64c452e0..e03508f4 100644 --- a/test/README.md +++ b/test/README.md @@ -103,6 +103,7 @@ The currently supported list of keys: - `EXE`: the executable to run, defaults to out/wast2wasm - `STDIN_FILE`: the file to use for STDIN instead of the contents of this file. - `FLAGS`: additional flags to pass to the executable +- `ENV`: environment variables to set, separated by spaces - `ERROR`: the expected return value from the executable, defaults to 0 - `SLOW`: if defined, this test's timeout is doubled. - `SKIP`: if defined, this test is not run. You can use the value as a comment. diff --git a/test/parse/force-color.txt b/test/parse/force-color.txt new file mode 100644 index 00000000..9ea7d587 --- /dev/null +++ b/test/parse/force-color.txt @@ -0,0 +1,14 @@ +;;; ERROR: 1 +;;; TOOL: wast2wasm +;;; ENV: FORCE_COLOR=1 +(module + (func badname (param i32) (result badtype) + drop)) +(;; STDERR ;;; +[1mout/test/parse/force-color.txt:5:9: [0munexpected token "badname" + (func badname (param i32) (result badtype) + [1m[32m^^^^^^^[0m +[1mout/test/parse/force-color.txt:5:37: [0munexpected token "badtype" + (func badname (param i32) (result badtype) + [1m[32m^^^^^^^[0m +;;; STDERR ;;) diff --git a/test/run-tests.py b/test/run-tests.py index 44de0525..eb459d19 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -171,7 +171,7 @@ class Cell(object): return self.value[0] -def RunCommandWithTimeout(command, cwd, timeout, console_out=False): +def RunCommandWithTimeout(command, cwd, timeout, console_out=False, env=None): process = None is_timeout = Cell(False) @@ -196,10 +196,10 @@ def RunCommandWithTimeout(command, cwd, timeout, console_out=False): # http://stackoverflow.com/a/10012262: subprocess with a timeout # http://stackoverflow.com/a/22582602: kill subprocess and children - process = subprocess.Popen(command, cwd=cwd, stdout=None if console_out - else subprocess.PIPE, stderr=None if console_out - else subprocess.PIPE, universal_newlines=True, - **kwargs) + process = subprocess.Popen(command, cwd=cwd, env=env, + stdout=None if console_out else subprocess.PIPE, + stderr=None if console_out else subprocess.PIPE, + universal_newlines=True, **kwargs) timer = threading.Timer(timeout, KillProcess) try: timer.start() @@ -231,6 +231,7 @@ class TestInfo(object): self.tool = 'wast2wasm' self.exe = '%(wast2wasm)s' self.flags = [] + self.env = {} self.last_cmd = '' self.expected_error = 0 self.slow = False @@ -250,6 +251,7 @@ class TestInfo(object): result.flags = ['--bindir', '%(bindir)s', '-v', '-o', '%(out_dir)s'] if fold_exprs: result.flags.append('--fold-exprs') + result.env = self.env result.expected_error = 0 result.slow = self.slow result.skip = self.skip @@ -311,6 +313,9 @@ class TestInfo(object): self.tool = value for tool_key, tool_value in TOOLS[value].items(): self.ParseDirective(tool_key, tool_value) + elif key == 'ENV': + # Pattern: FOO=1 BAR=stuff + self.env = dict(x.split('=') for x in value.split()) else: raise Error('Unknown directive: %s' % key) @@ -545,6 +550,8 @@ def RunTest(info, options, variables, verbose_level=0): variables = dict(variables) cwd = REPO_ROOT_DIR + env = dict(os.environ) + env.update(info.env) gen_input_path = info.CreateInputFile() rel_gen_input_path = os.path.relpath(gen_input_path, cwd) @@ -562,7 +569,7 @@ def RunTest(info, options, variables, verbose_level=0): print(' '.join(cmd)) try: - return RunCommandWithTimeout(cmd, cwd, timeout, verbose_level > 0) + return RunCommandWithTimeout(cmd, cwd, timeout, verbose_level > 0, env) except (Error, KeyboardInterrupt) as e: return e |