Skip to content

Commit 0887f9f

Browse files
committed
Add support for pre/post unit test run scripts
1 parent 4cd52f1 commit 0887f9f

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
@@ -62,6 +62,31 @@ action to install custom library versions (i.e. a version of a library that
6262
is different than what the library manager would automatically install by name)
6363
prior to CI test runs.
6464

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

6792
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"
@@ -444,6 +448,7 @@ def perform_unit_tests(cpp_library, file_config)
444448
platforms.each do |p|
445449
puts
446450
compilers.each do |gcc_binary|
451+
run_custom_script(VAR_ARDUINO_CI_PRE_UNIT_TEST_RUN_SCRIPT, p, gcc_binary)
447452
# before compiling the tests, build a shared library of everything except the test code
448453
next @failure_count += 1 unless build_shared_library(gcc_binary, p, config, cpp_library)
449454

@@ -463,6 +468,7 @@ def perform_unit_tests(cpp_library, file_config)
463468
cpp_library.run_test_file(exe)
464469
end
465470
end
471+
run_custom_script(VAR_ARDUINO_CI_POST_UNIT_TEST_RUN_SCRIPT, p, gcc_binary)
466472
end
467473
end
468474
end

0 commit comments

Comments
 (0)