Skip to content

Commit

Permalink
test-signalhandler: assert exitcode
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Jan 18, 2025
1 parent 3780314 commit ef72a3c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions test/signal/test-signalhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __call_process(arg):


def test_assert():
_, stdout, stderr = __call_process('assert')
exitcode, stdout, stderr = __call_process('assert')
if sys.platform == "darwin":
assert stderr.startswith("Assertion failed: (false), function my_assert, file test-signalhandler.cpp, line "), stderr
else:
Expand All @@ -44,21 +44,23 @@ def test_assert():
assert lines[1] == 'Callstack:'
assert lines[2].endswith('my_abort()'), lines[2] # TODO: wrong function
assert lines[len(lines)-1] == 'Please report this to the cppcheck developers!'
assert exitcode == -6


def test_abort():
_, stdout, _ = __call_process('abort')
exitcode, stdout, _ = __call_process('abort')
lines = stdout.splitlines()
assert lines[0] == 'Internal error: cppcheck received signal SIGABRT - abort or assertion'
# no stacktrace on macOS
if sys.platform != "darwin":
assert lines[1] == 'Callstack:'
assert lines[2].endswith('my_segv()'), lines[2] # TODO: wrong function
assert lines[len(lines)-1] == 'Please report this to the cppcheck developers!'
assert exitcode == -6


def test_segv():
_, stdout, stderr = __call_process('segv')
exitcode, stdout, stderr = __call_process('segv')
assert stderr == ''
lines = stdout.splitlines()
if sys.platform == "darwin":
Expand All @@ -70,15 +72,17 @@ def test_segv():
assert lines[1] == 'Callstack:'
assert lines[2].endswith('my_segv()'), lines[2] # TODO: wrong function
assert lines[len(lines)-1] == 'Please report this to the cppcheck developers!'
assert exitcode == -11


@pytest.mark.skipif(sys.platform == 'darwin', reason='Cannot raise FPE on macOS')
def test_fpe():
_, stdout, stderr = __call_process('fpe')
exitcode, stdout, stderr = __call_process('fpe')
assert stderr == ''
lines = stdout.splitlines()
assert lines[0].startswith('Internal error: cppcheck received signal SIGFPE - FPE_FLTINV (at 0x'), lines[0]
assert lines[0].endswith(').'), lines[0]
assert lines[1] == 'Callstack:'
assert lines[3].endswith('my_fpe()'), lines[2]
assert lines[len(lines)-1] == 'Please report this to the cppcheck developers!'
assert exitcode == -8

0 comments on commit ef72a3c

Please sign in to comment.