提交 33fa00d5 编写于 作者: M mvandervoord

- 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
上级 1f643e86
......@@ -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 <setjmp.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|
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
......
......@@ -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
......
......@@ -236,5 +236,4 @@ module RakefileHelpers
end
end
end
/* 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());
}
/* 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());
}
/* 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());
}
/* 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());
}
/* 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());
}
/* 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());
}
/* 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());
}
/* 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());
}
/* 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());
}
/* 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());
}
/* 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());
}
/* 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());
}
/* 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());
}
/* 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());
}
# ==========================================
# 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
// 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
:unity:
:includes
- two.h
- three.h
:plugins:
- :cexception
:suite_setup: |
a_yaml_setup();
\ No newline at end of file
// 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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册