Skip to content

Commit ff3c03b

Browse files
committed
Add support for pre/post unit test run scripts
1 parent 8599b12 commit ff3c03b

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111
- Added support for `ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS` environment variable.
1212
- Added support for overriding the shell used to execute `CUSTOM_INIT_SCRIPT`
1313
by setting `CUSTOM_INIT_SCRIPT_SHELL` (defaults to `/bin/sh`).
14+
- Added support running scripts before and/or after each run of unit tests with
15+
`ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT` and `ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT`.
1416

1517
### Changed
1618

Diff for: REFERENCE.md

+25
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ action to install custom library versions (i.e. a version of a library that
5757
is different than what the library manager would automatically install by name)
5858
prior to CI test runs.
5959

60+
### `ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT` and `ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT` environment variables
61+
62+
If set, the corresponding script will be run before/after each run of unit tests
63+
for each configured platform and for each compiler, e.g. if `.arduino-ci.yaml`
64+
contains
65+
66+
```yaml
67+
unittest:
68+
compilers:
69+
- g++-10
70+
- g++-11
71+
libraries: ~
72+
platforms:
73+
- leonardo
74+
- uno
75+
```
76+
77+
the scripts will be invoked four times, with the current platform name being
78+
tested as the first parameter to the script and the current compiler used as
79+
the second parameter. It is not necessary to define both PRE and POST script;
80+
if you only want to run something before or after unit tests that's fine.
81+
By default the scripts are executed by `/bin/sh`, you can override by setting
82+
`ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT_SHELL` and
83+
`ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT_SHELL` respectively.
84+
6085
### `USE_SUBDIR` environment variable
6186

6287
If set, testing will be conducted in this subdirectory (relative to the working directory). This is for monorepos or other layouts where the library directory and project root directory are different.

Diff for: exe/arduino_ci.rb

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
VAR_USE_SUBDIR = "USE_SUBDIR".freeze
1616
VAR_EXPECT_EXAMPLES = "EXPECT_EXAMPLES".freeze
1717
VAR_EXPECT_UNITTESTS = "EXPECT_UNITTESTS".freeze
18+
VAR_ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT = "ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT".freeze
19+
VAR_ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT = "ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT".freeze
1820

1921
@failure_count = 0
2022
@passfail = proc { |result| result ? "✓" : "✗" }
@@ -68,6 +70,8 @@ def self.parse(options)
6870
puts " prior to any automated library installation or testing (e.g. to install unofficial libraries)"
6971
puts " - #{VAR_CUSTOM_INIT_SCRIPT_SHELL} - if set, this will override the"
7072
puts " default shell (/bin/sh) used to execute #{VAR_CUSTOM_INIT_SCRIPT} with."
73+
puts " - #{VAR_ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT} and/or #{VAR_ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT}"
74+
puts " if set, run the script before/after each unit test run"
7175
puts " - #{VAR_USE_SUBDIR} - if set, the script will install the library from this subdirectory of the cwd"
7276
puts " - #{VAR_EXPECT_EXAMPLES} - if set, testing will fail if no example sketches are present"
7377
puts " - #{VAR_EXPECT_UNITTESTS} - if set, testing will fail if no unit tests are present"
@@ -438,6 +442,7 @@ def perform_unit_tests(cpp_library, file_config)
438442
platforms.each do |p|
439443
puts
440444
compilers.each do |gcc_binary|
445+
run_custom_script(VAR_ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT, p, gcc_binary)
441446
# before compiling the tests, build a shared library of everything except the test code
442447
next unless build_shared_library(gcc_binary, p, config, cpp_library)
443448

@@ -457,6 +462,7 @@ def perform_unit_tests(cpp_library, file_config)
457462
cpp_library.run_test_file(exe)
458463
end
459464
end
465+
run_custom_script(VAR_ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT, p, gcc_binary)
460466
end
461467
end
462468
end

0 commit comments

Comments
 (0)