Last active
October 8, 2019 09:07
-
-
Save dtasev/a894e4727eeaa94541d90ea1a3cc71a7 to your computer and use it in GitHub Desktop.
Filter GTEST failed tests from stdin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| To use to `./gest_test_binary | python filter_gtest_failed.py` | |
| Only failed tests' output will be printed. | |
| @author Dimitar Tasev | |
| @license MIT | |
| """ | |
| from __future__ import print_function | |
| import sys | |
| test_running = False | |
| test_output = [] | |
| print_everything_forever = False | |
| failed_line_end = "\n" | |
| def add_color(line, color): | |
| closing_bracket_idx = line.rfind("]") | |
| return color + line[0:closing_bracket_idx+1] + "\033[0m" + line[closing_bracket_idx+1:] | |
| for line in sys.stdin: | |
| if test_running: | |
| test_output.append(line) | |
| if "[----------] Global test environment tear-down" in line or print_everything_forever: | |
| print_everything_forever = True | |
| print(line, end="") | |
| failed_line_end = "" | |
| elif "[ FAILED ]" in line: | |
| # if test failed, print out test output | |
| test_running = False | |
| # make the [ FAILED ] red | |
| test_output[-1] = add_color(test_output[-1], "\033[31m") | |
| print("".join(test_output), end=failed_line_end) | |
| elif "[ OK ]" in line: | |
| # test was OK, if you want to see output from that... don't use this script | |
| test_running = False | |
| test_output = [] | |
| elif "[ RUN ]" in line: | |
| # test started | |
| test_running = True | |
| test_output = [add_color(line, "\033[32m")] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment