Skip to content

Commit 7ae62ae

Browse files
committed
Fix unit tests for source directory exclusion
1 parent acf84ee commit 7ae62ae

12 files changed

+95
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
unittest:
2+
exclude_dirs:
3+
- src/excludeThis
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ExcludeSomething
2+
3+
This example exists to test directory-exclusion code of ArduinoCI
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=TestSomething
2+
version=0.1.0
3+
author=Ian Katz <[email protected]>
4+
maintainer=Ian Katz <[email protected]>
5+
sentence=Arduino CI unit test example
6+
paragraph=A skeleton library demonstrating file exclusion
7+
category=Other
8+
url=https://github.com/Arduino-CI/arduino_ci/SampleProjects/ExcludeSomething
9+
architectures=avr,esp8266
10+
includes=do-something.h
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "exclude-something.h"
2+
int excludeSomething(void) {
3+
return -1;
4+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
#include <Arduino.h>
3+
int excludeSomething(void);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
~!@#$%^&*()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
~!@#$%^&*()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include <ArduinoUnitTests.h>
2+
3+
unittest(nothing)
4+
{
5+
}
6+
7+
unittest_main()

SampleProjects/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Because of this, these projects include some intentional quirks that differ from
1212
* "OnePointFiveMalformed" is a non-functional library meant to test file inclusion logic on libraries that attempt to conform to the ["1.5" specfication](https://arduino.github.io/arduino-cli/latest/library-specification/) but fail to include a `src` directory
1313
* "OnePointFiveDummy" is a non-functional library meant to test file inclusion logic on libraries conforming to the ["1.5" specfication](https://arduino.github.io/arduino-cli/latest/library-specification/)
1414
* "DependOnSomething" is a non-functional library meant to test file inclusion logic with dependencies
15+
* "ExcludeSomething" is a non-functional library meant to test directory exclusion logic

SampleProjects/TestSomething/.arduino-ci.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
unittest:
2-
exclude_dirs:
3-
- src/excludeThis
42
platforms:
53
- uno
64
- due

spec/cpp_library_spec.rb

+52
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,58 @@ def get_relative_dir(sampleprojects_tests_dir)
1010
sampleprojects_tests_dir.relative_path_from(base_dir)
1111
end
1212

13+
14+
RSpec.describe "ExcludeSomething C++" do
15+
next if skip_cpp_tests
16+
17+
cpp_lib_path = sampleproj_path + "ExcludeSomething"
18+
context "without excludes" do
19+
cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path,
20+
Pathname.new("my_fake_arduino_lib_dir"),
21+
[])
22+
context "cpp_files" do
23+
it "finds cpp files in directory" do
24+
excludesomething_cpp_files = [
25+
Pathname.new("ExcludeSomething/src/exclude-something.cpp"),
26+
Pathname.new("ExcludeSomething/src/excludeThis/exclude-this.cpp")
27+
]
28+
relative_paths = cpp_library.cpp_files.map { |f| get_relative_dir(f) }
29+
expect(relative_paths).to match_array(excludesomething_cpp_files)
30+
end
31+
end
32+
33+
context "unit tests" do
34+
it "can't build due to files that should have been excluded" do
35+
config = ArduinoCI::CIConfig.default.from_example(cpp_lib_path)
36+
path = config.allowable_unittest_files(cpp_library.test_files).first
37+
compiler = config.compilers_to_use.first
38+
result = cpp_library.build_for_test_with_configuration(path,
39+
[],
40+
compiler,
41+
config.gcc_config("uno"))
42+
expect(result).to be nil
43+
end
44+
end
45+
end
46+
47+
context "with excludes" do
48+
cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path,
49+
Pathname.new("my_fake_arduino_lib_dir"),
50+
["src/excludeThis"].map(&Pathname.method(:new)))
51+
context "cpp_files" do
52+
it "finds cpp files in directory" do
53+
excludesomething_cpp_files = [
54+
Pathname.new("ExcludeSomething/src/exclude-something.cpp")
55+
]
56+
relative_paths = cpp_library.cpp_files.map { |f| get_relative_dir(f) }
57+
expect(relative_paths).to match_array(excludesomething_cpp_files)
58+
end
59+
end
60+
61+
end
62+
63+
end
64+
1365
RSpec.describe ArduinoCI::CppLibrary do
1466
next if skip_ruby_tests
1567

spec/testsomething_unittests_spec.rb

-31
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,6 @@ 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/src/test-something.cpp"),
23-
Pathname.new("TestSomething/src/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
4413

4514
RSpec.describe "TestSomething C++" do
4615
next if skip_cpp_tests

0 commit comments

Comments
 (0)