Finish giving clues when you've chosen the wrong AndReturn version.

ReturnArrayThruPtr (and others) now protect sizes in parenthesis #415
This commit is contained in:
Mark VanderVoord
2024-03-21 11:35:21 -04:00
parent 3a6f1f29a3
commit 597a6d86eb
12 changed files with 97 additions and 33 deletions
@@ -1,7 +1,8 @@
---
:cmock:
:plugins:
- # none
- :ignore
- :expect_any_args
:systest:
:types: |
@@ -97,5 +98,45 @@
function_d();
}
- :pass: FALSE
:should: 'successfully report using ExpectAnyArgs instead of ExpectAnyArgsAndReturn'
:code: |
test()
{
foo_ExpectAnyArgs();
bar_ExpectAndReturn(2);
function_a(1);
}
- :pass: FALSE
:should: 'successfully report using ExpectAnyArgsAndReturn instead of ExpectAnyArgs'
:code: |
test()
{
do_it_Expect();
do_another_ExpectAnyArgsAndReturn(2);
function_d();
}
- :pass: FALSE
:should: 'successfully report using Ignore instead of IgnoreAndReturn'
:code: |
test()
{
foo_Ignore();
bar_IgnoreAndReturn(2);
function_a(1);
}
- :pass: FALSE
:should: 'successfully report using IgnoreAndReturn instead of Ignore'
:code: |
test()
{
do_it_Ignore();
do_another_IgnoreAndReturn(2);
function_d();
}
...
@@ -73,7 +73,8 @@ describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do
:return => test_return[:void],
:contains_ptr? => true }
expected = "#define #{function[:name]}_ExpectWithArray(tofu, tofu_Depth) #{function[:name]}_CMockExpectWithArray(__LINE__, tofu, tofu_Depth)\n" +
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) TEST_FAIL_MESSAGE(\"#{function[:name]} requires _ExpectWithArray (not AndReturn)\");\n" +
"#define #{function[:name]}_ExpectWithArray(tofu, tofu_Depth) #{function[:name]}_CMockExpectWithArray(__LINE__, tofu, (tofu_Depth))\n" +
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth);\n"
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
assert_equal(expected, returned)
@@ -88,7 +89,8 @@ describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do
:return => test_return[:string],
:contains_ptr? => true }
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, tofu_Depth, cmock_retval)\n" +
expected = "#define #{function[:name]}_ExpectWithArray(tofu, tofu_Depth) TEST_FAIL_MESSAGE(\"#{function[:name]} requires _ExpectWithArrayAndReturn\");\n" +
"#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, (tofu_Depth), cmock_retval)\n" +
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, int* tofu, int tofu_Depth, const char* cmock_to_return);\n"
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
assert_equal(expected, returned)
@@ -104,7 +106,8 @@ describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do
:return => test_return[:string],
:contains_ptr? => true }
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, tofu_Depth, cmock_retval)\n" +
expected = "#define #{function[:name]}_ExpectWithArray(tofu, tofu_Depth) TEST_FAIL_MESSAGE(\"#{function[:name]} requires _ExpectWithArrayAndReturn\");\n" +
"#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, (tofu_Depth), cmock_retval)\n" +
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, const int* tofu, int tofu_Depth, const char* cmock_to_return);\n"
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
assert_equal(expected, returned)
@@ -35,14 +35,17 @@ describe CMockGeneratorPluginExpectAnyArgs, "Verify CMockGeneratorPluginExpectAn
it "handle function declarations for functions without return values" do
function = {:name => "Mold", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:void]}
expected = "#define Mold_ExpectAnyArgs() Mold_CMockExpectAnyArgs(__LINE__)\nvoid Mold_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n"
expected = "#define Mold_ExpectAnyArgsAndReturn(cmock_retval) TEST_FAIL_MESSAGE(\"Mold requires _ExpectAnyArgs (not AndReturn)\");\n"+
"#define Mold_ExpectAnyArgs() Mold_CMockExpectAnyArgs(__LINE__)\n"+
"void Mold_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n"
returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function)
assert_equal(expected, returned)
end
it "handle function declarations for functions that returns something" do
function = {:name => "Fungus", :args_string => "int meh", :args => [ :stuff ], :return => test_return[:string]}
expected = "#define Fungus_ExpectAnyArgsAndReturn(cmock_retval) Fungus_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n"+
expected = "#define Fungus_ExpectAnyArgs() TEST_FAIL_MESSAGE(\"Fungus requires _ExpectAnyArgsAndReturn\");\n"+
"#define Fungus_ExpectAnyArgsAndReturn(cmock_retval) Fungus_CMockExpectAnyArgsAndReturn(__LINE__, cmock_retval)\n"+
"void Fungus_CMockExpectAnyArgsAndReturn(UNITY_LINE_TYPE cmock_line, const char* cmock_to_return);\n"
returned = @cmock_generator_plugin_expect_any_args.mock_function_declarations(function)
assert_equal(expected, returned)
@@ -35,15 +35,19 @@ describe CMockGeneratorPluginIgnoreStateless, "Verify CMockGeneratorPluginIgnore
it "handle function declarations for functions without return values" do
function = {:name => "Mold", :args_string => "void", :return => test_return[:void]}
expected = "#define Mold_Ignore() Mold_CMockIgnore()\nvoid Mold_CMockIgnore(void);\n" +
"#define Mold_StopIgnore() Mold_CMockStopIgnore()\nvoid Mold_CMockStopIgnore(void);\n"
expected = "#define Mold_IgnoreAndReturn(cmock_retval) TEST_FAIL_MESSAGE(\"Mold requires _Ignore (not AndReturn)\");\n" +
"#define Mold_Ignore() Mold_CMockIgnore()\n" +
"void Mold_CMockIgnore(void);\n" +
"#define Mold_StopIgnore() Mold_CMockStopIgnore()\n" +
"void Mold_CMockStopIgnore(void);\n"
returned = @cmock_generator_plugin_ignore_stateless.mock_function_declarations(function)
assert_equal(expected, returned)
end
it "handle function declarations for functions that returns something" do
function = {:name => "Fungus", :args_string => "void", :return => test_return[:string]}
expected = "#define Fungus_IgnoreAndReturn(cmock_retval) Fungus_CMockIgnoreAndReturn(cmock_retval)\n"+
expected = "#define Fungus_Ignore() TEST_FAIL_MESSAGE(\"Fungus requires _IgnoreAndReturn\");\n"+
"#define Fungus_IgnoreAndReturn(cmock_retval) Fungus_CMockIgnoreAndReturn(cmock_retval)\n"+
"void Fungus_CMockIgnoreAndReturn(const char* cmock_to_return);\n" +
"#define Fungus_StopIgnore() Fungus_CMockStopIgnore()\n"+
"void Fungus_CMockStopIgnore(void);\n"
@@ -35,15 +35,19 @@ describe CMockGeneratorPluginIgnore, "Verify CMockGeneratorPluginIgnore Module"
it "handle function declarations for functions without return values" do
function = {:name => "Mold", :args_string => "void", :return => test_return[:void]}
expected = "#define Mold_Ignore() Mold_CMockIgnore()\nvoid Mold_CMockIgnore(void);\n" +
"#define Mold_StopIgnore() Mold_CMockStopIgnore()\nvoid Mold_CMockStopIgnore(void);\n"
expected = "#define Mold_IgnoreAndReturn(cmock_retval) TEST_FAIL_MESSAGE(\"Mold requires _Ignore (not AndReturn)\");\n" +
"#define Mold_Ignore() Mold_CMockIgnore()\n" +
"void Mold_CMockIgnore(void);\n" +
"#define Mold_StopIgnore() Mold_CMockStopIgnore()\n" +
"void Mold_CMockStopIgnore(void);\n"
returned = @cmock_generator_plugin_ignore.mock_function_declarations(function)
assert_equal(expected, returned)
end
it "handle function declarations for functions that returns something" do
function = {:name => "Fungus", :args_string => "void", :return => test_return[:string]}
expected = "#define Fungus_IgnoreAndReturn(cmock_retval) Fungus_CMockIgnoreAndReturn(__LINE__, cmock_retval)\n"+
expected = "#define Fungus_Ignore() TEST_FAIL_MESSAGE(\"Fungus requires _IgnoreAndReturn\");\n"+
"#define Fungus_IgnoreAndReturn(cmock_retval) Fungus_CMockIgnoreAndReturn(__LINE__, cmock_retval)\n"+
"void Fungus_CMockIgnoreAndReturn(UNITY_LINE_TYPE cmock_line, const char* cmock_to_return);\n" +
"#define Fungus_StopIgnore() Fungus_CMockStopIgnore()\n"+
"void Fungus_CMockStopIgnore(void);\n"
@@ -118,16 +118,16 @@ describe CMockGeneratorPluginReturnThruPtr, "Verify CMockGeneratorPluginReturnTh
"#define Pine_ReturnThruPtr_tofu(tofu)" +
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, sizeof(int))\n" +
"#define Pine_ReturnArrayThruPtr_tofu(tofu, cmock_len)" +
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, cmock_len * sizeof(*tofu))\n" +
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, (cmock_len * sizeof(*tofu)))\n" +
"#define Pine_ReturnMemThruPtr_tofu(tofu, cmock_size)" +
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, cmock_size)\n" +
" Pine_CMockReturnMemThruPtr_tofu(__LINE__, tofu, (cmock_size))\n" +
"void Pine_CMockReturnMemThruPtr_tofu(UNITY_LINE_TYPE cmock_line, int const* tofu, size_t cmock_size);\n"+
"#define Pine_ReturnThruPtr_bean_buffer(bean_buffer)" +
" Pine_CMockReturnMemThruPtr_bean_buffer(__LINE__, bean_buffer, sizeof(char*))\n" +
"#define Pine_ReturnArrayThruPtr_bean_buffer(bean_buffer, cmock_len)" +
" Pine_CMockReturnMemThruPtr_bean_buffer(__LINE__, bean_buffer, cmock_len * sizeof(*bean_buffer))\n" +
" Pine_CMockReturnMemThruPtr_bean_buffer(__LINE__, bean_buffer, (cmock_len * sizeof(*bean_buffer)))\n" +
"#define Pine_ReturnMemThruPtr_bean_buffer(bean_buffer, cmock_size)" +
" Pine_CMockReturnMemThruPtr_bean_buffer(__LINE__, bean_buffer, cmock_size)\n" +
" Pine_CMockReturnMemThruPtr_bean_buffer(__LINE__, bean_buffer, (cmock_size))\n" +
"void Pine_CMockReturnMemThruPtr_bean_buffer(UNITY_LINE_TYPE cmock_line, char* const* bean_buffer, size_t cmock_size);\n"
returned = @cmock_generator_plugin_return_thru_ptr.mock_function_declarations(@complex_func)
@@ -141,16 +141,16 @@ describe CMockGeneratorPluginReturnThruPtr, "Verify CMockGeneratorPluginReturnTh
"#define Spruce_ReturnThruPtr_pork(pork)" +
" Spruce_CMockReturnMemThruPtr_pork(__LINE__, pork, sizeof(*pork))\n" +
"#define Spruce_ReturnArrayThruPtr_pork(pork, cmock_len)" +
" Spruce_CMockReturnMemThruPtr_pork(__LINE__, pork, cmock_len * sizeof(*pork))\n" +
" Spruce_CMockReturnMemThruPtr_pork(__LINE__, pork, (cmock_len * sizeof(*pork)))\n" +
"#define Spruce_ReturnMemThruPtr_pork(pork, cmock_size)" +
" Spruce_CMockReturnMemThruPtr_pork(__LINE__, pork, cmock_size)\n" +
" Spruce_CMockReturnMemThruPtr_pork(__LINE__, pork, (cmock_size))\n" +
"void Spruce_CMockReturnMemThruPtr_pork(UNITY_LINE_TYPE cmock_line, void const* pork, size_t cmock_size);\n" +
"#define Spruce_ReturnThruPtr_salad(salad)" +
" Spruce_CMockReturnMemThruPtr_salad(__LINE__, salad, sizeof(*salad))\n" +
"#define Spruce_ReturnArrayThruPtr_salad(salad, cmock_len)" +
" Spruce_CMockReturnMemThruPtr_salad(__LINE__, salad, cmock_len * sizeof(*salad))\n" +
" Spruce_CMockReturnMemThruPtr_salad(__LINE__, salad, (cmock_len * sizeof(*salad)))\n" +
"#define Spruce_ReturnMemThruPtr_salad(salad, cmock_size)" +
" Spruce_CMockReturnMemThruPtr_salad(__LINE__, salad, cmock_size)\n" +
" Spruce_CMockReturnMemThruPtr_salad(__LINE__, salad, (cmock_size))\n" +
"void Spruce_CMockReturnMemThruPtr_salad(UNITY_LINE_TYPE cmock_line, MY_FANCY_VOID const* salad, size_t cmock_size);\n"
returned = @cmock_generator_plugin_return_thru_ptr.mock_function_declarations(@void_ptr_func)