diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index b221663537b48126c9af63a6b64494651dd481f6..8625670e38a41fece3f57694716b0d566a19f2bb 100644 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -9,7 +9,7 @@ File.expand_path(File.join(File.dirname(__FILE__),'colour_prompt')) class UnityTestRunnerGenerator def initialize(options = nil) - @options = { :includes => [], :framework => :unity } + @options = { :includes => [], :plugins => [], :framework => :unity } case(options) when NilClass then @options when String then @options.merge!(UnityTestRunnerGenerator.grab_config(options)) @@ -19,16 +19,12 @@ class UnityTestRunnerGenerator end def self.grab_config(config_file) - options = { :includes => [], :framework => :unity } + options = { :includes => [], :plugins => [], :framework => :unity } unless (config_file.nil? or config_file.empty?) require 'yaml' yaml_guts = YAML.load_file(config_file) - yaml_goodness = yaml_guts[:unity] ? yaml_guts[:unity] : yaml_guts[:cmock] - raise "No :unity or :cmock section found in #{config_file}" unless yaml_goodness - options[:cexception] = 1 unless (yaml_goodness[:plugins] & ['cexception', :cexception]).empty? - options[:order] = 1 if (yaml_goodness[:enforce_strict_ordering]) - options[:framework] = (yaml_goodness[:framework] || :unity) - options[:includes] << (yaml_goodness[:includes]) + options.merge!(yaml_guts[:unity] ? yaml_guts[:unity] : yaml_guts[:cmock]) + raise "No :unity or :cmock section found in #{config_file}" unless options end return(options) end @@ -38,7 +34,7 @@ class UnityTestRunnerGenerator includes = [] used_mocks = [] - @options = options unless options.nil? + @options.merge!(options) unless options.nil? module_name = File.basename(input_file) #pull required data from source file @@ -47,8 +43,6 @@ class UnityTestRunnerGenerator includes = find_includes(input) used_mocks = find_mocks(includes) end - - puts "Creating test runner for #{module_name}..." #build runner file File.open(output_file, 'w') do |output| @@ -126,13 +120,13 @@ class UnityTestRunnerGenerator end output.puts('#include ') output.puts('#include ') - output.puts('#include "CException.h"') if @options[:cexception] + output.puts('#include "CException.h"') if @options[:plugins].include?(:cexception) mocks.each do |mock| output.puts("#include \"#{mock.gsub('.h','')}.h\"") end output.puts('') output.puts('char MessageBuffer[50];') - if @options[:order] + if @options[:enforce_strict_ordering] output.puts('int GlobalExpectCount;') output.puts('int GlobalVerifyOrder;') output.puts('char* GlobalOrderError;') @@ -156,7 +150,7 @@ class UnityTestRunnerGenerator unless (mocks.empty?) output.puts("static void CMock_Init(void)") output.puts("{") - if @options[:order] + if @options[:enforce_strict_ordering] output.puts(" GlobalExpectCount = 0;") output.puts(" GlobalVerifyOrder = 0;") output.puts(" GlobalOrderError = NULL;") @@ -198,17 +192,18 @@ class UnityTestRunnerGenerator end def create_runtest(output, used_mocks) + cexception = @options[:plugins].include? :cexception output.puts("static void runTest(UnityTestFunction test)") output.puts("{") output.puts(" if (TEST_PROTECT())") output.puts(" {") - output.puts(" CEXCEPTION_T e;") if @options[:cexception] - output.puts(" Try {") if @options[:cexception] + output.puts(" CEXCEPTION_T e;") if cexception + output.puts(" Try {") if cexception output.puts(" CMock_Init();") unless (used_mocks.empty?) output.puts(" setUp();") output.puts(" test();") output.puts(" CMock_Verify();") unless (used_mocks.empty?) - output.puts(" } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, \"Unhandled Exception!\"); }") if @options[:cexception] + output.puts(" } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, \"Unhandled Exception!\"); }") if cexception output.puts(" }") output.puts(" CMock_Destroy();") unless (used_mocks.empty?) output.puts(" if (TEST_PROTECT() && !TEST_IS_IGNORED)") @@ -250,30 +245,23 @@ end if ($0 == __FILE__) - usage = ["usage: ruby #{__FILE__} (yaml) (options) input_test_file output_test_runner (includes)", - " blah.yml - will use config options in the yml file (see CMock docs)", - " -cexception - include cexception support", - " -order - include cmock order-enforcement support" ] - options = { :includes => [] } yaml_file = nil #parse out all the options first ARGV.reject! do |arg| - if (arg =~ /\-(\w+)/) - options[$1.to_sym] = 1 - true - elsif (arg =~ /(\w+\.yml)/) - options = UnityTestRunnerGenerator.grab_config(arg) - true - else - false + case(arg) + when '-cexception': options[:plugins] = [:cexception]; true + when /\w+\.yml/: options = UnityTestRunnerGenerator.grab_config(arg); true + else false end end #make sure there is at least one parameter left (the input file) if !ARGV[0] - puts usage + puts ["usage: ruby #{__FILE__} (yaml) (options) input_test_file output_test_runner (includes)", + " blah.yml - will use config options in the yml file (see CMock docs)", + " -cexception - include cexception support"].join("\n") exit 1 end diff --git a/rakefile.rb b/rakefile.rb index 5b9652515fec8dd9bab5d7ee1b8a28b1511046b9..ba8969e144baa92971d1847525ff41f6d931d21a 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -22,6 +22,11 @@ task :unit do run_tests get_unit_test_files end +Rake::TestTask.new(:scripts) do |t| + t.pattern = 'test/test_*.rb' + t.verbose = true +end + desc "Generate test summary" task :summary do report_summary diff --git a/rakefile_helper.rb b/rakefile_helper.rb index 66f5088e7b0dd41283c3c6f647f57fc7d03008c0..bba32ddb0c9b35dcc77e8480e0d300422ad5ebcf 100644 --- a/rakefile_helper.rb +++ b/rakefile_helper.rb @@ -236,5 +236,4 @@ module RakefileHelpers end end - end diff --git a/test/expectdata/testsample_cmd.c b/test/expectdata/testsample_cmd.c new file mode 100644 index 0000000000000000000000000000000000000000..c8da7471a5a0649f9634ae731d54b44b929a9c4e --- /dev/null +++ b/test/expectdata/testsample_cmd.c @@ -0,0 +1,47 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include +#include +#include "CException.h" + +char MessageBuffer[50]; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + CEXCEPTION_T e; + Try { + setUp(); + test(); + } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } + } + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + tearDown(); + setUp(); +} + + +int main(void) +{ + Unity.TestFile = "test/testdata/testsample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return (UnityEnd()); +} diff --git a/test/expectdata/testsample_def.c b/test/expectdata/testsample_def.c new file mode 100644 index 0000000000000000000000000000000000000000..de46febd06da52b1f3f049497da6a1173c58b3b8 --- /dev/null +++ b/test/expectdata/testsample_def.c @@ -0,0 +1,43 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include +#include + +char MessageBuffer[50]; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + setUp(); + test(); + } + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + tearDown(); + setUp(); +} + + +int main(void) +{ + Unity.TestFile = "test/testdata/testsample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return (UnityEnd()); +} diff --git a/test/expectdata/testsample_mock_cmd.c b/test/expectdata/testsample_mock_cmd.c new file mode 100644 index 0000000000000000000000000000000000000000..125ccbbc59fdbb5ef24e1882eaae4c325f90f803 --- /dev/null +++ b/test/expectdata/testsample_mock_cmd.c @@ -0,0 +1,67 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include "cmock.h" +#include +#include +#include "CException.h" +#include "Mockstanky.h" + +char MessageBuffer[50]; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static void CMock_Init(void) +{ + Mockstanky_Init(); +} +static void CMock_Verify(void) +{ + Mockstanky_Verify(); +} +static void CMock_Destroy(void) +{ + Mockstanky_Destroy(); +} +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + CEXCEPTION_T e; + Try { + CMock_Init(); + setUp(); + test(); + CMock_Verify(); + } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } + } + CMock_Destroy(); + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + CMock_Verify(); + CMock_Destroy(); + tearDown(); + CMock_Init(); + setUp(); +} + + +int main(void) +{ + Unity.TestFile = "test/testdata/mocksample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return (UnityEnd()); +} diff --git a/test/expectdata/testsample_mock_def.c b/test/expectdata/testsample_mock_def.c new file mode 100644 index 0000000000000000000000000000000000000000..9b60a4835bf2852326e71ba26fafcf692752ff1f --- /dev/null +++ b/test/expectdata/testsample_mock_def.c @@ -0,0 +1,63 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include "cmock.h" +#include +#include +#include "Mockstanky.h" + +char MessageBuffer[50]; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static void CMock_Init(void) +{ + Mockstanky_Init(); +} +static void CMock_Verify(void) +{ + Mockstanky_Verify(); +} +static void CMock_Destroy(void) +{ + Mockstanky_Destroy(); +} +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + CMock_Init(); + setUp(); + test(); + CMock_Verify(); + } + CMock_Destroy(); + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + CMock_Verify(); + CMock_Destroy(); + tearDown(); + CMock_Init(); + setUp(); +} + + +int main(void) +{ + Unity.TestFile = "test/testdata/mocksample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return (UnityEnd()); +} diff --git a/test/expectdata/testsample_mock_new1.c b/test/expectdata/testsample_mock_new1.c new file mode 100644 index 0000000000000000000000000000000000000000..415da5935d463385a3f992cdbdbe2c980693a256 --- /dev/null +++ b/test/expectdata/testsample_mock_new1.c @@ -0,0 +1,75 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include "cmock.h" +#include "one.h" +#include "two.h" +#include +#include +#include "CException.h" +#include "Mockstanky.h" + +char MessageBuffer[50]; +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; + Mockstanky_Init(); +} +static void CMock_Verify(void) +{ + Mockstanky_Verify(); +} +static void CMock_Destroy(void) +{ + Mockstanky_Destroy(); +} +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + CEXCEPTION_T e; + Try { + CMock_Init(); + setUp(); + test(); + CMock_Verify(); + } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } + } + CMock_Destroy(); + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + CMock_Verify(); + CMock_Destroy(); + tearDown(); + CMock_Init(); + setUp(); +} + + +int main(void) +{ + Unity.TestFile = "test/testdata/mocksample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return (UnityEnd()); +} diff --git a/test/expectdata/testsample_mock_new2.c b/test/expectdata/testsample_mock_new2.c new file mode 100644 index 0000000000000000000000000000000000000000..0822ade9482250ca7d655910fa42124ae7e489cd --- /dev/null +++ b/test/expectdata/testsample_mock_new2.c @@ -0,0 +1,72 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include "cmock.h" +#include +#include +#include "Mockstanky.h" + +char MessageBuffer[50]; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static void CMock_Init(void) +{ + Mockstanky_Init(); +} +static void CMock_Verify(void) +{ + Mockstanky_Verify(); +} +static void CMock_Destroy(void) +{ + Mockstanky_Destroy(); +} +static int suite_setup(void) +{ +a_custom_setup(); +} +static int suite_teardown(int num_failures) +{ +a_custom_teardown(); +} +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + CMock_Init(); + setUp(); + test(); + CMock_Verify(); + } + CMock_Destroy(); + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + CMock_Verify(); + CMock_Destroy(); + tearDown(); + CMock_Init(); + setUp(); +} + + +int main(void) +{ + suite_setup(); + Unity.TestFile = "test/testdata/mocksample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return suite_teardown(UnityEnd()); +} diff --git a/test/expectdata/testsample_mock_run1.c b/test/expectdata/testsample_mock_run1.c new file mode 100644 index 0000000000000000000000000000000000000000..415da5935d463385a3f992cdbdbe2c980693a256 --- /dev/null +++ b/test/expectdata/testsample_mock_run1.c @@ -0,0 +1,75 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include "cmock.h" +#include "one.h" +#include "two.h" +#include +#include +#include "CException.h" +#include "Mockstanky.h" + +char MessageBuffer[50]; +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static void CMock_Init(void) +{ + GlobalExpectCount = 0; + GlobalVerifyOrder = 0; + GlobalOrderError = NULL; + Mockstanky_Init(); +} +static void CMock_Verify(void) +{ + Mockstanky_Verify(); +} +static void CMock_Destroy(void) +{ + Mockstanky_Destroy(); +} +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + CEXCEPTION_T e; + Try { + CMock_Init(); + setUp(); + test(); + CMock_Verify(); + } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } + } + CMock_Destroy(); + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + CMock_Verify(); + CMock_Destroy(); + tearDown(); + CMock_Init(); + setUp(); +} + + +int main(void) +{ + Unity.TestFile = "test/testdata/mocksample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return (UnityEnd()); +} diff --git a/test/expectdata/testsample_mock_run2.c b/test/expectdata/testsample_mock_run2.c new file mode 100644 index 0000000000000000000000000000000000000000..0822ade9482250ca7d655910fa42124ae7e489cd --- /dev/null +++ b/test/expectdata/testsample_mock_run2.c @@ -0,0 +1,72 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include "cmock.h" +#include +#include +#include "Mockstanky.h" + +char MessageBuffer[50]; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static void CMock_Init(void) +{ + Mockstanky_Init(); +} +static void CMock_Verify(void) +{ + Mockstanky_Verify(); +} +static void CMock_Destroy(void) +{ + Mockstanky_Destroy(); +} +static int suite_setup(void) +{ +a_custom_setup(); +} +static int suite_teardown(int num_failures) +{ +a_custom_teardown(); +} +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + CMock_Init(); + setUp(); + test(); + CMock_Verify(); + } + CMock_Destroy(); + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + CMock_Verify(); + CMock_Destroy(); + tearDown(); + CMock_Init(); + setUp(); +} + + +int main(void) +{ + suite_setup(); + Unity.TestFile = "test/testdata/mocksample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return suite_teardown(UnityEnd()); +} diff --git a/test/expectdata/testsample_mock_yaml.c b/test/expectdata/testsample_mock_yaml.c new file mode 100644 index 0000000000000000000000000000000000000000..30e7744bb1a578e15632d0b4fa5a435435bd4b04 --- /dev/null +++ b/test/expectdata/testsample_mock_yaml.c @@ -0,0 +1,68 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include "cmock.h" +#include +#include +#include "Mockstanky.h" + +char MessageBuffer[50]; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static void CMock_Init(void) +{ + Mockstanky_Init(); +} +static void CMock_Verify(void) +{ + Mockstanky_Verify(); +} +static void CMock_Destroy(void) +{ + Mockstanky_Destroy(); +} +static int suite_setup(void) +{ +a_yaml_setup(); +} +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + CMock_Init(); + setUp(); + test(); + CMock_Verify(); + } + CMock_Destroy(); + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + CMock_Verify(); + CMock_Destroy(); + tearDown(); + CMock_Init(); + setUp(); +} + + +int main(void) +{ + suite_setup(); + Unity.TestFile = "test/testdata/mocksample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return (UnityEnd()); +} diff --git a/test/expectdata/testsample_new1.c b/test/expectdata/testsample_new1.c new file mode 100644 index 0000000000000000000000000000000000000000..3aa48c9c4844474b83b475d0f367f0bc2a041e89 --- /dev/null +++ b/test/expectdata/testsample_new1.c @@ -0,0 +1,52 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include "one.h" +#include "two.h" +#include +#include +#include "CException.h" + +char MessageBuffer[50]; +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + CEXCEPTION_T e; + Try { + setUp(); + test(); + } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } + } + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + tearDown(); + setUp(); +} + + +int main(void) +{ + Unity.TestFile = "test/testdata/testsample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return (UnityEnd()); +} diff --git a/test/expectdata/testsample_new2.c b/test/expectdata/testsample_new2.c new file mode 100644 index 0000000000000000000000000000000000000000..295bf88a0dc617c9a735b31569b84b5debb6d239 --- /dev/null +++ b/test/expectdata/testsample_new2.c @@ -0,0 +1,52 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include +#include + +char MessageBuffer[50]; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static int suite_setup(void) +{ +a_custom_setup(); +} +static int suite_teardown(int num_failures) +{ +a_custom_teardown(); +} +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + setUp(); + test(); + } + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + tearDown(); + setUp(); +} + + +int main(void) +{ + suite_setup(); + Unity.TestFile = "test/testdata/testsample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return suite_teardown(UnityEnd()); +} diff --git a/test/expectdata/testsample_run1.c b/test/expectdata/testsample_run1.c new file mode 100644 index 0000000000000000000000000000000000000000..3aa48c9c4844474b83b475d0f367f0bc2a041e89 --- /dev/null +++ b/test/expectdata/testsample_run1.c @@ -0,0 +1,52 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include "one.h" +#include "two.h" +#include +#include +#include "CException.h" + +char MessageBuffer[50]; +int GlobalExpectCount; +int GlobalVerifyOrder; +char* GlobalOrderError; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + CEXCEPTION_T e; + Try { + setUp(); + test(); + } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } + } + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + tearDown(); + setUp(); +} + + +int main(void) +{ + Unity.TestFile = "test/testdata/testsample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return (UnityEnd()); +} diff --git a/test/expectdata/testsample_run2.c b/test/expectdata/testsample_run2.c new file mode 100644 index 0000000000000000000000000000000000000000..295bf88a0dc617c9a735b31569b84b5debb6d239 --- /dev/null +++ b/test/expectdata/testsample_run2.c @@ -0,0 +1,52 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include +#include + +char MessageBuffer[50]; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static int suite_setup(void) +{ +a_custom_setup(); +} +static int suite_teardown(int num_failures) +{ +a_custom_teardown(); +} +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + setUp(); + test(); + } + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + tearDown(); + setUp(); +} + + +int main(void) +{ + suite_setup(); + Unity.TestFile = "test/testdata/testsample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return suite_teardown(UnityEnd()); +} diff --git a/test/expectdata/testsample_yaml.c b/test/expectdata/testsample_yaml.c new file mode 100644 index 0000000000000000000000000000000000000000..76d5c9469ed835768f65a70849c55049020869af --- /dev/null +++ b/test/expectdata/testsample_yaml.c @@ -0,0 +1,48 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ +#include "unity.h" +#include +#include + +char MessageBuffer[50]; + +extern void setUp(void); +extern void tearDown(void); + +extern void test_TheFirstThingToTest(void); +extern void test_TheSecondThingToTest(void); + +static int suite_setup(void) +{ +a_yaml_setup(); +} +static void runTest(UnityTestFunction test) +{ + if (TEST_PROTECT()) + { + setUp(); + test(); + } + if (TEST_PROTECT() && !TEST_IS_IGNORED) + { + tearDown(); + } +} +void resetTest() +{ + tearDown(); + setUp(); +} + + +int main(void) +{ + suite_setup(); + Unity.TestFile = "test/testdata/testsample.c"; + UnityBegin(); + + // RUN_TEST calls runTest + RUN_TEST(test_TheFirstThingToTest, 21); + RUN_TEST(test_TheSecondThingToTest, 43); + + return (UnityEnd()); +} diff --git a/test/test_generate_test_runner.rb b/test/test_generate_test_runner.rb new file mode 100644 index 0000000000000000000000000000000000000000..71ac58975777c228e4cd4c2af2e2169b8d3ba2b4 --- /dev/null +++ b/test/test_generate_test_runner.rb @@ -0,0 +1,82 @@ +# ========================================== +# 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] +# ========================================== + +ruby_version = RUBY_VERSION.split('.') +if (ruby_version[1].to_i == 9) and (ruby_version[2].to_i > 1) + require 'gems' + gem 'test-unit' +end +require 'test/unit' +require 'auto/generate_test_runner.rb' + +TEST_FILE = 'test/testdata/testsample.c' +TEST_MOCK = 'test/testdata/mocksample.c' +OUT_FILE = 'build/testsample_' +EXP_FILE = 'test/expectdata/testsample_' + +class TestGenerateTestRunner < Test::Unit::TestCase + def setup + end + + def teardown + end + + def verify_output_equal(subtest) + expected = File.read(EXP_FILE + subtest + '.c').gsub(/\r\n/,"\n") + actual = File.read(OUT_FILE + subtest + '.c').gsub(/\r\n/,"\n") + assert_equal(expected, actual, "Generated File Sub-Test '#{subtest}' Failed") + end + + def test_ShouldGenerateARunnerByCreatingRunnerWithOptions + sets = { 'def' => nil, + 'new1' => { :plugins => [:cexception], :includes => ['one.h', 'two.h'], :enforce_strict_ordering => true }, + 'new2' => { :plugins => [:ignore], :suite_setup => "a_custom_setup();", :suite_teardown => "a_custom_teardown();" } + } + + sets.each_pair do |subtest, options| + UnityTestRunnerGenerator.new(options).run(TEST_FILE, OUT_FILE + subtest + '.c') + verify_output_equal(subtest) + UnityTestRunnerGenerator.new(options).run(TEST_MOCK, OUT_FILE + 'mock_' + subtest + '.c') + verify_output_equal('mock_' + subtest) + end + end + + def test_ShouldGenerateARunnerByRunningRunnerWithOptions + sets = { 'run1' => { :plugins => [:cexception], :includes => ['one.h', 'two.h'], :enforce_strict_ordering => true }, + 'run2' => { :plugins => [:ignore], :suite_setup => "a_custom_setup();", :suite_teardown => "a_custom_teardown();" } + } + + sets.each_pair do |subtest, options| + UnityTestRunnerGenerator.new.run(TEST_FILE, OUT_FILE + subtest + '.c', options) + verify_output_equal(subtest) + UnityTestRunnerGenerator.new.run(TEST_MOCK, OUT_FILE + 'mock_' + subtest + '.c', options) + verify_output_equal('mock_' + subtest) + end + end + + def test_ShouldGenerateARunnerByPullingYamlOptions + subtest = 'yaml' + cmdstr = "ruby auto/generate_test_runner.rb test/testdata/sample.yml \"#{TEST_FILE}\" \"#{OUT_FILE + subtest + '.c'}\"" + `#{cmdstr}` + verify_output_equal(subtest) + + cmdstr = "ruby auto/generate_test_runner.rb test/testdata/sample.yml \"#{TEST_MOCK}\" \"#{OUT_FILE + 'mock_' + subtest + '.c'}\"" + `#{cmdstr}` + verify_output_equal('mock_' + subtest) + end + + def test_ShouldGenerateARunnerByPullingCommandlineOptions + subtest = 'cmd' + cmdstr = "ruby auto/generate_test_runner.rb -cexception \"#{TEST_FILE}\" \"#{OUT_FILE + subtest + '.c'}\"" + `#{cmdstr}` + verify_output_equal(subtest) + + cmdstr = "ruby auto/generate_test_runner.rb -cexception \"#{TEST_MOCK}\" \"#{OUT_FILE + 'mock_' + subtest + '.c'}\"" + `#{cmdstr}` + verify_output_equal('mock_' + subtest) + end + +end diff --git a/test/testdata/mocksample.c b/test/testdata/mocksample.c new file mode 100644 index 0000000000000000000000000000000000000000..847d87f0d066c26246452acbee3aab629ed37272 --- /dev/null +++ b/test/testdata/mocksample.c @@ -0,0 +1,51 @@ +// This is just a sample test file to be used to test the generator script +#ifndef TEST_SAMPLE_H +#define TEST_SAMPLE_H + +#include +#include "unity.h" +#include "funky.h" +#include "Mockstanky.h" + +void setUp(void) +{ + CustomSetupStuff(); +} + +void tearDown(void) +{ + CustomTeardownStuff +} + +//Yup, nice comment +void test_TheFirstThingToTest(void) +{ + TEST_ASSERT(1); + + TEST_ASSERT_TRUE(1); +} + +/* +void test_ShouldBeIgnored(void) +{ + DoesStuff(); +} +*/ + +//void test_ShouldAlsoNotBeTested(void) +//{ +// Call_An_Expect(); +// +// CallAFunction(); +// test_CallAFunctionThatLooksLikeATest(); +//} + +void test_TheSecondThingToTest(void) +{ + Call_An_Expect(); + + CallAFunction(); + test_CallAFunctionThatLooksLikeATest(); +} + +#endif //TEST_SAMPLE_H diff --git a/test/testdata/sample.yml b/test/testdata/sample.yml new file mode 100644 index 0000000000000000000000000000000000000000..567972d101a63c776713efb6c24908e76b222d7d --- /dev/null +++ b/test/testdata/sample.yml @@ -0,0 +1,8 @@ +:unity: + :includes + - two.h + - three.h + :plugins: + - :cexception + :suite_setup: | + a_yaml_setup(); \ No newline at end of file diff --git a/test/testdata/testsample.c b/test/testdata/testsample.c new file mode 100644 index 0000000000000000000000000000000000000000..e5a2b184be26c78fd1e0bcb6d839f4c687c9e7dd --- /dev/null +++ b/test/testdata/testsample.c @@ -0,0 +1,51 @@ +// This is just a sample test file to be used to test the generator script +#ifndef TEST_SAMPLE_H +#define TEST_SAMPLE_H + +#include +#include "unity.h" +#include "funky.h" +#include "stanky.h" + +void setUp(void) +{ + CustomSetupStuff(); +} + +void tearDown(void) +{ + CustomTeardownStuff +} + +//Yup, nice comment +void test_TheFirstThingToTest(void) +{ + TEST_ASSERT(1); + + TEST_ASSERT_TRUE(1); +} + +/* +void test_ShouldBeIgnored(void) +{ + DoesStuff(); +} +*/ + +//void test_ShouldAlsoNotBeTested(void) +//{ +// Call_An_Expect(); +// +// CallAFunction(); +// test_CallAFunctionThatLooksLikeATest(); +//} + +void test_TheSecondThingToTest(void) +{ + Call_An_Expect(); + + CallAFunction(); + test_CallAFunctionThatLooksLikeATest(); +} + +#endif //TEST_SAMPLE_H