Class: TestContextExtractor
- Defined in:
- lib/ceedling/test_context_extractor.rb
Instance Method Summary collapse
-
#code_lines(input) ⇒ Object
Exposed for testing.
-
#collect_simple_context(filepath, input, *args) ⇒ Object
‘input` must have the interface of IO – StringIO for testing or File in typical use.
- #collect_test_runner_details(test_filepath, input_filepath = nil) ⇒ Object
-
#extract_includes(input) ⇒ Object
Scan for all includes.
-
#ingest_includes(filepath, includes) ⇒ Object
Unlike other ingest() calls, ingest_includes() can be called externally.
- #inspect_include_paths ⇒ Object
- #lookup_all_include_paths ⇒ Object
-
#lookup_build_directive_sources_list(filepath) ⇒ Object
Source extras via TEST_SOURCE_FILE() within test file.
-
#lookup_full_header_includes_list(filepath) ⇒ Object
All header includes .h of test file.
-
#lookup_header_includes_list(filepath) ⇒ Object
Header includes .h (minus mocks & framework headers) in test file.
-
#lookup_include_paths_list(filepath) ⇒ Object
Include paths of test file specified with TEST_INCLUDE_PATH().
-
#lookup_raw_mock_list(filepath) ⇒ Object
Mocks within test file with no file extension.
-
#lookup_source_includes_list(filepath) ⇒ Object
Source header_includes within test file.
- #lookup_test_cases(filepath) ⇒ Object
- #lookup_test_runner_generator(filepath) ⇒ Object
- #setup ⇒ Object
Instance Method Details
#code_lines(input) ⇒ Object
Exposed for testing
238 239 240 241 242 243 244 245 |
# File 'lib/ceedling/test_context_extractor.rb', line 238 def code_lines(input) comment_block = false # Far more memory efficient and faster (for large files) than slurping entire file into memory input.each_line do |line| _line, comment_block = clean_code_line( line, comment_block ) yield( _line ) end end |
#collect_simple_context(filepath, input, *args) ⇒ Object
‘input` must have the interface of IO – StringIO for testing or File in typical use
33 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ceedling/test_context_extractor.rb', line 33 def collect_simple_context( filepath, input, *args ) = [ :build_directive_include_paths, :build_directive_source_files, :includes, :test_runner_details ] # Code error check--bad context symbol argument args.each do |context| next if context == :all msg = "Unrecognized test context for collection :#{context}" raise CeedlingException.new( msg ) if !.include?( context ) end # Handle the :all shortcut to redefine list to include all contexts args = if args.include?( :all ) include_paths = [] source_extras = [] includes = [] code_lines( input ) do |line| if args.include?( :build_directive_include_paths ) # Scan for build directives: TEST_INCLUDE_PATH() include_paths += extract_build_directive_include_paths( line ) end if args.include?( :build_directive_source_files ) # Scan for build directives: TEST_SOURCE_FILE() source_extras += extract_build_directive_source_files( line ) end if args.include?( :includes ) # Scan for contents of #include directives includes += _extract_includes( line ) end end collect_build_directive_include_paths( filepath, include_paths ) if args.include?( :build_directive_include_paths ) collect_build_directive_source_files( filepath, source_extras ) if args.include?( :build_directive_source_files ) collect_includes( filepath, includes ) if args.include?( :includes ) # Different code processing pattern for test runner if args.include?( :test_runner_details ) # Go back to beginning of IO object for a full string extraction input.rewind() # Ultimately, we rely on Unity's runner generator that processes file contents as a single string _collect_test_runner_details( filepath, input.read() ) end end |
#collect_test_runner_details(test_filepath, input_filepath = nil) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/ceedling/test_context_extractor.rb', line 86 def collect_test_runner_details(test_filepath, input_filepath=nil) # Ultimately, we rely on Unity's runner generator that processes file contents as a single string _collect_test_runner_details( test_filepath, @file_wrapper.read( test_filepath ), input_filepath.nil? ? nil : @file_wrapper.read( input_filepath ) ) end |
#extract_includes(input) ⇒ Object
Scan for all includes. Unlike other extract() calls, extract_includes() is public to be called externally. ‘input` must have the interface of IO – StringIO for testing or File in typical use
98 99 100 101 102 103 104 |
# File 'lib/ceedling/test_context_extractor.rb', line 98 def extract_includes(input) includes = [] code_lines( input ) {|line| includes += _extract_includes( line ) } return includes.uniq end |
#ingest_includes(filepath, includes) ⇒ Object
Unlike other ingest() calls, ingest_includes() can be called externally.
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/ceedling/test_context_extractor.rb', line 197 def ingest_includes(filepath, includes) mock_prefix = @configurator.cmock_mock_prefix file_key = form_file_key( filepath ) 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)}/) 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 all_headers << include # <*.c> elsif include =~ /#{Regexp.escape(@configurator.extension_source)}$/ # Add to .c includes list sources << include end end @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 end |
#inspect_include_paths ⇒ Object
190 191 192 193 194 |
# File 'lib/ceedling/test_context_extractor.rb', line 190 def inspect_include_paths @lock.synchronize do @include_paths.each { |test, paths| yield test, paths } end end |
#lookup_all_include_paths ⇒ Object
182 183 184 185 186 187 188 |
# File 'lib/ceedling/test_context_extractor.rb', line 182 def lookup_all_include_paths val = nil @lock.synchronize do val = @all_include_paths.uniq end return val end |
#lookup_build_directive_sources_list(filepath) ⇒ Object
Source extras via TEST_SOURCE_FILE() within test file
143 144 145 146 147 148 149 |
# File 'lib/ceedling/test_context_extractor.rb', line 143 def lookup_build_directive_sources_list(filepath) val = nil @lock.synchronize do val = @source_extras[form_file_key( filepath )] || [] end return val end |
#lookup_full_header_includes_list(filepath) ⇒ Object
All header includes .h of test file
107 108 109 110 111 112 113 |
# File 'lib/ceedling/test_context_extractor.rb', line 107 def lookup_full_header_includes_list(filepath) val = nil @lock.synchronize do val = @all_header_includes[form_file_key( filepath )] || [] end return val end |
#lookup_header_includes_list(filepath) ⇒ Object
Header includes .h (minus mocks & framework headers) in test file
116 117 118 119 120 121 122 |
# File 'lib/ceedling/test_context_extractor.rb', line 116 def lookup_header_includes_list(filepath) val = nil @lock.synchronize do val = @header_includes[form_file_key( filepath )] || [] end return val end |
#lookup_include_paths_list(filepath) ⇒ Object
Include paths of test file specified with TEST_INCLUDE_PATH()
125 126 127 128 129 130 131 |
# File 'lib/ceedling/test_context_extractor.rb', line 125 def lookup_include_paths_list(filepath) val = nil @lock.synchronize do val = @include_paths[form_file_key( filepath )] || [] end return val end |
#lookup_raw_mock_list(filepath) ⇒ Object
Mocks within test file with no file extension
174 175 176 177 178 179 180 |
# File 'lib/ceedling/test_context_extractor.rb', line 174 def lookup_raw_mock_list(filepath) val = nil @lock.synchronize do val = @mocks[form_file_key( filepath )] || [] end return val end |
#lookup_source_includes_list(filepath) ⇒ Object
Source header_includes within test file
134 135 136 137 138 139 140 |
# File 'lib/ceedling/test_context_extractor.rb', line 134 def lookup_source_includes_list(filepath) val = nil @lock.synchronize do val = @source_includes[form_file_key( filepath )] || [] end return val end |
#lookup_test_cases(filepath) ⇒ Object
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/ceedling/test_context_extractor.rb', line 151 def lookup_test_cases(filepath) val = [] @lock.synchronize do details = @test_runner_details[form_file_key( filepath )] if !details.nil? val = details[:test_cases] end end return val end |
#lookup_test_runner_generator(filepath) ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/ceedling/test_context_extractor.rb', line 162 def lookup_test_runner_generator(filepath) val = nil @lock.synchronize do details = @test_runner_details[form_file_key( filepath )] if !details.nil? val = details[:generator] end end return val end |
#setup ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ceedling/test_context_extractor.rb', line 16 def setup # Per test-file lookup hashes @all_header_includes = {} # Full list of all headers from test #include statements @header_includes = {} # List of all headers minus mocks & framework files @source_includes = {} # List of C files #include'd in a test file @source_extras = {} # C source files outside of header convention added to test build by TEST_SOURCE_FILE() @test_runner_details = {} # Test case lists & Unity runner generator instances @mocks = {} # List of mocks by name without header file extension @include_paths = {} # Additional search paths added to a test build via TEST_INCLUDE_PATH() # Arrays @all_include_paths = [] # List of all search paths added through individual test files using TEST_INCLUDE_PATH() @lock = Mutex.new end |