Skip to content

Commit 041dcb4

Browse files
committed
Allow testing from a subdirectory during CI testing
1 parent 4b4e6dd commit 041dcb4

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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
- Environment variable to run a custom initialization script during CI testing: `CUSTOM_INIT_SCRIPT`
11+
- Environment variable to run from a subdirectory during CI testing: `USE_SUBDIR`
1112

1213
### Changed
1314

REFERENCE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ This allows a file (or glob) pattern to be executed in your tests directory, cre
4444
If set, testing will execute (using `/bin/sh`) the script referred to by this variable -- relative to the current working directory. This enables use cases like the GitHub action to install custom library versions (i.e. a version of a library that is different than what the library manager would automatically install by name) prior to CI test runs.
4545

4646

47+
### `USE_SUBDIR` environment variable
48+
49+
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.
50+
51+
4752
### `EXPECT_UNITTESTS` environment variable
4853

4954
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.

exe/arduino_ci.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
WIDTH = 80
88
VAR_CUSTOM_INIT_SCRIPT = "CUSTOM_INIT_SCRIPT".freeze
9+
VAR_USE_SUBDIR = "USE_SUBDIR".freeze
910
VAR_EXPECT_EXAMPLES = "EXPECT_EXAMPLES".freeze
1011
VAR_EXPECT_UNITTESTS = "EXPECT_UNITTESTS".freeze
1112

@@ -54,6 +55,7 @@ def self.parse(options)
5455
puts "Additionally, the following environment variables control the script:"
5556
puts " - #{VAR_CUSTOM_INIT_SCRIPT} - if set, this script will be run from the Arduino/libraries directory"
5657
puts " prior to any automated library installation or testing (e.g. to install unoffical libraries)"
58+
puts " - #{VAR_USE_SUBDIR} - if set, the script will install the library from this subdirectory of the cwd"
5759
puts " - #{VAR_EXPECT_EXAMPLES} - if set, testing will fail if no example sketches are present"
5860
puts " - #{VAR_EXPECT_UNITTESTS} - if set, testing will fail if no unit tests are present"
5961
exit
@@ -424,8 +426,10 @@ def perform_example_compilation_tests(cpp_library, config)
424426
# run any library init scripts from the library itself.
425427
perform_custom_initialization(config)
426428

429+
427430
# initialize library under test
428-
cpp_library_path = Pathname.new(".")
431+
inform("Environment variable #{VAR_USE_SUBDIR}") { "'#{ENV[VAR_USE_SUBDIR]}'" }
432+
cpp_library_path = Pathname.new(ENV[VAR_USE_SUBDIR].nil? ? "." : ENV[VAR_USE_SUBDIR])
429433
cpp_library = assure("Installing library under test") do
430434
@backend.install_local_library(cpp_library_path)
431435
end

0 commit comments

Comments
 (0)