Skip to content

Commit 8a4ecdf

Browse files
committed
add ability to slim list of unit tests
1 parent e8d6246 commit 8a4ecdf

File tree

7 files changed

+46
-0
lines changed

7 files changed

+46
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77
## [Unreleased]
88
### Added
99
- Yaml files can have either `.yml` or `.yaml` extensions
10+
- Yaml files support select/reject critera for paths of unit tests for targeted testing
1011

1112
### Changed
1213

lib/arduino_ci/ci_config.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
UNITTEST_SCHEMA = {
2828
platforms: Array,
2929
libraries: Array,
30+
testfiles: {
31+
select: Array,
32+
reject: Array,
33+
}
3034
}.freeze
3135
module ArduinoCI
3236

@@ -223,6 +227,21 @@ def aux_libraries_for_unittest
223227
@unittest_info[:libraries]
224228
end
225229

230+
# Config allows select / reject (aka whitelist / blacklist) criteria. Enforce on a dir
231+
# @param paths [Array<String>] the initial set of test files
232+
# @return [Array<String>] files that match the select/reject criteria
233+
def allowable_unittest_files(paths)
234+
return if @unittest_info[:testfiles].nil?
235+
ret = paths
236+
unless @unittest_info[:testfiles][:select].nil? || @unittest_info[:testfiles][:select].empty?
237+
ret = ret.select { |p| unittest_info[:testfiles][:select].any? { |glob| File.fnmatch(glob, File.basename(p)) } }
238+
end
239+
unless @unittest_info[:testfiles][:reject].nil?
240+
ret = ret.reject { |p| unittest_info[:testfiles][:reject].any? { |glob| File.fnmatch(glob, File.basename(p)) } }
241+
end
242+
ret
243+
end
244+
226245
# get GCC configuration for a given platform
227246
# @param platform_name [String] The name of the platform as defined in yaml
228247
# @return [Hash] the settings

spec/ci_config_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,26 @@
6666
end
6767
end
6868

69+
context "allowable_unittest_files" do
70+
cpp_lib_path = File.join(File.dirname(__FILE__), "fake_library")
71+
cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path)
72+
73+
it "starts with a known set of files" do
74+
expect(cpp_library.test_files.map { |f| File.basename(f) }).to match_array([
75+
"sam-squamsh.cpp",
76+
"yes-good.cpp",
77+
"mars.cpp"
78+
])
79+
end
80+
81+
it "filters that set of files" do
82+
override_file = File.join(File.dirname(__FILE__), "yaml", "o1.yaml")
83+
combined_config = ArduinoCI::CIConfig.default.with_override(override_file)
84+
expect(combined_config.allowable_unittest_files(cpp_library.test_files).map { |f| File.basename(f) }).to match_array([
85+
"yes-good.cpp",
86+
])
87+
end
88+
end
89+
6990
end
7091

spec/fake_library/test/mars.cpp

Whitespace-only changes.

spec/fake_library/test/sam-squamsh.cpp

Whitespace-only changes.

spec/fake_library/test/yes-good.cpp

Whitespace-only changes.

spec/yaml/o1.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ compile:
3232
- esp8266
3333

3434
unittest:
35+
testfiles:
36+
select:
37+
- "*-*.*"
38+
reject:
39+
- "sam-squamsh.*"
3540
libraries:
3641
- "abc123"
3742
- "def456"

0 commit comments

Comments
 (0)