mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-09-26 03:57:28 +00:00
Verify that failures can be thrown from tearDown without crashing (Verify #67)
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
# =========================================================================
|
||||
# CMock - Automatic Mock Generation for C
|
||||
# ThrowTheSwitch.org
|
||||
# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
|
||||
# SPDX-License-Identifier: MIT
|
||||
# =========================================================================
|
||||
|
||||
# Test for issue #67: mock segfault on incorrect expectations in tearDown.
|
||||
# Verifies that calling a mock function in tearDown without a matching
|
||||
# expectation produces a clean failure message rather than a crash.
|
||||
|
||||
---
|
||||
:cmock:
|
||||
:plugins:
|
||||
- # none
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
|
||||
:mockable: |
|
||||
void init(void);
|
||||
void deinit(void);
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
/* no source functions needed for this test */
|
||||
|
||||
:tests:
|
||||
:common: |
|
||||
void setUp(void) {}
|
||||
void tearDown(void)
|
||||
{
|
||||
/* Simulate issue #67: accidentally call a mock with no expectation.
|
||||
This should produce "Called more times than expected", not a crash. */
|
||||
deinit();
|
||||
}
|
||||
|
||||
:units:
|
||||
- :pass: FALSE
|
||||
:should: 'fail gracefully (not segfault) when a mock is called in tearDown without any expectation'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
/* Empty test body; tearDown calls deinit() with no expectation */
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'fail gracefully when mock is called in tearDown even when test body passed'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
/* Test body passes fine; the tearDown call is what causes failure */
|
||||
init_Expect();
|
||||
init();
|
||||
}
|
||||
|
||||
...
|
||||
@@ -0,0 +1,59 @@
|
||||
# =========================================================================
|
||||
# CMock - Automatic Mock Generation for C
|
||||
# ThrowTheSwitch.org
|
||||
# Copyright (c) 2007-26 Mike Karlesky, Mark VanderVoord, & Greg Williams
|
||||
# SPDX-License-Identifier: MIT
|
||||
# =========================================================================
|
||||
|
||||
# Test for issue #67: mock segfault on incorrect expectations in tearDown.
|
||||
# Verifies that setting mock expectations in tearDown for functions that are
|
||||
# never called produces a clean failure message rather than a crash.
|
||||
|
||||
---
|
||||
:cmock:
|
||||
:plugins:
|
||||
- # none
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
|
||||
:mockable: |
|
||||
void init(void);
|
||||
void deinit(void);
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
/* no source functions needed for this test */
|
||||
|
||||
:tests:
|
||||
:common: |
|
||||
void setUp(void) {}
|
||||
void tearDown(void)
|
||||
{
|
||||
/* Simulate issue #67: user meant to call deinit_Expect() but accidentally
|
||||
called init_Expect() instead. The init function is never actually called,
|
||||
so CMock should report "Called too few times", not segfault. */
|
||||
init_Expect();
|
||||
}
|
||||
|
||||
:units:
|
||||
- :pass: FALSE
|
||||
:should: 'fail gracefully (not segfault) when wrong expectations are set in tearDown'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
/* Empty test body. tearDown sets up init_Expect() but init is never
|
||||
called, so CMock_Verify should report an unmet expectation. */
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'fail gracefully when wrong expectations are set in tearDown even if test body passed'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
/* Test body is correct; tearDown's wrong expectation causes the failure */
|
||||
deinit_Expect();
|
||||
deinit();
|
||||
}
|
||||
|
||||
...
|
||||
Reference in New Issue
Block a user