mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-23 08:25:58 +01:00
Centralize all testing to the test folder instead of each subproject.
Trigger ALL tests when calling `rake test:all` instead of that being just the core tests.
This commit is contained in:
@@ -7,7 +7,8 @@ E = -Weverything
|
||||
CFLAGS += $E -Wno-unknown-warning-option -Wno-missing-prototypes
|
||||
CFLAGS += -Wno-unused-macros -Wno-padded -Wno-missing-noreturn
|
||||
endif
|
||||
CFLAGS += -std=c99 -pedantic -Wall -Wextra -Wconversion -Werror
|
||||
CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror
|
||||
#CFLAGS += -Wconversion #disabled because if falsely complains about the isinf and isnan macros
|
||||
CFLAGS += -Wno-switch-enum -Wno-double-promotion
|
||||
CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstrict-overflow \
|
||||
-Wstrict-prototypes -Wswitch-default -Wundef
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
# ==========================================
|
||||
|
||||
$verbose = false
|
||||
$extra_paths = []
|
||||
|
||||
require 'rake'
|
||||
require 'rake/clean'
|
||||
@@ -29,9 +30,10 @@ include RakefileHelpers
|
||||
DEFAULT_CONFIG_FILE = 'gcc_auto_stdint.yml'
|
||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||
|
||||
############# ALL THE SELF-TESTS WE CAN PERFORM
|
||||
namespace :test do
|
||||
desc "Build and test Unity"
|
||||
task :all => [:clean, :prepare_for_tests, 'test:scripts', 'test:unit', :style, 'test:summary']
|
||||
task :all => [:clean, :prepare_for_tests, 'test:scripts', 'test:unit', :style, 'test:make', 'test:fixture', 'test:memory', 'test:summary']
|
||||
|
||||
desc "Test unity with its own unit tests"
|
||||
task :unit => [:prepare_for_tests] do
|
||||
@@ -45,6 +47,28 @@ namespace :test do
|
||||
end
|
||||
end
|
||||
|
||||
desc "Test unity triggered from make"
|
||||
task :make => [:prepare_for_tests] do
|
||||
run_make_tests()
|
||||
end
|
||||
|
||||
desc "Test unity fixture addon"
|
||||
task :fixture => [:prepare_for_tests] do
|
||||
test_fixtures()
|
||||
end
|
||||
|
||||
desc "Test unity memory addon"
|
||||
task :memory => [:prepare_for_tests] do
|
||||
test_memory()
|
||||
end
|
||||
|
||||
desc "Test unity examples"
|
||||
task :examples => [:prepare_for_tests] do
|
||||
execute("cd ../examples/example_1 && make -s ci", false)
|
||||
execute("cd ../examples/example_2 && make -s ci", false)
|
||||
execute("cd ../examples/example_3 && rake", false)
|
||||
end
|
||||
|
||||
desc "Run all rspecs"
|
||||
RSpec::Core::RakeTask.new(:spec) do |t|
|
||||
t.pattern = 'spec/**/*_spec.rb'
|
||||
@@ -56,11 +80,10 @@ namespace :test do
|
||||
end
|
||||
end
|
||||
|
||||
# Shorthand for many common tasks
|
||||
###################### Shorthand for many common tasks
|
||||
task :all => ['test:all']
|
||||
task :default => [:clobber, :all]
|
||||
task :ci => [:no_color, :default]
|
||||
task :cruise => [:no_color, :default]
|
||||
|
||||
desc "Load configuration"
|
||||
task :config, :config_file do |t, args|
|
||||
@@ -75,6 +98,7 @@ task :verbose do
|
||||
$verbose = true
|
||||
end
|
||||
|
||||
################### CODING STYLE VALIDATION
|
||||
namespace :style do
|
||||
desc "Check style"
|
||||
task :check do
|
||||
|
||||
@@ -103,13 +103,13 @@ module RakefileHelpers
|
||||
|
||||
elsif arg.include? ': COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR'
|
||||
pattern = arg.gsub(': COLLECTION_PATHS_TEST_SUPPORT_SOURCE_INCLUDE_VENDOR','')
|
||||
[ 'src', File.join('tests'), File.join('testdata'), $cfg[:paths][:support] ].flatten.uniq.compact.each do |f|
|
||||
[ $extra_paths, 'src', File.join('tests'), File.join('testdata'), $cfg[:paths][:support] ].flatten.uniq.compact.each do |f|
|
||||
args << pattern.gsub(/\$/,f)
|
||||
end
|
||||
|
||||
elsif arg.include? ': COLLECTION_DEFINES_TEST_AND_VENDOR'
|
||||
pattern = arg.gsub(': COLLECTION_DEFINES_TEST_AND_VENDOR','')
|
||||
[ 'TEST', $cfg[:defines][:test], defines ].flatten.uniq.compact.each do |f|
|
||||
[ $cfg[:defines][:test], defines ].flatten.uniq.compact.each do |f|
|
||||
args << pattern.gsub(/\$/,f)
|
||||
end
|
||||
|
||||
@@ -181,15 +181,75 @@ module RakefileHelpers
|
||||
def report_summary
|
||||
summary = UnityTestSummary.new
|
||||
summary.root = __dir__
|
||||
results_glob = "build/*.test*"
|
||||
results_glob = File.join('build','*.test*')
|
||||
results_glob.tr!('\\', '/')
|
||||
results = Dir[results_glob]
|
||||
summary.targets = results
|
||||
report summary.run
|
||||
end
|
||||
|
||||
def save_test_results(test_base, output)
|
||||
test_results = File.join('build',test_base)
|
||||
if output.match(/OK$/m).nil?
|
||||
test_results += '.testfail'
|
||||
else
|
||||
report output unless $verbose # Verbose already prints this line, as does a failure
|
||||
test_results += '.testpass'
|
||||
end
|
||||
File.open(test_results, 'w') { |f| f.print output }
|
||||
end
|
||||
|
||||
def test_fixtures()
|
||||
report "\nRunning Fixture Addon"
|
||||
|
||||
# Get a list of all source files needed
|
||||
src_files = Dir[File.join('..','extras','fixture','src','*.c')]
|
||||
src_files += Dir[File.join('..','extras','fixture','test','*.c')]
|
||||
src_files += Dir[File.join('..','extras','fixture','test','main','*.c')]
|
||||
src_files += Dir[File.join('..','extras','memory','src','*.c')]
|
||||
src_files << File.join('..','src','unity.c')
|
||||
|
||||
# Build object files
|
||||
$extra_paths = [File.join('..','extras','fixture','src'), File.join('..','extras','memory','src')]
|
||||
obj_list = src_files.map { |f| compile(f, ['UNITY_SKIP_DEFAULT_RUNNER', 'UNITY_FIXTURE_NO_EXTRAS']) }
|
||||
|
||||
# Link the test executable
|
||||
test_base = File.basename('framework_test', C_EXTENSION)
|
||||
link_it(test_base, obj_list)
|
||||
|
||||
# Run and collect output
|
||||
output = runtest(test_base + " -v -r")
|
||||
save_test_results(test_base, output)
|
||||
end
|
||||
|
||||
def test_memory()
|
||||
{ 'w_malloc' => [],
|
||||
'wo_malloc' => ['UNITY_EXCLUDE_STDLIB_MALLOC']
|
||||
}.each_pair do |name, defs|
|
||||
report "\nRunning Memory Addon #{name}"
|
||||
|
||||
# Get a list of all source files needed
|
||||
src_files = Dir[File.join('..','extras','memory','src','*.c')]
|
||||
src_files += Dir[File.join('..','extras','memory','test','*.c')]
|
||||
src_files += Dir[File.join('..','extras','memory','test','main','*.c')]
|
||||
src_files << File.join('..','src','unity.c')
|
||||
|
||||
# Build object files
|
||||
$extra_paths = [File.join('..','extras','memory','src')]
|
||||
obj_list = src_files.map { |f| compile(f, defs) }
|
||||
|
||||
# Link the test executable
|
||||
test_base = File.basename("memory_test_#{name}", C_EXTENSION)
|
||||
link_it(test_base, obj_list)
|
||||
|
||||
# Run and collect output
|
||||
output = runtest(test_base)
|
||||
save_test_results(test_base, output)
|
||||
end
|
||||
end
|
||||
|
||||
def run_tests(test_files)
|
||||
report 'Running Unity system tests...'
|
||||
report "\nRunning Unity system tests"
|
||||
|
||||
include_dirs = local_include_dirs
|
||||
|
||||
@@ -218,7 +278,7 @@ module RakefileHelpers
|
||||
# Build the test runner (generate if configured to do so)
|
||||
test_base = File.basename(test, C_EXTENSION)
|
||||
runner_name = test_base + '_Runner.c'
|
||||
runner_path = 'build/' + runner_name
|
||||
runner_path = File.join('build',runner_name)
|
||||
|
||||
options = $cfg[:unity]
|
||||
options[:use_param_tests] = test =~ /parameterized/ ? true : false
|
||||
@@ -233,14 +293,22 @@ module RakefileHelpers
|
||||
|
||||
# Execute unit test and generate results file
|
||||
output = runtest(test_base)
|
||||
test_results = 'build/' + test_base
|
||||
if output.match(/OK$/m).nil?
|
||||
test_results += '.testfail'
|
||||
else
|
||||
report output unless $verbose # Verbose already prints this line, as does a failure
|
||||
test_results += '.testpass'
|
||||
end
|
||||
File.open(test_results, 'w') { |f| f.print output }
|
||||
save_test_results(test_base, output)
|
||||
end
|
||||
end
|
||||
|
||||
def run_make_tests()
|
||||
[ "make -s", # test with all defaults
|
||||
"make -s DEBUG=-m32", # test 32-bit architecture with 64-bit support
|
||||
"make -s DEBUG=-m32 UNITY_SUPPORT_64=", # test 32-bit build without 64-bit types
|
||||
"make -s UNITY_INCLUDE_DOUBLE= ", # test without double
|
||||
"cd #{File.join("..","extras","fixture")} && make -s default noStdlibMalloc",
|
||||
"cd #{File.join("..","extras","fixture")} && make -s C89",
|
||||
"cd #{File.join("..","extras","memory")} && make -s default noStdlibMalloc",
|
||||
"cd #{File.join("..","extras","memory")} && make -s C89",
|
||||
].each do |cmd|
|
||||
report "Testing '#{cmd}'"
|
||||
execute(cmd, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user