Skip to content

Commit f623be4

Browse files
committed
Fix bugs and other issues in contributed code
1 parent 3cf5dfc commit f623be4

File tree

8 files changed

+54
-21
lines changed

8 files changed

+54
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99
### Added
10+
- Unit testing configuration now allows `exclude_dirs` to be set, which prevents stray source files from as part of unit testing allows
1011

1112
### Changed
1213

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
#include "test-something.h"
2-
int testSomething(void) {
3-
millis(); // this line is only here to test that we're able to refer to the builtins
4-
return 4;
5-
};
1+
This file intentionally contains syntactically incorrect code
2+
to break unit test compilation. If arduino_ci is working
3+
properly, it should exclude this file (as per .arduino-ci.yml
4+
configuration) and unit test compilation should succeed.
65

7-
int* aNullPointer(void) {
8-
int* ret = nullptr;
9-
return ret;
10-
}
6+
~!@#$%^&*()
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#pragma once
2-
#include <Arduino.h>
3-
int testSomething(void);
4-
int *aNullPointer(void);
1+
This file intentionally contains syntactically incorrect code
2+
to break unit test compilation. If arduino_ci is working
3+
properly, it should exclude this file (as per .arduino-ci.yml
4+
configuration) and unit test compilation should succeed.
5+
6+
~!@#$%^&*()

exe/arduino_ci_remote.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ def perform_unit_tests(file_config)
183183
return
184184
end
185185
config = file_config.with_override_config(@cli_options[:ci_config])
186-
cpp_library = ArduinoCI::CppLibrary.new(Pathname.new("."), @arduino_cmd.lib_dir, config.exclude_dirs)
186+
cpp_library = ArduinoCI::CppLibrary.new(Pathname.new("."),
187+
@arduino_cmd.lib_dir,
188+
config.exclude_dirs.map(&Pathname.method(:new)))
187189

188190
# check GCC
189191
compilers = config.compilers_to_use

lib/arduino_ci/cpp_library.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ class CppLibrary
3737

3838
# @param base_dir [Pathname] The path to the library being tested
3939
# @param arduino_lib_dir [Pathname] The path to the libraries directory
40-
def initialize(base_dir, arduino_lib_dir, exclude_dirs = [])
40+
# @param exclude_dirs [Array<Pathname>] Directories that should be excluded from compilation
41+
def initialize(base_dir, arduino_lib_dir, exclude_dirs)
4142
raise ArgumentError, 'base_dir is not a Pathname' unless base_dir.is_a? Pathname
4243
raise ArgumentError, 'arduino_lib_dir is not a Pathname' unless arduino_lib_dir.is_a? Pathname
43-
raise ArgumentError, 'exclude_dir is not an array of Pathnames' unless exclude_dirs.is_a?(Array) &&
44-
exclude_dirs.each { |p| p.is_a? Pathname }
44+
raise ArgumentError, 'exclude_dir is not an array of Pathnames' unless exclude_dirs.is_a?(Array)
45+
raise ArgumentError, 'exclude_dir array contains non-Pathname elements' unless exclude_dirs.all? { |p| p.is_a? Pathname }
4546

4647
@base_dir = base_dir
4748
@exclude_dirs = exclude_dirs

spec/ci_config_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@
157157

158158
context "allowable_unittest_files" do
159159
cpp_lib_path = Pathname.new(__dir__) + "fake_library"
160-
cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path, Pathname.new("my_fake_arduino_lib_dir"))
160+
cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path, Pathname.new("my_fake_arduino_lib_dir"), [])
161161

162162
it "starts with a known set of files" do
163163
expect(cpp_library.test_files.map { |f| File.basename(f) }).to match_array([
@@ -177,4 +177,3 @@
177177
end
178178

179179
end
180-

spec/cpp_library_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def get_relative_dir(sampleprojects_tests_dir)
1313
RSpec.describe ArduinoCI::CppLibrary do
1414
next if skip_ruby_tests
1515
cpp_lib_path = sampleproj_path + "DoSomething"
16-
cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path, Pathname.new("my_fake_arduino_lib_dir"))
16+
cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path, Pathname.new("my_fake_arduino_lib_dir"), [])
1717
context "cpp_files" do
1818
it "finds cpp files in directory" do
1919
dosomething_cpp_files = [Pathname.new("DoSomething") + "do-something.cpp"]

spec/testsomething_unittests_spec.rb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,44 @@ def get_relative_dir(sampleprojects_tests_dir)
1010
sampleprojects_tests_dir.relative_path_from(base_dir)
1111
end
1212

13+
RSpec.describe "TestSomething C++ without excludes" do
14+
next if skip_cpp_tests
15+
cpp_lib_path = sampleproj_path + "TestSomething"
16+
cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path,
17+
Pathname.new("my_fake_arduino_lib_dir"),
18+
[])
19+
context "cpp_files" do
20+
it "finds cpp files in directory" do
21+
testsomething_cpp_files = [
22+
Pathname.new("TestSomething/test-something.cpp"),
23+
Pathname.new("TestSomething/excludeThis/exclude-this.cpp")
24+
]
25+
relative_paths = cpp_library.cpp_files.map { |f| get_relative_dir(f) }
26+
expect(relative_paths).to match_array(testsomething_cpp_files)
27+
end
28+
end
29+
30+
context "unit tests" do
31+
it "can't build due to files that should have been excluded" do
32+
config = ArduinoCI::CIConfig.default.from_example(cpp_lib_path)
33+
path = config.allowable_unittest_files(cpp_library.test_files).first
34+
compiler = config.compilers_to_use.first
35+
result = cpp_library.build_for_test_with_configuration(path,
36+
[],
37+
compiler,
38+
config.gcc_config("uno"))
39+
expect(result).to be nil
40+
end
41+
end
42+
43+
end
44+
1345
RSpec.describe "TestSomething C++" do
1446
next if skip_cpp_tests
1547
cpp_lib_path = sampleproj_path + "TestSomething"
1648
cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path,
1749
Pathname.new("my_fake_arduino_lib_dir"),
18-
["excludeThis"])
50+
["excludeThis"].map(&Pathname.method(:new)))
1951
context "cpp_files" do
2052
it "finds cpp files in directory" do
2153
testsomething_cpp_files = [Pathname.new("TestSomething/test-something.cpp")]

0 commit comments

Comments
 (0)