|
2 | 2 | require 'arduino_ci'
|
3 | 3 | require 'set'
|
4 | 4 | require 'pathname'
|
| 5 | +require 'optparse' |
5 | 6 |
|
6 | 7 | WIDTH = 80
|
7 | 8 | FIND_FILES_INDENT = 4
|
8 | 9 |
|
9 | 10 | @failure_count = 0
|
10 | 11 | @passfail = proc { |result| result ? "✓" : "✗" }
|
11 | 12 |
|
| 13 | +# Use some basic parsing to allow command-line overrides of config |
| 14 | +class Parser |
| 15 | + def self.parse(options) |
| 16 | + parsed_config = {} |
| 17 | + parsed_config["unittest"] = {} |
| 18 | + |
| 19 | + opt_parser = OptionParser.new do |opts| |
| 20 | + opts.banner = "Usage: #{File.basename(__FILE__)} [options]" |
| 21 | + |
| 22 | + opts.on("--testfile-select=GLOB", "Unit test file (or glob) to select") do |p| |
| 23 | + parsed_config["unittest"]["testfiles"] ||= {} |
| 24 | + parsed_config["unittest"]["testfiles"]["select"] ||= [] |
| 25 | + parsed_config["unittest"]["testfiles"]["select"] << p |
| 26 | + end |
| 27 | + |
| 28 | + opts.on("--testfile-reject=GLOB", "Unit test file (or glob) to reject") do |p| |
| 29 | + parsed_config["unittest"]["testfiles"] ||= {} |
| 30 | + parsed_config["unittest"]["testfiles"]["reject"] ||= [] |
| 31 | + parsed_config["unittest"]["testfiles"]["reject"] << p |
| 32 | + end |
| 33 | + |
| 34 | + opts.on("-h", "--help", "Prints this help") do |
| 35 | + puts opts |
| 36 | + exit |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + opt_parser.parse!(options) |
| 41 | + parsed_config |
| 42 | + end |
| 43 | +end |
| 44 | + |
| 45 | +# Read in command line options and make them read-only |
| 46 | +@cli_options = (Parser.parse ARGV).freeze |
| 47 | + |
12 | 48 | # terminate after printing any debug info. TODO: capture debug info
|
13 | 49 | def terminate(final = nil)
|
14 | 50 | puts "Failures: #{@failure_count}"
|
@@ -117,7 +153,10 @@ def display_files(pathname)
|
117 | 153 | non_hidden.each { |p| puts "#{margin}#{p}" }
|
118 | 154 | end
|
119 | 155 |
|
120 |
| -def perform_unit_tests(config) |
| 156 | +def perform_unit_tests(file_config) |
| 157 | + puts file_config.to_h[:unittest].to_s |
| 158 | + config = file_config.with_override_config(@cli_options) |
| 159 | + puts config.to_h[:unittest].to_s |
121 | 160 | cpp_library = ArduinoCI::CppLibrary.new(Pathname.new("."), @arduino_cmd.lib_dir)
|
122 | 161 |
|
123 | 162 | # check GCC
|
@@ -155,7 +194,7 @@ def perform_unit_tests(config)
|
155 | 194 | inform("Skipping unit tests") { "no platforms were requested" }
|
156 | 195 | else
|
157 | 196 | config.platforms_to_unittest.each do |p|
|
158 |
| - cpp_library.test_files.each do |unittest_path| |
| 197 | + config.allowable_unittest_files(cpp_library.test_files).each do |unittest_path| |
159 | 198 | unittest_name = unittest_path.basename.to_s
|
160 | 199 | compilers.each do |gcc_binary|
|
161 | 200 | attempt_multiline("Unit testing #{unittest_name} with #{gcc_binary}") do
|
|
0 commit comments