Skip to content

Commit 7e3a8a4

Browse files
committed
Add support for pre/post unit test run scripts
1 parent 39a5901 commit 7e3a8a4

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
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1717
- Added support for `ARDUINO_CI_UNIT_TEST_EXTRA_COMPILER_FLAGS` environment variable.
1818
- Added support for overriding the shell used to execute `CUSTOM_INIT_SCRIPT`
1919
by setting `CUSTOM_INIT_SCRIPT_SHELL` (defaults to `/bin/sh`).
20+
- Added support running scripts before and/or after each run of unit tests with
21+
`ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT` and `ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT`.
2022

2123
### Changed
2224
- We now compile a shared library to be used for each test.

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
@@ -9,6 +9,8 @@
99
VAR_USE_SUBDIR = "USE_SUBDIR".freeze
1010
VAR_EXPECT_EXAMPLES = "EXPECT_EXAMPLES".freeze
1111
VAR_EXPECT_UNITTESTS = "EXPECT_UNITTESTS".freeze
12+
VAR_ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT = "ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT".freeze
13+
VAR_ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT = "ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT".freeze
1214

1315
@failure_count = 0
1416
@passfail = proc { |result| result ? "✓" : "✗" }
@@ -62,6 +64,8 @@ def self.parse(options)
6264
puts " prior to any automated library installation or testing (e.g. to install unofficial libraries)"
6365
puts " - #{VAR_CUSTOM_INIT_SCRIPT_SHELL} - if set, this will override the"
6466
puts " default shell (/bin/sh) used to execute #{VAR_CUSTOM_INIT_SCRIPT} with."
67+
puts " - #{VAR_ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT} and/or #{VAR_ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT}"
68+
puts " if set, run the script before/after each unit test run"
6569
puts " - #{VAR_USE_SUBDIR} - if set, the script will install the library from this subdirectory of the cwd"
6670
puts " - #{VAR_EXPECT_EXAMPLES} - if set, testing will fail if no example sketches are present"
6771
puts " - #{VAR_EXPECT_UNITTESTS} - if set, testing will fail if no unit tests are present"
@@ -425,6 +429,7 @@ def perform_unit_tests(cpp_library, file_config)
425429
platforms.each do |p|
426430
puts
427431
compilers.each do |gcc_binary|
432+
run_custom_script(VAR_ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT, p, gcc_binary)
428433
# before compiling the tests, build a shared library of everything except the test code
429434
next unless build_shared_library(gcc_binary, p, config, cpp_library)
430435

@@ -444,6 +449,7 @@ def perform_unit_tests(cpp_library, file_config)
444449
cpp_library.run_test_file(exe)
445450
end
446451
end
452+
run_custom_script(VAR_ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT, p, gcc_binary)
447453
end
448454
end
449455
end

0 commit comments

Comments
 (0)