Class: GeneratorTestRunner

Inherits:
Object show all
Defined in:
lib/ceedling/generators/generator_test_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, test_file_contents:, preprocessed_file_contents: nil, parsing_parcels:) ⇒ GeneratorTestRunner

This class is not within any DIY context. It is instantiated on demand for each test file processed in a build.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ceedling/generators/generator_test_runner.rb', line 21

def initialize(config:, test_file_contents:, preprocessed_file_contents: nil, parsing_parcels:)
  @unity_runner_generator = UnityTestRunnerGenerator.new( config )
  @parsing_parcels = parsing_parcels

  # Reduced information set
  @test_cases = []

  # Full information set used for runner generation
  @test_cases_internal = []

  parse_test_file( test_file_contents, preprocessed_file_contents )
end

Instance Attribute Details

#test_casesObject

Returns the value of attribute test_cases.



14
15
16
# File 'lib/ceedling/generators/generator_test_runner.rb', line 14

def test_cases
  @test_cases
end

Instance Method Details

#generate(module_name:, runner_filepath:, mocks:, includes:) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ceedling/generators/generator_test_runner.rb', line 34

def generate(module_name:, runner_filepath:, mocks:, includes:)
  # Actually build the test runner using Unity's test runner generator.
  @unity_runner_generator.generate(
    module_name,
    runner_filepath,
    @test_cases_internal,
    # Small hack for mock subdirectory support until include paths fully supported
    mocks.map{ |include| include.filepath },
    # Unity's own generator emits a string verbatim if it contains '<' and otherwise
    # wraps it in double quotes -- each entry here must therefore already be in its
    # final, exact form.
    #
    # System includes only: use the full, bracketed spelling (include_path, a
    # reconciled SystemInclude's original as-written directive text -- e.g.
    # "sys/stat.h" -- when set, else the directory-preserving filepath). A bare
    # filename here drops both the directory component and the '<>' delimiters a
    # system header's own search path depends on (issue #1236).
    #
    # User includes: bare filename, same as always. Unlike mocks (whose subdirectory
    # is a real, dedicated build/test/mocks/<test>/ path -- hence their own
    # directory-preserving filepath usage above) or a system header (whose directory
    # is meaningful to the system include search path), a project's own directories
    # are exposed to the compiler as a flat list of -I search paths, not nested to
    # match whatever directory component a captured UserInclude's filepath happens to
    # carry -- rendering the full path here breaks resolution instead of fixing it.
    includes.map do |include|
      if include.is_a?(SystemInclude)
        "<#{include.include_path || include.filepath}>"
      else
        include.filename
      end
    end
  )
end