diff --git a/lib/cmock_generator.rb b/lib/cmock_generator.rb index 109ebd5..b47fdc9 100644 --- a/lib/cmock_generator.rb +++ b/lib/cmock_generator.rb @@ -126,7 +126,7 @@ class CMockGenerator def create_mock_verify_function(file, functions) file << "void #{@mock_name}_Verify(void)\n{\n" verifications = functions.collect {|function| @plugins.run(:mock_verify, function)}.join - verifications += " UNITY_TEST_ASSERT_NULL(GlobalOrderError, cmock_line, NULL);\n" if (@ordered) + verifications += " UNITY_TEST_ASSERT_NULL(GlobalOrderError, cmock_line, \"Internal CMock error.\");\n" if (@ordered) file << " UNITY_LINE_TYPE cmock_line = TEST_LINE_NUM;\n" unless verifications.empty? file << verifications file << "}\n\n" diff --git a/lib/cmock_generator_utils.rb b/lib/cmock_generator_utils.rb index 718cc3d..4a914ba 100644 --- a/lib/cmock_generator_utils.rb +++ b/lib/cmock_generator_utils.rb @@ -94,7 +94,7 @@ class CMockGeneratorUtils else (@helpers.nil? or @helpers[:unity_helper].nil?) ? ["UNITY_TEST_ASSERT_EQUAL",''] : @helpers[:unity_helper].get_helper(c_type) end - unity_msg = ", \"Function '#{function[:name]}' called with unexpected value for argument '#{arg_name}'.\"" + unity_msg = "Function '#{function[:name]}' called with unexpected value for argument '#{arg_name}'." return c_type, arg_name, expected, unity_func[0], unity_func[1], unity_msg end @@ -103,19 +103,19 @@ class CMockGeneratorUtils case(unity_func) when "UNITY_TEST_ASSERT_EQUAL_MEMORY" c_type_local = c_type.gsub(/\*$/,'') - return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line#{unity_msg});\n" + return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, \"#{unity_msg}\");\n" when "UNITY_TEST_ASSERT_EQUAL_MEMORY" [ " if (#{pre}#{expected} == NULL)", - " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, NULL); }", + " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }", " else", - " { UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), cmock_line#{unity_msg}); }\n"].join("\n") + " { UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), cmock_line, \"#{unity_msg}\"); }\n"].join("\n") when /_ARRAY/ [ " if (#{pre}#{expected} == NULL)", - " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, NULL); }", + " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }", " else", - " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, NULL); }\n"].join("\n") + " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, \"#{unity_msg}\"); }\n"].join("\n") else - return " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line#{unity_msg});\n" + return " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\");\n" end end @@ -125,23 +125,23 @@ class CMockGeneratorUtils case(unity_func) when "UNITY_TEST_ASSERT_EQUAL_MEMORY" c_type_local = c_type.gsub(/\*$/,'') - return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line#{unity_msg});\n" + return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, \"#{unity_msg}\");\n" when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY" [ " if (#{pre}#{expected} == NULL)", - " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, NULL); }", + " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }", " else", - " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line#{unity_msg}); }\n"].compact.join("\n") + " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n"].compact.join("\n") when /_ARRAY/ if (pre == '&') - " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, NULL);\n" + " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\");\n" else [ " if (#{pre}#{expected} == NULL)", - " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, NULL); }", + " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }", " else", - " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, NULL); }\n"].compact.join("\n") + " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n"].compact.join("\n") end else - return " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line#{unity_msg});\n" + return " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\");\n" end end @@ -151,25 +151,25 @@ class CMockGeneratorUtils case(unity_func) when "UNITY_TEST_ASSERT_EQUAL_MEMORY" c_type_local = c_type.gsub(/\*$/,'') - return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line#{unity_msg});\n" + return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, \"#{unity_msg}\");\n" when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY" [ " if (#{pre}#{expected} == NULL)", - " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }", - ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_HEX32(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, NULL); }" : nil), + " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }", + ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_HEX32(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\"); }" : nil), " else", - " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line#{unity_msg}); }\n"].compact.join("\n") + " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n"].compact.join("\n") when /_ARRAY/ if (pre == '&') - " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, NULL);\n" + " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\");\n" else [ " if (#{pre}#{expected} == NULL)", - " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, NULL); }", - ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_HEX32(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, NULL); }" : nil), + " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }", + ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_HEX32(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\"); }" : nil), " else", - " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, NULL); }\n"].compact.join("\n") + " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n"].compact.join("\n") end else - return " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line#{unity_msg});\n" + return " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\");\n" end end diff --git a/test/unit/cmock_generator_main_test.rb b/test/unit/cmock_generator_main_test.rb index 9518506..8d8150d 100644 --- a/test/unit/cmock_generator_main_test.rb +++ b/test/unit/cmock_generator_main_test.rb @@ -234,7 +234,7 @@ class CMockGeneratorTest < Test::Unit::TestCase " Dos_First" + " Uno_Second" + " Dos_Second" + - " UNITY_TEST_ASSERT_NULL(GlobalOrderError, cmock_line, NULL);\n", + " UNITY_TEST_ASSERT_NULL(GlobalOrderError, cmock_line, \"Internal CMock error.\");\n", "}\n\n" ] @plugins.expect.run(:mock_verify, functions[0]).returns([" Uno_First"," Dos_First"]) diff --git a/test/unit/cmock_generator_utils_test.rb b/test/unit/cmock_generator_utils_test.rb index 5febe65..6398fd0 100644 --- a/test/unit/cmock_generator_utils_test.rb +++ b/test/unit/cmock_generator_utils_test.rb @@ -215,7 +215,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase should 'handle pointers to custom types with array handlers, even if the array extension is turned off' do function = { :name => 'Pear' } arg = test_arg[:mytype] - expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, NULL);\n" + expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n" @unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY','&']) assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) end @@ -232,11 +232,11 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase function = { :name => 'Pear' } arg = test_arg[:int_ptr] expected = " if (cmock_call_instance->Expected_MyIntPtr == NULL)\n" + - " { UNITY_TEST_ASSERT_NULL(MyIntPtr, cmock_line, NULL); }\n" + + " { UNITY_TEST_ASSERT_NULL(MyIntPtr, cmock_line, \"Expected NULL. Function 'Pear' called with unexpected value for argument 'MyIntPtr'.\"); }\n" + " else if (cmock_call_instance->Expected_MyIntPtr_Depth == 0)\n" + - " { UNITY_TEST_ASSERT_EQUAL_HEX32(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, NULL); }\n" + + " { UNITY_TEST_ASSERT_EQUAL_HEX32(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyIntPtr'.\"); }\n" + " else\n" + - " { UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_call_instance->Expected_MyIntPtr_Depth, cmock_line, NULL); }\n" + " { UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_call_instance->Expected_MyIntPtr_Depth, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyIntPtr'.\"); }\n" @unity_helper.expect.get_helper('int*').returns(['UNITY_TEST_ASSERT_EQUAL_INT_ARRAY','']) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) end @@ -269,11 +269,11 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase function = { :name => 'Pear' } arg = test_arg[:mytype_ptr] expected = " if (cmock_call_instance->Expected_MyMyTypePtr == NULL)\n" + - " { UNITY_TEST_ASSERT_NULL(MyMyTypePtr, cmock_line, NULL); }\n" + + " { UNITY_TEST_ASSERT_NULL(MyMyTypePtr, cmock_line, \"Expected NULL. Function 'Pear' called with unexpected value for argument 'MyMyTypePtr'.\"); }\n" + " else if (cmock_call_instance->Expected_MyMyTypePtr_Depth == 0)\n" + - " { UNITY_TEST_ASSERT_EQUAL_HEX32(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_line, NULL); }\n" + + " { UNITY_TEST_ASSERT_EQUAL_HEX32(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyTypePtr'.\"); }\n" + " else\n" + - " { UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_call_instance->Expected_MyMyTypePtr_Depth, cmock_line, NULL); }\n" + " { UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_call_instance->Expected_MyMyTypePtr_Depth, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyTypePtr'.\"); }\n" @unity_helper.expect.get_helper('MY_TYPE*').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY','']) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) end @@ -281,7 +281,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase should 'handle custom types with array handlers when array plugin is enabled for non-array types' do function = { :name => 'Pear' } arg = test_arg[:mytype] - expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, NULL);\n" + expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n" @unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY','&']) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) end