mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-06-24 00:28:35 +08:00
- added tests for generate_test_runner. other script tests to come
git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@97 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
@ -9,7 +9,7 @@ File.expand_path(File.join(File.dirname(__FILE__),'colour_prompt'))
|
|||||||
class UnityTestRunnerGenerator
|
class UnityTestRunnerGenerator
|
||||||
|
|
||||||
def initialize(options = nil)
|
def initialize(options = nil)
|
||||||
@options = { :includes => [], :framework => :unity }
|
@options = { :includes => [], :plugins => [], :framework => :unity }
|
||||||
case(options)
|
case(options)
|
||||||
when NilClass then @options
|
when NilClass then @options
|
||||||
when String then @options.merge!(UnityTestRunnerGenerator.grab_config(options))
|
when String then @options.merge!(UnityTestRunnerGenerator.grab_config(options))
|
||||||
@ -19,16 +19,12 @@ class UnityTestRunnerGenerator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.grab_config(config_file)
|
def self.grab_config(config_file)
|
||||||
options = { :includes => [], :framework => :unity }
|
options = { :includes => [], :plugins => [], :framework => :unity }
|
||||||
unless (config_file.nil? or config_file.empty?)
|
unless (config_file.nil? or config_file.empty?)
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
yaml_guts = YAML.load_file(config_file)
|
yaml_guts = YAML.load_file(config_file)
|
||||||
yaml_goodness = yaml_guts[:unity] ? yaml_guts[:unity] : yaml_guts[:cmock]
|
options.merge!(yaml_guts[:unity] ? yaml_guts[:unity] : yaml_guts[:cmock])
|
||||||
raise "No :unity or :cmock section found in #{config_file}" unless yaml_goodness
|
raise "No :unity or :cmock section found in #{config_file}" unless options
|
||||||
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])
|
|
||||||
end
|
end
|
||||||
return(options)
|
return(options)
|
||||||
end
|
end
|
||||||
@ -38,7 +34,7 @@ class UnityTestRunnerGenerator
|
|||||||
includes = []
|
includes = []
|
||||||
used_mocks = []
|
used_mocks = []
|
||||||
|
|
||||||
@options = options unless options.nil?
|
@options.merge!(options) unless options.nil?
|
||||||
module_name = File.basename(input_file)
|
module_name = File.basename(input_file)
|
||||||
|
|
||||||
#pull required data from source file
|
#pull required data from source file
|
||||||
@ -47,8 +43,6 @@ class UnityTestRunnerGenerator
|
|||||||
includes = find_includes(input)
|
includes = find_includes(input)
|
||||||
used_mocks = find_mocks(includes)
|
used_mocks = find_mocks(includes)
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "Creating test runner for #{module_name}..."
|
|
||||||
|
|
||||||
#build runner file
|
#build runner file
|
||||||
File.open(output_file, 'w') do |output|
|
File.open(output_file, 'w') do |output|
|
||||||
@ -126,13 +120,13 @@ class UnityTestRunnerGenerator
|
|||||||
end
|
end
|
||||||
output.puts('#include <setjmp.h>')
|
output.puts('#include <setjmp.h>')
|
||||||
output.puts('#include <stdio.h>')
|
output.puts('#include <stdio.h>')
|
||||||
output.puts('#include "CException.h"') if @options[:cexception]
|
output.puts('#include "CException.h"') if @options[:plugins].include?(:cexception)
|
||||||
mocks.each do |mock|
|
mocks.each do |mock|
|
||||||
output.puts("#include \"#{mock.gsub('.h','')}.h\"")
|
output.puts("#include \"#{mock.gsub('.h','')}.h\"")
|
||||||
end
|
end
|
||||||
output.puts('')
|
output.puts('')
|
||||||
output.puts('char MessageBuffer[50];')
|
output.puts('char MessageBuffer[50];')
|
||||||
if @options[:order]
|
if @options[:enforce_strict_ordering]
|
||||||
output.puts('int GlobalExpectCount;')
|
output.puts('int GlobalExpectCount;')
|
||||||
output.puts('int GlobalVerifyOrder;')
|
output.puts('int GlobalVerifyOrder;')
|
||||||
output.puts('char* GlobalOrderError;')
|
output.puts('char* GlobalOrderError;')
|
||||||
@ -156,7 +150,7 @@ class UnityTestRunnerGenerator
|
|||||||
unless (mocks.empty?)
|
unless (mocks.empty?)
|
||||||
output.puts("static void CMock_Init(void)")
|
output.puts("static void CMock_Init(void)")
|
||||||
output.puts("{")
|
output.puts("{")
|
||||||
if @options[:order]
|
if @options[:enforce_strict_ordering]
|
||||||
output.puts(" GlobalExpectCount = 0;")
|
output.puts(" GlobalExpectCount = 0;")
|
||||||
output.puts(" GlobalVerifyOrder = 0;")
|
output.puts(" GlobalVerifyOrder = 0;")
|
||||||
output.puts(" GlobalOrderError = NULL;")
|
output.puts(" GlobalOrderError = NULL;")
|
||||||
@ -198,17 +192,18 @@ class UnityTestRunnerGenerator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_runtest(output, used_mocks)
|
def create_runtest(output, used_mocks)
|
||||||
|
cexception = @options[:plugins].include? :cexception
|
||||||
output.puts("static void runTest(UnityTestFunction test)")
|
output.puts("static void runTest(UnityTestFunction test)")
|
||||||
output.puts("{")
|
output.puts("{")
|
||||||
output.puts(" if (TEST_PROTECT())")
|
output.puts(" if (TEST_PROTECT())")
|
||||||
output.puts(" {")
|
output.puts(" {")
|
||||||
output.puts(" CEXCEPTION_T e;") if @options[:cexception]
|
output.puts(" CEXCEPTION_T e;") if cexception
|
||||||
output.puts(" Try {") if @options[:cexception]
|
output.puts(" Try {") if cexception
|
||||||
output.puts(" CMock_Init();") unless (used_mocks.empty?)
|
output.puts(" CMock_Init();") unless (used_mocks.empty?)
|
||||||
output.puts(" setUp();")
|
output.puts(" setUp();")
|
||||||
output.puts(" test();")
|
output.puts(" test();")
|
||||||
output.puts(" CMock_Verify();") unless (used_mocks.empty?)
|
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(" }")
|
||||||
output.puts(" CMock_Destroy();") unless (used_mocks.empty?)
|
output.puts(" CMock_Destroy();") unless (used_mocks.empty?)
|
||||||
output.puts(" if (TEST_PROTECT() && !TEST_IS_IGNORED)")
|
output.puts(" if (TEST_PROTECT() && !TEST_IS_IGNORED)")
|
||||||
@ -250,30 +245,23 @@ end
|
|||||||
|
|
||||||
|
|
||||||
if ($0 == __FILE__)
|
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 => [] }
|
options = { :includes => [] }
|
||||||
yaml_file = nil
|
yaml_file = nil
|
||||||
|
|
||||||
#parse out all the options first
|
#parse out all the options first
|
||||||
ARGV.reject! do |arg|
|
ARGV.reject! do |arg|
|
||||||
if (arg =~ /\-(\w+)/)
|
case(arg)
|
||||||
options[$1.to_sym] = 1
|
when '-cexception': options[:plugins] = [:cexception]; true
|
||||||
true
|
when /\w+\.yml/: options = UnityTestRunnerGenerator.grab_config(arg); true
|
||||||
elsif (arg =~ /(\w+\.yml)/)
|
else false
|
||||||
options = UnityTestRunnerGenerator.grab_config(arg)
|
|
||||||
true
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#make sure there is at least one parameter left (the input file)
|
#make sure there is at least one parameter left (the input file)
|
||||||
if !ARGV[0]
|
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
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,6 +22,11 @@ task :unit do
|
|||||||
run_tests get_unit_test_files
|
run_tests get_unit_test_files
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Rake::TestTask.new(:scripts) do |t|
|
||||||
|
t.pattern = 'test/test_*.rb'
|
||||||
|
t.verbose = true
|
||||||
|
end
|
||||||
|
|
||||||
desc "Generate test summary"
|
desc "Generate test summary"
|
||||||
task :summary do
|
task :summary do
|
||||||
report_summary
|
report_summary
|
||||||
|
@ -236,5 +236,4 @@ module RakefileHelpers
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
47
test/expectdata/testsample_cmd.c
Normal file
47
test/expectdata/testsample_cmd.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#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());
|
||||||
|
}
|
43
test/expectdata/testsample_def.c
Normal file
43
test/expectdata/testsample_def.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.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())
|
||||||
|
{
|
||||||
|
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());
|
||||||
|
}
|
67
test/expectdata/testsample_mock_cmd.c
Normal file
67
test/expectdata/testsample_mock_cmd.c
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include "cmock.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#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());
|
||||||
|
}
|
63
test/expectdata/testsample_mock_def.c
Normal file
63
test/expectdata/testsample_mock_def.c
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include "cmock.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.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())
|
||||||
|
{
|
||||||
|
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());
|
||||||
|
}
|
75
test/expectdata/testsample_mock_new1.c
Normal file
75
test/expectdata/testsample_mock_new1.c
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include "cmock.h"
|
||||||
|
#include "one.h"
|
||||||
|
#include "two.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#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());
|
||||||
|
}
|
72
test/expectdata/testsample_mock_new2.c
Normal file
72
test/expectdata/testsample_mock_new2.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include "cmock.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.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 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());
|
||||||
|
}
|
75
test/expectdata/testsample_mock_run1.c
Normal file
75
test/expectdata/testsample_mock_run1.c
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include "cmock.h"
|
||||||
|
#include "one.h"
|
||||||
|
#include "two.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#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());
|
||||||
|
}
|
72
test/expectdata/testsample_mock_run2.c
Normal file
72
test/expectdata/testsample_mock_run2.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include "cmock.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.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 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());
|
||||||
|
}
|
68
test/expectdata/testsample_mock_yaml.c
Normal file
68
test/expectdata/testsample_mock_yaml.c
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include "cmock.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.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 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());
|
||||||
|
}
|
52
test/expectdata/testsample_new1.c
Normal file
52
test/expectdata/testsample_new1.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include "one.h"
|
||||||
|
#include "two.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#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());
|
||||||
|
}
|
52
test/expectdata/testsample_new2.c
Normal file
52
test/expectdata/testsample_new2.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
52
test/expectdata/testsample_run1.c
Normal file
52
test/expectdata/testsample_run1.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include "one.h"
|
||||||
|
#include "two.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#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());
|
||||||
|
}
|
52
test/expectdata/testsample_run2.c
Normal file
52
test/expectdata/testsample_run2.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
48
test/expectdata/testsample_yaml.c
Normal file
48
test/expectdata/testsample_yaml.c
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/* AUTOGENERATED FILE. DO NOT EDIT. */
|
||||||
|
#include "unity.h"
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
82
test/test_generate_test_runner.rb
Normal file
82
test/test_generate_test_runner.rb
Normal file
@ -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
|
51
test/testdata/mocksample.c
vendored
Normal file
51
test/testdata/mocksample.c
vendored
Normal file
@ -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 <setjmp.h>
|
||||||
|
#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
|
8
test/testdata/sample.yml
vendored
Normal file
8
test/testdata/sample.yml
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
:unity:
|
||||||
|
:includes
|
||||||
|
- two.h
|
||||||
|
- three.h
|
||||||
|
:plugins:
|
||||||
|
- :cexception
|
||||||
|
:suite_setup: |
|
||||||
|
a_yaml_setup();
|
51
test/testdata/testsample.c
vendored
Normal file
51
test/testdata/testsample.c
vendored
Normal file
@ -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 <setjmp.h>
|
||||||
|
#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
|
Reference in New Issue
Block a user