|
| 1 | +import subprocess |
| 2 | +import os |
| 3 | +import sys |
| 4 | + |
| 5 | +def _lookup_cppcheck_exe(exe_name): |
| 6 | + # path the script is located in |
| 7 | + script_path = os.path.dirname(os.path.realpath(__file__)) |
| 8 | + |
| 9 | + if sys.platform == "win32": |
| 10 | + exe_name += ".exe" |
| 11 | + |
| 12 | + for base in (script_path + '/../../', './'): |
| 13 | + for path in ('', 'bin/', 'bin/debug/'): |
| 14 | + exe_path = base + path + exe_name |
| 15 | + if os.path.isfile(exe_path): |
| 16 | + print("using '{}'".format(exe_path)) |
| 17 | + return exe_path |
| 18 | + |
| 19 | + return None |
| 20 | + |
| 21 | +def _call_process(): |
| 22 | + exe = _lookup_cppcheck_exe('test-stacktrace') |
| 23 | + if exe is None: |
| 24 | + raise Exception('executable not found') |
| 25 | + p = subprocess.Popen([exe], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 26 | + comm = p.communicate() |
| 27 | + stdout = comm[0].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') |
| 28 | + stderr = comm[1].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n') |
| 29 | + return p.returncode, stdout, stderr |
| 30 | + |
| 31 | + |
| 32 | +def test_stack(): |
| 33 | + exitcode, stdout, stderr = _call_process() |
| 34 | + assert stderr == '' |
| 35 | + lines = stdout.splitlines() |
| 36 | + assert lines[0] == 'Callstack:' |
| 37 | + assert lines[1].endswith('my_func_2()') |
| 38 | + assert lines[2].endswith('my_func()') |
0 commit comments