From 156879d750f6382453afe3f916f6f63df92beedb Mon Sep 17 00:00:00 2001 From: mkarlesky Date: Sun, 12 Apr 2009 03:46:55 +0000 Subject: [PATCH] few more basic system tests plus slightly better system test reporting git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@74 bf332499-1b4d-0410-844d-d2d48d5cc64c --- rakefile.rb | 2 +- rakefile_helper.rb | 14 +++-- test/system/cases/expect_and_return.yml | 84 +++++++++++++++++++++++++ test/system/cases/ignore_and_return.yml | 66 +++++++++++++++++++ test/system/cases/simple.yml | 54 ---------------- 5 files changed, 161 insertions(+), 59 deletions(-) create mode 100644 test/system/cases/expect_and_return.yml create mode 100644 test/system/cases/ignore_and_return.yml delete mode 100644 test/system/cases/simple.yml diff --git a/rakefile.rb b/rakefile.rb index 74de92e..5261465 100644 --- a/rakefile.rb +++ b/rakefile.rb @@ -35,7 +35,7 @@ namespace :test do desc "Run system tests" task :system => [:clobber] do - report 'Running system tests' + report "\nRunning system tests..." tests_failed = run_systests(FileList['test/system/cases/*.yml']) raise "System tests failed." if (tests_failed > 0) diff --git a/rakefile_helper.rb b/rakefile_helper.rb index f550184..f8af082 100644 --- a/rakefile_helper.rb +++ b/rakefile_helper.rb @@ -181,10 +181,12 @@ module RakefileHelpers test_base = File.basename(test, C_EXTENSION) cmock_config = test_base.gsub(/test_/, '') + '_cmock.yml' + puts "Executing system test cases contained in #{File.basename(test)}..." + # Detect dependencies and build required required modules extract_headers(test).each do |header| - # Generate mock if a mock was included + # Generate any needed mocks if header =~ /^mock_(.*)\.h/i module_name = $1 cmock = CMock.new(SYSTEST_GENERATED_FILES_PATH + cmock_config) @@ -244,7 +246,8 @@ module RakefileHelpers # if they don't match, the system test has failed if (test[:pass] != !((test_results =~ /test#{index+1}::: PASS/).nil?)) total_failures += 1 - failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}" + test_results =~ /test#{index+1}:(.+)/ + failure_messages << "#{test_file}:test#{index+1}:should #{test[:should]}:#{$1}" end end end @@ -256,8 +259,11 @@ module RakefileHelpers puts "TOTAL TESTS: #{total_tests} TOTAL FAILURES: #{total_failures}\n" puts "\n" - failure_messages.each do |failure| - puts failure + if (failure_messages.size > 0) + puts 'System test failures:' + failure_messages.each do |failure| + puts failure + end end puts '' diff --git a/test/system/cases/expect_and_return.yml b/test/system/cases/expect_and_return.yml new file mode 100644 index 0000000..1d7fc3b --- /dev/null +++ b/test/system/cases/expect_and_return.yml @@ -0,0 +1,84 @@ +--- +:cmock: + :plugins: + - # none + +:systest: + :types: | + #define UINT32 unsigned int + + typedef signed int custom_type; + + :mockable: | + UINT32 foo(custom_type a); + UINT32 bar(custom_type b); + UINT32 foo_varargs(custom_type a, ...); + + :source: + :header: | + UINT32 function_a(int a, int b); + void function_b(void); + UINT32 function_c(int a); + :code: | + UINT32 function_a(int a, int b) + { + return foo((custom_type)a) + bar((custom_type)b); + } + + void function_b(void) { } + + UINT32 function_c(int a) + { + return foo_varargs((custom_type)a, "ignored", 5); + } + + :tests: + :common: | + void setUp(void) {} + void tearDown(void) {} + :units: + - :pass: TRUE + :should: 'successfully exercise two simple ExpectAndReturn mock calls' + :code: | + test() + { + foo_ExpectAndReturn((custom_type)1, 10); + bar_ExpectAndReturn((custom_type)2, 20); + TEST_ASSERT_EQUAL(30, function_a(1, 2)); + } + + - :pass: FALSE + :should: 'fail because bar() is called but not expected' + :code: | + test() + { + foo_ExpectAndReturn((custom_type)1, 10); + TEST_ASSERT_EQUAL(30, function_a(1, 2)); + } + + - :pass: FALSE + :should: 'fail because bar() is not called but is expected' + :code: | + test() + { + bar_ExpectAndReturn((custom_type)1, 10); + function_b(); + } + + - :pass: TRUE + :should: 'consume varargs passed to mocked function' + :code: | + test() + { + foo_varargs_ExpectAndReturn((custom_type)3, 10); + TEST_ASSERT_EQUAL(10, function_c(3)); + } + +... + + # :unity_helper: + # :header: | + # // header stuff + # :code: + # // code stuff + # \ No newline at end of file diff --git a/test/system/cases/ignore_and_return.yml b/test/system/cases/ignore_and_return.yml new file mode 100644 index 0000000..a97f3a1 --- /dev/null +++ b/test/system/cases/ignore_and_return.yml @@ -0,0 +1,66 @@ +--- +:cmock: + :plugins: + - 'ignore' + +:systest: + :types: | + + :mockable: | + int foo(int a); + void bar(int b); + + :source: + :header: | + int function(int a, int b); + :code: | + int function(int a, int b) + { + bar(b); + return foo(a) + foo(b); + } + + :tests: + :common: | + void setUp(void) {} + void tearDown(void) {} + :units: + - :pass: TRUE + :should: 'successfully exercise simple ExpectAndReturn mock calls' + :code: | + test() + { + bar_Expect(2); + foo_ExpectAndReturn(1, 10); + foo_ExpectAndReturn(2, 20); + TEST_ASSERT_EQUAL(30, function(1, 2)); + } + + - :pass: TRUE + :should: 'ignore foo() calls' + :code: | + test() + { + bar_Expect(4); + foo_IgnoreAndReturn(10); + TEST_ASSERT_EQUAL(20, function(3, 4)); + } + + - :pass: TRUE + :should: 'ignore bar() and foo() calls' + :code: | + test() + { + bar_Ignore(); + foo_IgnoreAndReturn(50); + TEST_ASSERT_EQUAL(100, function(0, 0)); + } + +... + + # :unity_helper: + # :header: | + # // header stuff + # :code: + # // code stuff + # \ No newline at end of file diff --git a/test/system/cases/simple.yml b/test/system/cases/simple.yml deleted file mode 100644 index aca8987..0000000 --- a/test/system/cases/simple.yml +++ /dev/null @@ -1,54 +0,0 @@ ---- -:cmock: - :plugins: - - 'ignore' - -:systest: - :types: | - #define UINT32 unsigned int - - typedef signed int custom_type; - - :mockable: | - UINT32 foo(custom_type a); - UINT32 bar(custom_type b); - - :source: - :header: | - unsigned int foobar(int a, int b); - :code: | - unsigned int foobar(int a, int b) - { - return foo((custom_type)a) + bar((custom_type)b); - } - - :tests: - :common: | - void setUp(void) {} - void tearDown(void) {} - :units: - - :pass: TRUE - :should: 'exercise two simple ExpectAndReturn mock calls' - :code: | - test() - { - foo_ExpectAndReturn((custom_type)1, 10); - bar_ExpectAndReturn((custom_type)2, 20); - TEST_ASSERT_EQUAL(30, foobar(1, 2)); - } - - - :pass: FALSE - :should: 'fail because bar() is called but not expected' - :code: | - test() - { - foo_ExpectAndReturn((custom_type)1, 10); - TEST_ASSERT_EQUAL(30, foobar(1, 2)); - } - - # :unity_helper: - # :header: | - # // header stuff - # :code: - # // code stuff - # \ No newline at end of file