mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-10-14 12:57:26 +00:00
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
This commit is contained in:
+1
-1
@@ -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)
|
||||
|
||||
+10
-4
@@ -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 ''
|
||||
|
||||
@@ -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
|
||||
#
|
||||
@@ -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
|
||||
#
|
||||
@@ -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
|
||||
#
|
||||
Reference in New Issue
Block a user