diff options
author | Jan Niklas Hasse <jhasse@bixense.com> | 2018-11-05 17:18:51 (GMT) |
---|---|---|
committer | Jan Niklas Hasse <jhasse@bixense.com> | 2018-11-05 17:42:31 (GMT) |
commit | 775c8e89ef6cae7b95a0cb8ccf48b990f4d9bc45 (patch) | |
tree | b734ec998f9c9ab99eaa66e9fc0227c243b21204 | |
parent | 10e66a153daa7b8ce664948031136ba27e8dfeba (diff) | |
download | Ninja-775c8e89ef6cae7b95a0cb8ccf48b990f4d9bc45.zip Ninja-775c8e89ef6cae7b95a0cb8ccf48b990f4d9bc45.tar.gz Ninja-775c8e89ef6cae7b95a0cb8ccf48b990f4d9bc45.tar.bz2 |
Add script to test Ninja's output
First test checks for #1214.
-rw-r--r-- | .travis.yml | 7 | ||||
-rwxr-xr-x | misc/output_test.py | 61 |
2 files changed, 67 insertions, 1 deletions
diff --git a/.travis.yml b/.travis.yml index 093139b..70b1fd0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,9 @@ language: cpp compiler: - gcc - clang -script: ./configure.py --bootstrap && ./ninja all && ./ninja_test --gtest_filter=-SubprocessTest.SetWithLots && ./misc/ninja_syntax_test.py +script: + - ./configure.py --bootstrap + - ./ninja all + - ./ninja_test --gtest_filter=-SubprocessTest.SetWithLots + - ./misc/ninja_syntax_test.py + - ./misc/output_test.py diff --git a/misc/output_test.py b/misc/output_test.py new file mode 100755 index 0000000..0651698 --- /dev/null +++ b/misc/output_test.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +"""Runs ./ninja and checks if the output is correct. + +In order to simulate a smart terminal it uses the 'script' command. +""" + +import subprocess +import sys +import tempfile +import unittest + +def run(build_ninja, flags='', pipe=False): + with tempfile.NamedTemporaryFile('w') as f: + f.write(build_ninja) + f.flush() + ninja_cmd = './ninja {} -f {}'.format(flags, f.name) + try: + if pipe: + output = subprocess.check_output([ninja_cmd], shell=True) + else: + output = subprocess.check_output(['script', '-qfec', ninja_cmd, '/dev/null']) + except subprocess.CalledProcessError as err: + sys.stdout.buffer.write(err.output) + raise err + final_output = '' + for line in output.decode('utf-8').splitlines(True): + if len(line) > 0 and line[-1] == '\r': + continue + final_output += line.replace('\r', '') + return final_output + +class Output(unittest.TestCase): + def test_issue_1214(self): + print_red = '''rule echo + command = printf '\x1b[31mred\x1b[0m' + description = echo $out + +build a: echo +''' + # Only strip color when ninja's output is piped. + self.assertEqual(run(print_red), +'''[1/1] echo a\x1b[K +\x1b[31mred\x1b[0m +''') + self.assertEqual(run(print_red, pipe=True), +'''[1/1] echo a +red +''') + # Even in verbose mode, colors should still only be stripped when piped. + self.assertEqual(run(print_red, flags='-v'), +'''[1/1] printf '\x1b[31mred\x1b[0m' +\x1b[31mred\x1b[0m +''') + self.assertEqual(run(print_red, flags='-v', pipe=True), +'''[1/1] printf '\x1b[31mred\x1b[0m' +red +''') + +if __name__ == '__main__': + unittest.main() |