From 3093a440dd7e360ee8d18ae3cbf52cde6120f9a7 Mon Sep 17 00:00:00 2001 From: John Lindgren Date: Thu, 5 Dec 2019 16:34:49 -0500 Subject: [PATCH] expect: Optimize mock_verify() for the successful case. Remove unconditional UNITY_SET_DETAIL/UNITY_CLEAR_DETAILS pair and only call UNITY_SET_DETAIL if we are failing. --- lib/cmock_generator_plugin_expect.rb | 9 +++++---- test/unit/cmock_generator_plugin_expect_a_test.rb | 8 +++++--- test/unit/cmock_generator_plugin_expect_b_test.rb | 9 +++++---- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/cmock_generator_plugin_expect.rb b/lib/cmock_generator_plugin_expect.rb index dcf96f2..44bb98b 100644 --- a/lib/cmock_generator_plugin_expect.rb +++ b/lib/cmock_generator_plugin_expect.rb @@ -95,9 +95,10 @@ class CMockGeneratorPluginExpect end def mock_verify(function) - " UNITY_SET_DETAIL(CMockString_#{function[:name]});\n" + - " UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == call_instance, cmock_line, CMockStringCalledLess);\n" + - " UNITY_CLR_DETAILS();\n" + " if (CMOCK_GUTS_NONE != call_instance)\n" \ + " {\n" \ + " UNITY_SET_DETAIL(CMockString_#{function[:name]});\n" \ + " UNITY_TEST_FAIL(cmock_line, CMockStringCalledLess);\n" \ + " }\n" end - end diff --git a/test/unit/cmock_generator_plugin_expect_a_test.rb b/test/unit/cmock_generator_plugin_expect_a_test.rb index 3b4dfe6..dd86689 100644 --- a/test/unit/cmock_generator_plugin_expect_a_test.rb +++ b/test/unit/cmock_generator_plugin_expect_a_test.rb @@ -174,9 +174,11 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module W it "add mock verify lines" do function = {:name => "Banana" } - expected = " UNITY_SET_DETAIL(CMockString_Banana);\n" + - " UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == call_instance, cmock_line, CMockStringCalledLess);\n" + - " UNITY_CLR_DETAILS();\n" + expected = " if (CMOCK_GUTS_NONE != call_instance)\n" \ + " {\n" \ + " UNITY_SET_DETAIL(CMockString_Banana);\n" \ + " UNITY_TEST_FAIL(cmock_line, CMockStringCalledLess);\n" \ + " }\n" returned = @cmock_generator_plugin_expect.mock_verify(function) assert_equal(expected, returned) end diff --git a/test/unit/cmock_generator_plugin_expect_b_test.rb b/test/unit/cmock_generator_plugin_expect_b_test.rb index e6e49b0..35d4871 100644 --- a/test/unit/cmock_generator_plugin_expect_b_test.rb +++ b/test/unit/cmock_generator_plugin_expect_b_test.rb @@ -190,11 +190,12 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w it "add mock verify lines" do function = {:name => "Banana" } - expected = " UNITY_SET_DETAIL(CMockString_Banana);\n" + - " UNITY_TEST_ASSERT(CMOCK_GUTS_NONE == call_instance, cmock_line, CMockStringCalledLess);\n" + - " UNITY_CLR_DETAILS();\n" + expected = " if (CMOCK_GUTS_NONE != call_instance)\n" \ + " {\n" \ + " UNITY_SET_DETAIL(CMockString_Banana);\n" \ + " UNITY_TEST_FAIL(cmock_line, CMockStringCalledLess);\n" \ + " }\n" returned = @cmock_generator_plugin_expect.mock_verify(function) assert_equal(expected, returned) end - end