Skip to content

Commit b46e1c9

Browse files
committed
Add information about skipping unnecessary tests
1 parent ddf67d2 commit b46e1c9

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

exe/arduino_ci.rb

+34-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
VAR_EXPECT_EXAMPLES = "EXPECT_EXAMPLES".freeze
1010
VAR_EXPECT_UNITTESTS = "EXPECT_UNITTESTS".freeze
1111

12+
CLI_SKIP_EXAMPLES_COMPILATION = "--skip-examples-compilation".freeze
13+
CLI_SKIP_UNITTESTS = "--skip-unittests".freeze
14+
1215
# script-level variables we'll use
1316
@log = nil
1417
@backend = nil
@@ -30,11 +33,11 @@ def self.parse(options)
3033
opt_parser = OptionParser.new do |opts|
3134
opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
3235

33-
opts.on("--skip-unittests", "Don't run unit tests") do |p|
36+
opts.on(CLI_SKIP_UNITTESTS, "Don't run unit tests") do |p|
3437
output_options[:skip_unittests] = p
3538
end
3639

37-
opts.on("--skip-examples-compilation", "Don't compile example sketches") do |p|
40+
opts.on(CLI_SKIP_EXAMPLES_COMPILATION, "Don't compile example sketches") do |p|
3841
output_options[:skip_compilation] = p
3942
end
4043

@@ -195,10 +198,11 @@ def install_all_packages(platforms, specific_config)
195198

196199
# @param expectation_envvar [String] the name of the env var to check
197200
# @param operation [String] a description of what operation we might be skipping
201+
# @param howto_skip [String] a description of how the runner can skip this
198202
# @param filegroup_name [String] a description of the set of files without which we effectively skip the operation
199203
# @param dir_description [String] a description of the directory where we looked for the files
200204
# @param dir [Pathname] the directory where we looked for the files
201-
def handle_expectation_of_files(expectation_envvar, operation, filegroup_name, dir_description, dir_path)
205+
def handle_expectation_of_files(expectation_envvar, operation, howto_skip, filegroup_name, dir_description, dir_path)
202206
# alert future me about running the script from the wrong directory, instead of doing the huge file dump
203207
# otherwise, assume that the user might be running the script on a library with no actual unit tests
204208
if Pathname.new(__dir__).parent == Pathname.new(Dir.pwd)
@@ -222,20 +226,22 @@ def handle_expectation_of_files(expectation_envvar, operation, filegroup_name, d
222226
end
223227

224228
@log.inform(problem) { dir_path }
225-
explain_and_exercise_envvar(expectation_envvar, operation, "contents of #{dir_desc}") { display_files(dir) }
229+
explain_and_exercise_envvar(expectation_envvar, operation, howto_skip, "contents of #{dir_desc}") { display_files(dir) }
226230
end
227231

228232
# @param expectation_envvar [String] the name of the env var to check
229233
# @param operation [String] a description of what operation we might be skipping
234+
# @param howto_skip [String] a description of how the runner can skip this
230235
# @param block_desc [String] a description of what information will be dumped to assist the user
231236
# @param block [Proc] a function that dumps information
232-
def explain_and_exercise_envvar(expectation_envvar, operation, block_desc, &block)
237+
def explain_and_exercise_envvar(expectation_envvar, operation, howto_skip, block_desc, &block)
233238
@log.inform("Environment variable #{expectation_envvar} is") { "(#{ENV[expectation_envvar].class}) #{ENV[expectation_envvar]}" }
234239
if ENV[expectation_envvar].nil?
235240
@log.inform_multiline("Skipping #{operation}") do
236241
@log.iputs "In case that's an error, displaying #{block_desc}:"
237242
block.call
238243
@log.iputs "To force an error in this case, set the environment variable #{expectation_envvar}"
244+
@log.iputs "To explicitly skip this check, use #{howto_skip}"
239245
true
240246
end
241247
else
@@ -410,14 +416,21 @@ def perform_unit_tests(cpp_library, file_config)
410416

411417
# Handle lack of test files
412418
if cpp_library.test_files.empty?
413-
handle_expectation_of_files(VAR_EXPECT_UNITTESTS, "unit tests", "test files", "tests directory", cpp_library.tests_dir)
419+
handle_expectation_of_files(
420+
VAR_EXPECT_UNITTESTS,
421+
"unit tests",
422+
CLI_SKIP_UNITTESTS,
423+
"test files",
424+
"tests directory",
425+
cpp_library.tests_dir
426+
)
414427
return
415428
end
416429

417430
# Get platforms, handle lack of them
418431
platforms = choose_platform_set(config, "unittest", config.platforms_to_unittest, cpp_library.library_properties)
419432
if platforms.empty?
420-
explain_and_exercise_envvar(VAR_EXPECT_UNITTESTS, "unit tests", "platforms and architectures") do
433+
explain_and_exercise_envvar(VAR_EXPECT_UNITTESTS, "unit tests", CLI_SKIP_UNITTESTS, "platforms and architectures") do
421434
@log.iputs "Configured platforms: #{config.platforms_to_unittest}"
422435
@log.iputs "Configuration is default: #{config.is_default}"
423436
arches = cpp_library.library_properties.nil? ? nil : cpp_library.library_properties.architectures
@@ -479,7 +492,14 @@ def perform_example_compilation_tests(cpp_library, config)
479492
library_examples = cpp_library.example_sketches
480493

481494
if library_examples.empty?
482-
handle_expectation_of_files(VAR_EXPECT_EXAMPLES, "builds", "examples", "the examples directory", cpp_library.examples_dir)
495+
handle_expectation_of_files(
496+
VAR_EXPECT_EXAMPLES,
497+
"builds",
498+
CLI_SKIP_EXAMPLES_COMPILATION,
499+
"examples",
500+
"the examples directory",
501+
cpp_library.examples_dir
502+
)
483503
return
484504
end
485505

@@ -498,7 +518,12 @@ def perform_example_compilation_tests(cpp_library, config)
498518

499519
# having no platforms defined is probably an error
500520
if platforms.empty?
501-
explain_and_exercise_envvar(VAR_EXPECT_EXAMPLES, "examples compilation", "platforms and architectures") do
521+
explain_and_exercise_envvar(
522+
VAR_EXPECT_EXAMPLES,
523+
"examples compilation",
524+
CLI_SKIP_EXAMPLES_COMPILATION,
525+
"platforms and architectures"
526+
) do
502527
@log.iputs "Configured platforms: #{ovr_config.platforms_to_build}"
503528
@log.iputs "Configuration is default: #{ovr_config.is_default}"
504529
arches = cpp_library.library_properties.nil? ? nil : cpp_library.library_properties.architectures

0 commit comments

Comments
 (0)