Skip to content

Commit

Permalink
Merge branch 'master' into unit-test-execution-time
Browse files Browse the repository at this point in the history
  • Loading branch information
elliot-gawthrop committed Jul 28, 2018
2 parents cc909ef + ccb7faf commit f0e4571
Show file tree
Hide file tree
Showing 20 changed files with 712 additions and 325 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ before_install:
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --assume-yes --quiet gcc-multilib; fi
install:
- gem install rspec
- gem install rubocop
- gem install rubocop -v 0.57.2
script:
- cd test && rake ci
- make -s
- make -s DEBUG=-m32
- make -s DEBUG=-m32 #32-bit architecture with 64-bit support
- make -s DEBUG=-m32 UNITY_SUPPORT_64= #32-bit build without 64-bit types
- make -s UNITY_INCLUDE_DOUBLE= # without double
- cd ../extras/fixture/test && rake ci
- make -s default noStdlibMalloc
- make -s C89
Expand Down
40 changes: 30 additions & 10 deletions auto/generate_test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def self.default_options
framework: :unity,
test_prefix: 'test|spec|should',
mock_prefix: 'Mock',
mock_suffix: '',
setup_name: 'setUp',
teardown_name: 'tearDown',
main_name: 'main', # set to :auto to automatically generate each time
Expand Down Expand Up @@ -119,7 +120,7 @@ def find_tests(source)
source_index = 0
tests_and_line_numbers.size.times do |i|
source_lines[source_index..-1].each_with_index do |line, index|
next unless line =~ /#{tests_and_line_numbers[i][:test]}/
next unless line =~ /\s+#{tests_and_line_numbers[i][:test]}(?:\s|\()/
source_index += index
tests_and_line_numbers[i][:line_number] = source_index + 1
break
Expand Down Expand Up @@ -148,7 +149,7 @@ def find_mocks(includes)
mock_headers = []
includes.each do |include_path|
include_file = File.basename(include_path)
mock_headers << include_path if include_file =~ /^#{@options[:mock_prefix]}/i
mock_headers << include_path if include_file =~ /^#{@options[:mock_prefix]}.*#{@options[:mock_suffix]}$/i
end
mock_headers
end
Expand All @@ -157,9 +158,14 @@ def create_header(output, mocks, testfile_includes = [])
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
create_runtest(output, mocks)
output.puts("\n/*=======Automagically Detected Files To Include=====*/")
output.puts('#ifdef __WIN32__')
output.puts('#define UNITY_INCLUDE_SETUP_STUBS')
output.puts('#endif')
output.puts("#include \"#{@options[:framework]}.h\"")
output.puts('#include "cmock.h"') unless mocks.empty?
output.puts('#ifndef UNITY_EXCLUDE_SETJMP_H')
output.puts('#include <setjmp.h>')
output.puts("#endif")
output.puts('#include <stdio.h>')
if @options[:defines] && !@options[:defines].empty?
@options[:defines].each { |d| output.puts("#define #{d}") }
Expand Down Expand Up @@ -235,22 +241,36 @@ def create_mock_management(output, mock_headers)
end

def create_suite_setup(output)
return if @options[:suite_setup].nil?

output.puts("\n/*=======Suite Setup=====*/")
output.puts('static void suite_setup(void)')
output.puts('{')
output.puts(@options[:suite_setup])
if @options[:suite_setup].nil?
# New style, call suiteSetUp() if we can use weak symbols
output.puts('#if defined(UNITY_WEAK_ATTRIBUTE) || defined(UNITY_WEAK_PRAGMA)')
output.puts(' suiteSetUp();')
output.puts('#endif')
else
# Old style, C code embedded in the :suite_setup option
output.puts(@options[:suite_setup])
end
output.puts('}')
end

def create_suite_teardown(output)
return if @options[:suite_teardown].nil?

output.puts("\n/*=======Suite Teardown=====*/")
output.puts('static int suite_teardown(int num_failures)')
output.puts('{')
output.puts(@options[:suite_teardown])
if @options[:suite_teardown].nil?
# New style, call suiteTearDown() if we can use weak symbols
output.puts('#if defined(UNITY_WEAK_ATTRIBUTE) || defined(UNITY_WEAK_PRAGMA)')
output.puts(' return suiteTearDown(num_failures);')
output.puts('#else')
output.puts(' return num_failures;')
output.puts('#endif')
else
# Old style, C code embedded in the :suite_teardown option
output.puts(@options[:suite_teardown])
end
output.puts('}')
end

Expand Down Expand Up @@ -342,7 +362,7 @@ def create_main(output, filename, tests, used_mocks)
output.puts("int #{main_name}(void)")
output.puts('{')
end
output.puts(' suite_setup();') unless @options[:suite_setup].nil?
output.puts(' suite_setup();')
output.puts(" UnityBegin(\"#{filename.gsub(/\\/, '\\\\\\')}\");")
if @options[:use_param_tests]
tests.each do |test|
Expand All @@ -357,7 +377,7 @@ def create_main(output, filename, tests, used_mocks)
end
output.puts
output.puts(' CMock_Guts_MemFreeFinal();') unless used_mocks.empty?
output.puts(" return #{@options[:suite_teardown].nil? ? '' : 'suite_teardown'}(UnityEnd());")
output.puts(" return suite_teardown(UnityEnd());")
output.puts('}')
end

Expand Down
Loading

0 comments on commit f0e4571

Please sign in to comment.