mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-08-03 09:47:50 +00:00
🪲 Added fail messages when using Expect for ExpectAndReturn or vice versa. (see issue #462)
This commit is contained in:
@@ -36,16 +36,20 @@ class CMockGeneratorPluginExpect
|
||||
def mock_function_declarations(function)
|
||||
if function[:args].empty?
|
||||
if function[:return][:void?]
|
||||
"#define #{function[:name]}_ExpectAndReturn(cmock_retval) TEST_FAIL_MESSAGE(\"#{function[:name]} requires _Expect (not AndReturn)\");\n" \
|
||||
"#define #{function[:name]}_Expect() #{function[:name]}_CMockExpect(__LINE__)\n" \
|
||||
"void #{function[:name]}_CMockExpect(UNITY_LINE_TYPE cmock_line);\n"
|
||||
else
|
||||
"#define #{function[:name]}_Expect() TEST_FAIL_MESSAGE(\"#{function[:name]} requires _ExpectAndReturn\");\n" \
|
||||
"#define #{function[:name]}_ExpectAndReturn(cmock_retval) #{function[:name]}_CMockExpectAndReturn(__LINE__, cmock_retval)\n" \
|
||||
"void #{function[:name]}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:return][:str]});\n"
|
||||
end
|
||||
elsif function[:return][:void?]
|
||||
"#define #{function[:name]}_ExpectAndReturn(#{function[:args_call]}, cmock_retval) TEST_FAIL_MESSAGE(\"#{function[:name]} requires _Expect (not AndReturn)\");\n" \
|
||||
"#define #{function[:name]}_Expect(#{function[:args_call]}) #{function[:name]}_CMockExpect(__LINE__, #{function[:args_call]})\n" \
|
||||
"void #{function[:name]}_CMockExpect(UNITY_LINE_TYPE cmock_line, #{function[:args_string]});\n"
|
||||
else
|
||||
"#define #{function[:name]}_Expect(#{function[:args_call]}) TEST_FAIL_MESSAGE(\"#{function[:name]} requires _ExpectAndReturn\");\n" \
|
||||
"#define #{function[:name]}_ExpectAndReturn(#{function[:args_call]}, cmock_retval) #{function[:name]}_CMockExpectAndReturn(__LINE__, #{function[:args_call]}, cmock_retval)\n" \
|
||||
"void #{function[:name]}_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, #{function[:args_string]}, #{function[:return][:str]});\n"
|
||||
end
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
---
|
||||
:cmock:
|
||||
:plugins:
|
||||
- # none
|
||||
|
||||
:systest:
|
||||
:types: |
|
||||
#define UINT32 unsigned int
|
||||
|
||||
typedef signed int custom_type;
|
||||
|
||||
:mockable: |
|
||||
UINT32 foo(custom_type a);
|
||||
UINT32 bar(void);
|
||||
UINT32 foo_varargs(custom_type a, ...);
|
||||
void do_it(void);
|
||||
void do_another(int i);
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
UINT32 function_a(int a);
|
||||
void function_b(void);
|
||||
UINT32 function_c(int a);
|
||||
void function_d(void);
|
||||
|
||||
:code: |
|
||||
UINT32 function_a(int a)
|
||||
{
|
||||
return foo((custom_type)a) + bar();
|
||||
}
|
||||
|
||||
void function_b(void) { }
|
||||
|
||||
UINT32 function_c(int a)
|
||||
{
|
||||
return foo_varargs((custom_type)a, "ignored", 5);
|
||||
}
|
||||
|
||||
void function_d(void)
|
||||
{
|
||||
do_it();
|
||||
do_another(2);
|
||||
}
|
||||
|
||||
:tests:
|
||||
:common: |
|
||||
void setUp(void) {}
|
||||
void tearDown(void) {}
|
||||
|
||||
:units:
|
||||
- :pass: FALSE
|
||||
:should: 'successfully report using Expect instead of ExpectAndReturn with args'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
foo_Expect((custom_type)1);
|
||||
bar_ExpectAndReturn(2);
|
||||
function_a(1);
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'successfully report using Expect instead of ExpectAndReturn without args'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
foo_ExpectAndReturn((custom_type)1, 4);
|
||||
bar_Expect();
|
||||
function_a(1);
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'successfully report using Expect instead of ExpectAndReturn with varargs'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
foo_varargs_Expect((custom_type)3);
|
||||
function_c(3);
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'successfully report using ExpectAndReturn instead of Expect with args'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
do_it_Expect();
|
||||
do_another_ExpectAndReturn(2, 2);
|
||||
function_d();
|
||||
}
|
||||
|
||||
- :pass: FALSE
|
||||
:should: 'successfully report using ExpectAndReturn instead of Expect without args'
|
||||
:code: |
|
||||
test()
|
||||
{
|
||||
do_it_ExpectAndReturn(6);
|
||||
do_another_Expect(2);
|
||||
function_d();
|
||||
}
|
||||
|
||||
|
||||
...
|
||||
@@ -64,7 +64,8 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module W
|
||||
|
||||
it "add mock function declaration for functions of style 'void func(void)'" do
|
||||
function = {:name => "Maple", :args => [], :return => test_return[:void]}
|
||||
expected = "#define Maple_Expect() Maple_CMockExpect(__LINE__)\n" +
|
||||
expected = "#define Maple_ExpectAndReturn(cmock_retval) TEST_FAIL_MESSAGE(\"Maple requires _Expect (not AndReturn)\");\n" +
|
||||
"#define Maple_Expect() Maple_CMockExpect(__LINE__)\n" +
|
||||
"void Maple_CMockExpect(UNITY_LINE_TYPE cmock_line);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
@@ -72,7 +73,8 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module W
|
||||
|
||||
it "add mock function declaration for functions of style 'int func(void)'" do
|
||||
function = {:name => "Spruce", :args => [], :return => test_return[:int]}
|
||||
expected = "#define Spruce_ExpectAndReturn(cmock_retval) Spruce_CMockExpectAndReturn(__LINE__, cmock_retval)\n" +
|
||||
expected = "#define Spruce_Expect() TEST_FAIL_MESSAGE(\"Spruce requires _ExpectAndReturn\");\n" +
|
||||
"#define Spruce_ExpectAndReturn(cmock_retval) Spruce_CMockExpectAndReturn(__LINE__, cmock_retval)\n" +
|
||||
"void Spruce_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
@@ -80,7 +82,8 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module W
|
||||
|
||||
it "add mock function declaration for functions of style 'const char* func(int tofu)'" do
|
||||
function = {:name => "Pine", :args => ["int tofu"], :args_string => "int tofu", :args_call => 'tofu', :return => test_return[:string]}
|
||||
expected = "#define Pine_ExpectAndReturn(tofu, cmock_retval) Pine_CMockExpectAndReturn(__LINE__, tofu, cmock_retval)\n" +
|
||||
expected = "#define Pine_Expect(tofu) TEST_FAIL_MESSAGE(\"Pine requires _ExpectAndReturn\");\n" +
|
||||
"#define Pine_ExpectAndReturn(tofu, cmock_retval) Pine_CMockExpectAndReturn(__LINE__, tofu, cmock_retval)\n" +
|
||||
"void Pine_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int tofu, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
|
||||
@@ -64,7 +64,8 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w
|
||||
|
||||
it "add mock function declaration for functions of style 'void func(void)'" do
|
||||
function = {:name => "Maple", :args => [], :return => test_return[:void]}
|
||||
expected = "#define Maple_Expect() Maple_CMockExpect(__LINE__)\n" +
|
||||
expected = "#define Maple_ExpectAndReturn(cmock_retval) TEST_FAIL_MESSAGE(\"Maple requires _Expect (not AndReturn)\");\n" +
|
||||
"#define Maple_Expect() Maple_CMockExpect(__LINE__)\n" +
|
||||
"void Maple_CMockExpect(UNITY_LINE_TYPE cmock_line);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
@@ -72,7 +73,8 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w
|
||||
|
||||
it "add mock function declaration for functions of style 'int func(void)'" do
|
||||
function = {:name => "Spruce", :args => [], :return => test_return[:int]}
|
||||
expected = "#define Spruce_ExpectAndReturn(cmock_retval) Spruce_CMockExpectAndReturn(__LINE__, cmock_retval)\n" +
|
||||
expected = "#define Spruce_Expect() TEST_FAIL_MESSAGE(\"Spruce requires _ExpectAndReturn\");\n" +
|
||||
"#define Spruce_ExpectAndReturn(cmock_retval) Spruce_CMockExpectAndReturn(__LINE__, cmock_retval)\n" +
|
||||
"void Spruce_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
@@ -80,7 +82,8 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w
|
||||
|
||||
it "add mock function declaration for functions of style 'const char* func(int tofu)'" do
|
||||
function = {:name => "Pine", :args => ["int tofu"], :args_string => "int tofu", :args_call => 'tofu', :return => test_return[:string]}
|
||||
expected = "#define Pine_ExpectAndReturn(tofu, cmock_retval) Pine_CMockExpectAndReturn(__LINE__, tofu, cmock_retval)\n" +
|
||||
expected = "#define Pine_Expect(tofu) TEST_FAIL_MESSAGE(\"Pine requires _ExpectAndReturn\");\n" +
|
||||
"#define Pine_ExpectAndReturn(tofu, cmock_retval) Pine_CMockExpectAndReturn(__LINE__, tofu, cmock_retval)\n" +
|
||||
"void Pine_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int tofu, const char* cmock_to_return);\n"
|
||||
returned = @cmock_generator_plugin_expect.mock_function_declarations(function)
|
||||
assert_equal(expected, returned)
|
||||
|
||||
Reference in New Issue
Block a user