From a604fb71a47259d0392d100c5b5925445bd49f6e Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 30 Aug 2017 10:28:53 -0400 Subject: [PATCH 1/5] Remove dead code (unity_msg is not used since 647876644b46). --- lib/cmock_generator_utils.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/cmock_generator_utils.rb b/lib/cmock_generator_utils.rb index 86729b6..fde3338 100644 --- a/lib/cmock_generator_utils.rb +++ b/lib/cmock_generator_utils.rb @@ -112,12 +112,11 @@ 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}'." - return c_type, arg_name, expected, ignore, unity_func[0], unity_func[1], unity_msg + return c_type, arg_name, expected, ignore, unity_func[0], unity_func[1] end def code_verify_an_arg_expectation_with_no_arrays(function, arg) - c_type, arg_name, expected, ignore, unity_func, pre, unity_msg = lookup_expect_type(function, arg) + c_type, arg_name, expected, ignore, unity_func, pre = lookup_expect_type(function, arg) lines = "" lines << " if (!#{ignore})\n" if @ignore_arg lines << " {\n" @@ -152,7 +151,7 @@ class CMockGeneratorUtils end def code_verify_an_arg_expectation_with_normal_arrays(function, arg) - c_type, arg_name, expected, ignore, unity_func, pre, unity_msg = lookup_expect_type(function, arg) + c_type, arg_name, expected, ignore, unity_func, pre = lookup_expect_type(function, arg) depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1 lines = "" lines << " if (!#{ignore})\n" if @ignore_arg @@ -188,7 +187,7 @@ class CMockGeneratorUtils end def code_verify_an_arg_expectation_with_smart_arrays(function, arg) - c_type, arg_name, expected, ignore, unity_func, pre, unity_msg = lookup_expect_type(function, arg) + c_type, arg_name, expected, ignore, unity_func, pre = lookup_expect_type(function, arg) depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1 lines = "" lines << " if (!#{ignore})\n" if @ignore_arg From 53d6a7c0e4a907251e7857ba888bc60f83fcf6e0 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 30 Aug 2017 15:49:14 -0400 Subject: [PATCH 2/5] Remove a commented-out function (it confuses yard otherwise). --- lib/cmock_generator_plugin_expect_any_args.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/lib/cmock_generator_plugin_expect_any_args.rb b/lib/cmock_generator_plugin_expect_any_args.rb index 31752ba..0e80844 100644 --- a/lib/cmock_generator_plugin_expect_any_args.rb +++ b/lib/cmock_generator_plugin_expect_any_args.rb @@ -28,7 +28,6 @@ class CMockGeneratorPluginExpectAnyArgs end def mock_function_declarations(function) - if (function[:return][:void?]) return "#define #{function[:name]}_ExpectAnyArgs() #{function[:name]}_CMockExpectAnyArgs(__LINE__)\n" + "void #{function[:name]}_CMockExpectAnyArgs(UNITY_LINE_TYPE cmock_line);\n" @@ -38,19 +37,6 @@ class CMockGeneratorPluginExpectAnyArgs end end - # def mock_implementation(function) - # lines = " if (cmock_call_instance->IgnoreMode == CMOCK_ARG_NONE)\n {\n" - # if (function[:return][:void?]) - # lines << " return;\n }\n" - # else - # retval = function[:return].merge( { :name => "cmock_call_instance->ReturnVal"} ) - # lines << " " + @utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval) unless (retval[:void?]) - # return_type = function[:return][:const?] ? "(const #{function[:return][:type]})" : ((function[:return][:type] =~ /cmock/) ? "(#{function[:return][:type]})" : '') - # lines << " return #{return_type}cmock_call_instance->ReturnVal;\n }\n" - # end - # lines - # end - def mock_interfaces(function) lines = "" if (function[:return][:void?]) From 9e69cfb9b11b73b3f6a0b858357cd42ea5bc109e Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 30 Aug 2017 15:50:20 -0400 Subject: [PATCH 3/5] Remove an extra newline. --- lib/cmock_generator_plugin_expect.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cmock_generator_plugin_expect.rb b/lib/cmock_generator_plugin_expect.rb index 07079d3..19fb41b 100644 --- a/lib/cmock_generator_plugin_expect.rb +++ b/lib/cmock_generator_plugin_expect.rb @@ -68,7 +68,7 @@ class CMockGeneratorPluginExpect function[:args].each do |arg| lines << @utils.code_verify_an_arg_expectation(function, arg) end - lines << "\n }\n" + lines << " }\n" lines end From 846423768b0e81f1b1a163c8487c595001db60b6 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 30 Aug 2017 16:01:11 -0400 Subject: [PATCH 4/5] Fix whitespace checking in tests. --- .../cmock_generator_plugin_expect_b_test.rb | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/test/unit/cmock_generator_plugin_expect_b_test.rb b/test/unit/cmock_generator_plugin_expect_b_test.rb index f2b16c6..47b0c6f 100644 --- a/test/unit/cmock_generator_plugin_expect_b_test.rb +++ b/test/unit/cmock_generator_plugin_expect_b_test.rb @@ -96,11 +96,12 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w it "add mock function implementation for functions of style 'int func(int veal, unsigned int sushi)'" do function = {:name => "Cherry", :args => [ { :type => "int", :name => "veal" }, { :type => "unsigned int", :name => "sushi" } ], :return => test_return[:int]} - @utils.expect :code_verify_an_arg_expectation, " mocked_retval_1", [function, function[:args][0]] - @utils.expect :code_verify_an_arg_expectation, " mocked_retval_2", [function, function[:args][1]] + @utils.expect :code_verify_an_arg_expectation, "mocked_retval_1\n", [function, function[:args][0]] + @utils.expect :code_verify_an_arg_expectation, "mocked_retval_2\n", [function, function[:args][1]] expected = " if (cmock_call_instance->IgnoreMode != CMOCK_ARG_NONE)\n" + " {\n" + - " mocked_retval_1 mocked_retval_2\n" + + "mocked_retval_1\n" + + "mocked_retval_2\n" + " }\n" returned = @cmock_generator_plugin_expect.mock_implementation(function) assert_equal(expected, returned) @@ -116,7 +117,7 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w it "add mock function implementation for functions of style 'void func(int worm)' and strict ordering" do function = {:name => "Apple", :args => [{ :type => "int", :name => "worm" }], :return => test_return[:void]} - @utils.expect :code_verify_an_arg_expectation, "mocked_retval_0", [function, function[:args][0]] + @utils.expect :code_verify_an_arg_expectation, "mocked_retval_0\n", [function, function[:args][0]] expected = " if (cmock_call_instance->IgnoreMode != CMOCK_ARG_NONE)\n" + " {\n" + "mocked_retval_0\n" + @@ -128,12 +129,12 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w it "add mock interfaces for functions of style 'void func(void)'" do function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:void]} - @utils.expect :code_add_base_expectation, "mock_retval_0 ", ["Pear"] - @utils.expect :code_call_argument_loader, "mock_retval_1 ", [function] + @utils.expect :code_add_base_expectation, "mock_retval_0\n", ["Pear"] + @utils.expect :code_call_argument_loader, "mock_retval_1\n", [function] expected = ["void Pear_CMockExpect(UNITY_LINE_TYPE cmock_line)\n", "{\n", - "mock_retval_0 ", - "mock_retval_1 ", + "mock_retval_0\n", + "mock_retval_1\n", " UNITY_CLR_DETAILS();\n", "}\n\n" ].join @@ -143,14 +144,14 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w it "add mock interfaces for functions of style 'int func(void)'" do function = {:name => "Orange", :args => [], :args_string => "void", :return => test_return[:int]} - @utils.expect :code_add_base_expectation, "mock_retval_0 ", ["Orange"] - @utils.expect :code_call_argument_loader, "mock_retval_1 ", [function] - @utils.expect :code_assign_argument_quickly, "mock_retval_2", ["cmock_call_instance->ReturnVal", function[:return]] + @utils.expect :code_add_base_expectation, "mock_retval_0\n", ["Orange"] + @utils.expect :code_call_argument_loader, "mock_retval_1\n", [function] + @utils.expect :code_assign_argument_quickly, "mock_retval_2\n", ["cmock_call_instance->ReturnVal", function[:return]] expected = ["void Orange_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, int cmock_to_return)\n", "{\n", - "mock_retval_0 ", - "mock_retval_1 ", - "mock_retval_2", + "mock_retval_0\n", + "mock_retval_1\n", + "mock_retval_2\n", " UNITY_CLR_DETAILS();\n", "}\n\n" ].join @@ -160,14 +161,14 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w it "add mock interfaces for functions of style 'int func(char* pescado)'" do function = {:name => "Lemon", :args => [{ :type => "char*", :name => "pescado"}], :args_string => "char* pescado", :return => test_return[:int]} - @utils.expect :code_add_base_expectation, "mock_retval_0 ", ["Lemon"] - @utils.expect :code_call_argument_loader, "mock_retval_1 ", [function] - @utils.expect :code_assign_argument_quickly, "mock_retval_2", ["cmock_call_instance->ReturnVal", function[:return]] + @utils.expect :code_add_base_expectation, "mock_retval_0\n", ["Lemon"] + @utils.expect :code_call_argument_loader, "mock_retval_1\n", [function] + @utils.expect :code_assign_argument_quickly, "mock_retval_2\n", ["cmock_call_instance->ReturnVal", function[:return]] expected = ["void Lemon_CMockExpectAndReturn(UNITY_LINE_TYPE cmock_line, char* pescado, int cmock_to_return)\n", "{\n", - "mock_retval_0 ", - "mock_retval_1 ", - "mock_retval_2", + "mock_retval_0\n", + "mock_retval_1\n", + "mock_retval_2\n", " UNITY_CLR_DETAILS();\n", "}\n\n" ].join @@ -177,12 +178,12 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w it "add mock interfaces for functions when using ordering" do function = {:name => "Pear", :args => [], :args_string => "void", :return => test_return[:void]} - @utils.expect :code_add_base_expectation, "mock_retval_0 ", ["Pear"] - @utils.expect :code_call_argument_loader, "mock_retval_1 ", [function] + @utils.expect :code_add_base_expectation, "mock_retval_0\n", ["Pear"] + @utils.expect :code_call_argument_loader, "mock_retval_1\n", [function] expected = ["void Pear_CMockExpect(UNITY_LINE_TYPE cmock_line)\n", "{\n", - "mock_retval_0 ", - "mock_retval_1 ", + "mock_retval_0\n", + "mock_retval_1\n", " UNITY_CLR_DETAILS();\n", "}\n\n" ].join From 7eb7e14fbccd80f4c19afa177884adc5f86d2444 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Wed, 30 Aug 2017 16:03:45 -0400 Subject: [PATCH 5/5] Remove trailing whitespace. --- lib/cmock_plugin_manager.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cmock_plugin_manager.rb b/lib/cmock_plugin_manager.rb index eb8f9e8..8da6756 100644 --- a/lib/cmock_plugin_manager.rb +++ b/lib/cmock_plugin_manager.rb @@ -2,12 +2,12 @@ # CMock Project - Automatic Mock Generation for C # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams # [Released under MIT License. Please refer to license.txt for details] -# ========================================== +# ========================================== class CMockPluginManager attr_accessor :plugins - + def initialize(config, utils) @plugins = [] plugins_to_load = [:expect, config.plugins].flatten.uniq.compact @@ -25,7 +25,7 @@ class CMockPluginManager end @plugins.sort! {|a,b| a.priority <=> b.priority } end - + def run(method, args=nil) if args.nil? return @plugins.collect{ |plugin| plugin.send(method) if plugin.respond_to?(method) }.flatten.join @@ -33,7 +33,7 @@ class CMockPluginManager return @plugins.collect{ |plugin| plugin.send(method, args) if plugin.respond_to?(method) }.flatten.join end end - + def camelize(lower_case_and_underscored_word) lower_case_and_underscored_word.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } end