diff --git a/lib/ceedling/generator.rb b/lib/ceedling/generator.rb index ce92d038..306f6cfb 100644 --- a/lib/ceedling/generator.rb +++ b/lib/ceedling/generator.rb @@ -73,7 +73,7 @@ def generate_mock(context:, mock:, test:, input_filepath:, output_path:) end end - def generate_test_runner(context:, mock_list:, test_filepath:, input_filepath:, runner_filepath:) + def generate_test_runner(context:, mock_list:, includes_list:, test_filepath:, input_filepath:, runner_filepath:) arg_hash = { :context => context, :test_file => test_filepath, @@ -102,6 +102,7 @@ def generate_test_runner(context:, mock_list:, test_filepath:, input_filepath:, module_name: module_name, runner_filepath: runner_filepath, mock_list: mock_list, + test_file_includes: includes_list, header_extension: @configurator.extension_header ) rescue diff --git a/lib/ceedling/generator_test_runner.rb b/lib/ceedling/generator_test_runner.rb index d529a4b5..ef444b74 100644 --- a/lib/ceedling/generator_test_runner.rb +++ b/lib/ceedling/generator_test_runner.rb @@ -28,7 +28,7 @@ def initialize(config:, test_file_contents:, preprocessed_file_contents:nil) parse_test_file( test_file_contents, preprocessed_file_contents ) end - def generate(module_name:, runner_filepath:, mock_list:, test_file_includes:[], header_extension:) + def generate(module_name:, runner_filepath:, mock_list:, test_file_includes:, header_extension:) # Actually build the test runner using Unity's test runner generator. @unity_runner_generator.generate( module_name, diff --git a/lib/ceedling/test_context_extractor.rb b/lib/ceedling/test_context_extractor.rb index caab5c96..f18bda4d 100644 --- a/lib/ceedling/test_context_extractor.rb +++ b/lib/ceedling/test_context_extractor.rb @@ -13,8 +13,9 @@ class TestContextExtractor constructor :configurator, :file_wrapper, :loginator def setup - @header_includes = {} - @source_includes = {} + @all_header_includes = {} # Full list of all headers a test #includes + @header_includes = {} # List of all headers minus mocks & framework files + @source_includes = {} @source_extras = {} @test_runner_details = {} # Test case lists & Unity runner generator instances @mocks = {} @@ -63,7 +64,12 @@ def extract_includes(filepath) return extract_includes( filepath, content ) end - # Header includes of test file with file extension + # All header includes .h of test file + def lookup_full_header_includes_list(filepath) + return @all_header_includes[form_file_key( filepath )] || [] + end + + # Header includes .h (minus mocks & framework headers) in test file def lookup_header_includes_list(filepath) return @header_includes[form_file_key( filepath )] || [] end @@ -108,19 +114,27 @@ def ingest_includes(filepath, includes) mock_prefix = @configurator.cmock_mock_prefix file_key = form_file_key( filepath ) - mocks = [] - headers = [] - sources = [] + mocks = [] + all_headers = [] + headers = [] + sources = [] includes.each do |include| # <*.h> if include =~ /#{Regexp.escape(@configurator.extension_header)}$/ # Check if include is a mock with regex match that extracts only mock name (no .h) scan_results = include.scan(/(#{mock_prefix}.+)#{Regexp.escape(@configurator.extension_header)}/) - mocks << scan_results[0][0] if (scan_results.size > 0) + + if (scan_results.size > 0) + # Collect mock name + mocks << scan_results[0][0] + else + # If not a mock or framework file, collect tailored header filename + headers << include unless VENDORS_FILES.include?( include.ext('') ) + end # Add to .h includes list - headers << include + all_headers << include # <*.c> elsif include =~ /#{Regexp.escape(@configurator.extension_source)}$/ # Add to .c includes list @@ -130,6 +144,7 @@ def ingest_includes(filepath, includes) @lock.synchronize do @mocks[file_key] = mocks + @all_header_includes[file_key] = all_headers @header_includes[file_key] = headers @source_includes[file_key] = sources end diff --git a/lib/ceedling/test_invoker.rb b/lib/ceedling/test_invoker.rb index bf0a6e8e..b2fdb787 100644 --- a/lib/ceedling/test_invoker.rb +++ b/lib/ceedling/test_invoker.rb @@ -281,6 +281,7 @@ def setup_and_invoke(tests:, context:TEST_SYM, options:{}) arg_hash = { context: TEST_SYM, mock_list: details[:mock_list], + includes_list: @test_context_extractor.lookup_header_includes_list( details[:filepath] ), test_filepath: details[:filepath], input_filepath: details[:runner][:input_filepath], runner_filepath: details[:runner][:output_filepath] diff --git a/lib/ceedling/test_invoker_helper.rb b/lib/ceedling/test_invoker_helper.rb index 990f4ab6..ff4738a0 100644 --- a/lib/ceedling/test_invoker_helper.rb +++ b/lib/ceedling/test_invoker_helper.rb @@ -199,7 +199,7 @@ def extract_sources(test_filepath) _support_headers = COLLECTION_ALL_SUPPORT.map { |filepath| File.basename(filepath).ext(EXTENSION_HEADER) } # Get all #include .h files from test file so we can find any source files by convention - includes = @test_context_extractor.lookup_header_includes_list(test_filepath) + includes = @test_context_extractor.lookup_full_header_includes_list(test_filepath) includes.each do |include| _basename = File.basename(include) next if _basename == UNITY_H_FILE # Ignore Unity in this list