mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-24 08:51:36 +01:00
- rework to not bother with any of the ever-changing test frameworks in Ruby (sigh) for self-testing
- started working on cleaner floating point support. more coming.
This commit is contained in:
@@ -2,14 +2,8 @@
|
||||
# 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 'rubygems'
|
||||
gem 'test-unit'
|
||||
end
|
||||
require 'test/unit'
|
||||
require './auto/generate_test_runner.rb'
|
||||
|
||||
TEST_FILE = 'test/testdata/testsample.c'
|
||||
@@ -17,78 +11,78 @@ TEST_MOCK = 'test/testdata/mocksample.c'
|
||||
OUT_FILE = 'build/testsample_'
|
||||
EXP_FILE = 'test/expectdata/testsample_'
|
||||
|
||||
class TestGenerateTestRunner < Test::Unit::TestCase
|
||||
def setup
|
||||
end
|
||||
$generate_test_runner_failures = 0
|
||||
|
||||
def teardown
|
||||
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")
|
||||
if (expected != actual)
|
||||
report(" #{subtest}:FAIL")
|
||||
$generate_test_runner_failures += 1
|
||||
else
|
||||
report(" #{subtest}:PASS")
|
||||
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
|
||||
|
||||
def test_ShouldGenerateARunnerThatUsesParameterizedTests
|
||||
sets = { 'param' => { :plugins => [:ignore], :use_param_tests => true }
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
should "GenerateARunnerByCreatingRunnerWithOptions" do
|
||||
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
|
||||
|
||||
should "GenerateARunnerByRunningRunnerWithOptions" do
|
||||
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
|
||||
|
||||
should "GenerateARunnerByPullingYamlOptions" do
|
||||
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
|
||||
|
||||
should "GenerateARunnerByPullingCommandlineOptions" do
|
||||
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
|
||||
|
||||
should "GenerateARunnerThatUsesParameterizedTests" do
|
||||
sets = { 'param' => { :plugins => [:ignore], :use_param_tests => true }
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
raise "There were #{$generate_test_runner_failures.to_s} failures while testing generate_test_runner.rb" if ($generate_test_runner_failures > 0)
|
||||
|
||||
@@ -9,7 +9,10 @@
|
||||
|
||||
// Dividing by these constants produces +/- infinity.
|
||||
// The rationale is given in UnityAssertFloatIsInf's body.
|
||||
#ifndef UNITY_EXCLUDE_FLOAT
|
||||
static const _UF f_zero = 0.0f;
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_EXCLUDE_DOUBLE
|
||||
static const _UD d_zero = 0.0;
|
||||
#endif
|
||||
@@ -2332,17 +2335,47 @@ void testFloatsNotEqualPlusMinusInf(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFloatIsInf(void)
|
||||
void testFloatIsPosInf1(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
TEST_ASSERT_FLOAT_IS_INF(2.0f / f_zero);
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFloatIsPosInf2(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_FLOAT_IS_NOT_INF(2.0f / f_zero);
|
||||
VERIFY_FAILS_END
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFloatIsNegInf1(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
TEST_ASSERT_FLOAT_IS_NEG_INF(-3.0f / f_zero);
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFloatIsNotInf(void)
|
||||
void testFloatIsNegInf2(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(-3.0f / f_zero);
|
||||
VERIFY_FAILS_END
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFloatIsNotPosInf1(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
TEST_IGNORE();
|
||||
@@ -2353,6 +2386,15 @@ void testFloatIsNotInf(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFloatIsNotPosInf2(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
TEST_ASSERT_FLOAT_IS_NOT_INF(2.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFloatIsNotNegInf(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
@@ -2364,7 +2406,7 @@ void testFloatIsNotNegInf(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFloatIsNan(void)
|
||||
void testFloatIsNan1(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
TEST_IGNORE();
|
||||
@@ -2373,7 +2415,18 @@ void testFloatIsNan(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFloatIsNotNan(void)
|
||||
void testFloatIsNan2(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
EXPECT_ABORT_BEGIN
|
||||
TEST_ASSERT_FLOAT_IS_NOT_NAN(0.0f / f_zero);
|
||||
VERIFY_FAILS_END
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFloatIsNotNan1(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
TEST_IGNORE();
|
||||
@@ -2384,6 +2437,15 @@ void testFloatIsNotNan(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFloatIsNotNan2(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
TEST_IGNORE();
|
||||
#else
|
||||
TEST_ASSERT_FLOAT_IS_NOT_NAN(234.9f);
|
||||
#endif
|
||||
}
|
||||
|
||||
void testFloatInfIsNotNan(void)
|
||||
{
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
|
||||
Reference in New Issue
Block a user