Skip to content

Commit 4fbb472

Browse files
committed
re-enable and expand selection and rejection of test files
1 parent d815750 commit 4fbb472

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- `to_h` and `to_s` functions for `ci_config.rb`
1111
- `CIConfig::clone`
1212
- Ability to override `CIConfig` from a hash instead of just a file
13+
- `arduino_ci_remote.rb` now supports command line switches `--testfile-select=GLOB` and `--testfile-reject=GLOB` (which can both be repeated)
1314

1415
### Changed
1516
- Simplified the use of `Array.each` with a return statement; it's now simply `Array.find`
@@ -22,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2223

2324
### Fixed
2425
- Determining a working OSX launch command no longer breaks on non-English installations
26+
- `arduino_ci_remote.rb` now honors selected and rejected test files
2527

2628
### Security
2729

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ source 'https://rubygems.org'
3434
gem 'arduino_ci'
3535
```
3636

37+
### Testing Locally
38+
39+
First, pull in the `arduino_ci` library as a dependency.
40+
41+
```
42+
$ bundle install
43+
```
44+
45+
46+
With that installed, just the following shell command each time you want the tests to execute:
47+
48+
```
49+
$ bundle exec arduino_ci_remote.rb
50+
```
51+
52+
53+
54+
### Testing with remote CI
55+
3756
> **Note:** `arduino_ci_remote.rb` expects to be run from the root directory of your Arduino project library.
3857
3958

REFERENCE.md

+22
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ These defaults are specified in [misc/default.yml](misc/default.yml). You are f
99

1010
## Overriding default build behavior
1111

12+
### From the command line
13+
14+
The following options are currently available in the `arduino_ci_remote.rb` test runner.
15+
16+
```
17+
Usage: arduino_ci_remote.rb [options]
18+
--testfile-select=GLOB Unit test file (or glob) to select
19+
--testfile-reject=GLOB Unit test file (or glob) to reject
20+
-h, --help Prints this help
21+
```
22+
23+
#### `--testfile-select` option
24+
25+
This allows a file (or glob) pattern to be executed in your tests directory, creating a whitelist of files to test. E.g. `--testfile-select=test_animal_*.cpp` would match `test_animal_cat.cpp` and `test_animal_dog.cpp` (testing only those) and not `test_plant_rose.cpp`.
26+
27+
#### `--testfile-reject` option
28+
29+
This allows a file (or glob) pattern to be executed in your tests directory, creating a blacklist of files to skip. E.g. `--testfile-reject=test_animal_*.cpp` would match `test_animal_cat.cpp` and `test_animal_dog.cpp` (skipping those) and test only `test_plant_rose.cpp`, `test_plant_daisy.cpp`, etc.
30+
31+
32+
### From configuration
33+
1234
`.arduino-ci.yml` files will override the default behavior. There are 3 places you can put them:
1335

1436
1. the root of your library

exe/arduino_ci_remote.rb

+41-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,49 @@
22
require 'arduino_ci'
33
require 'set'
44
require 'pathname'
5+
require 'optparse'
56

67
WIDTH = 80
78
FIND_FILES_INDENT = 4
89

910
@failure_count = 0
1011
@passfail = proc { |result| result ? "✓" : "✗" }
1112

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+
1248
# terminate after printing any debug info. TODO: capture debug info
1349
def terminate(final = nil)
1450
puts "Failures: #{@failure_count}"
@@ -117,7 +153,10 @@ def display_files(pathname)
117153
non_hidden.each { |p| puts "#{margin}#{p}" }
118154
end
119155

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
121160
cpp_library = ArduinoCI::CppLibrary.new(Pathname.new("."), @arduino_cmd.lib_dir)
122161

123162
# check GCC
@@ -155,7 +194,7 @@ def perform_unit_tests(config)
155194
inform("Skipping unit tests") { "no platforms were requested" }
156195
else
157196
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|
159198
unittest_name = unittest_path.basename.to_s
160199
compilers.each do |gcc_binary|
161200
attempt_multiline("Unit testing #{unittest_name} with #{gcc_binary}") do

0 commit comments

Comments
 (0)