Skip to content

Commit a75f16a

Browse files
committed
Env vars to escalate certain files not being discovered during CI
1 parent 119172b commit a75f16a

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99
### Added
1010
- `ensure_arduino_installation.rb` now ensures the existence of the library directory as well
11+
- Environment variables to escalate unit tests or examples not being found during CI testing
1112

1213
### Changed
1314
- Conserve CI testing minutes by grouping CI into fewer runs

REFERENCE.md

+11
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,22 @@ This completely skips the compilation tests (of library examples) portion of the
3333

3434
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`.
3535

36+
3637
### `--testfile-reject` option
3738

3839
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.
3940

4041

42+
### `EXPECT_UNITTESTS` environment variable
43+
44+
If set, testing will fail if no unit test files are detected (or if the directory does not exist). This is to avoid communicating a passing status in cases where a commit may have accidentally moved or deleted the test files.
45+
46+
47+
### `EXPECT_EXAMPLES` environment variable
48+
49+
If set, testing will fail if no example sketches are detected. This is to avoid communicating a passing status in cases where a commit may have accidentally moved or deleted the examples.
50+
51+
4152
## Indirectly Overriding Build Behavior (medium term use), and Advanced Options
4253

4354
For build behavior that you'd like to persist across commits (e.g. defining the set of platforms to test against, disabling a test that you expect to re-enable at some future point), a special configuration file called `.arduino-ci.yml` can be used. There are 3 places you can put them:

exe/arduino_ci.rb

+25-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
WIDTH = 80
88
FIND_FILES_INDENT = 4
9+
VAR_EXPECT_EXAMPLES = "EXPECT_EXAMPLES".freeze
10+
VAR_EXPECT_UNITTESTS = "EXPECT_UNITTESTS".freeze
911

1012
@failure_count = 0
1113
@passfail = proc { |result| result ? "✓" : "✗" }
@@ -48,6 +50,10 @@ def self.parse(options)
4850

4951
opts.on("-h", "--help", "Prints this help") do
5052
puts opts
53+
puts
54+
puts "Additionally, the following environment variables control the script:"
55+
puts " - #{VAR_EXPECT_EXAMPLES} - if set, testing will fail if no example sketches are present"
56+
puts " - #{VAR_EXPECT_UNITTESTS} - if set, testing will fail if no unit tests are present"
5157
exit
5258
end
5359
end
@@ -189,6 +195,23 @@ def install_arduino_library_dependencies(library_names, on_behalf_of, already_in
189195
installed
190196
end
191197

198+
def handle_expectation_of_files(expectation_envvar, operation, filegroup_name, dir_description, dir)
199+
if ENV[expectation_envvar].nil?
200+
inform_multiline("Skipping #{operation}; no #{filegroup_name} were found in #{dir}") do
201+
puts " In case that's an error, this is what was found in the #{dir_description}:"
202+
display_files(dir)
203+
puts "To force an error in this case, set the environment variable #{expectation_envvar}"
204+
true
205+
end
206+
else
207+
assure_multiline("No #{filegroup_name} were found in #{dir} and #{expectation_envvar} was set") do
208+
puts " This is what was found in the #{dir_description}:"
209+
display_files(dir)
210+
false
211+
end
212+
end
213+
end
214+
192215
def perform_unit_tests(cpp_library, file_config)
193216
if @cli_options[:skip_unittests]
194217
inform("Skipping unit tests") { "as requested via command line" }
@@ -239,11 +262,7 @@ def perform_unit_tests(cpp_library, file_config)
239262
end
240263
end
241264
elsif cpp_library.test_files.empty?
242-
inform_multiline("Skipping unit tests; no test files were found in #{cpp_library.tests_dir}") do
243-
puts " In case that's an error, this is what was found in the tests directory:"
244-
display_files(cpp_library.tests_dir)
245-
true
246-
end
265+
handle_expectation_of_files(VAR_EXPECT_UNITTESTS, "unit tests", "test files", "tests directory", cpp_library.tests_dir)
247266
elsif config.platforms_to_unittest.empty?
248267
inform("Skipping unit tests") { "no platforms were requested" }
249268
else
@@ -337,9 +356,7 @@ def perform_example_compilation_tests(cpp_library, config)
337356
inform("Skipping builds") { "no platforms were requested" }
338357
return
339358
elsif library_examples.empty?
340-
inform_multiline("Skipping builds; no examples found in #{installed_library_path}") do
341-
display_files(installed_library_path)
342-
end
359+
handle_expectation_of_files(VAR_EXPECT_EXAMPLES, "builds", "examples", "the library directory", installed_library_path)
343360
return
344361
end
345362

0 commit comments

Comments
 (0)