Skip to content

Commit 32f80c4

Browse files
committed
separate example project for CI from example project for rspec
1 parent 9dc9d4e commit 32f80c4

File tree

12 files changed

+120
-28
lines changed

12 files changed

+120
-28
lines changed

SampleProjects/TestSomething/Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source 'https://rubygems.org'
2+
gem 'arduino_ci', path: '../../'
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
PATH
2+
remote: /Users/ikatz/Development/non-wayfair/arduino_ci
3+
specs:
4+
arduino_ci (0.0.1)
5+
os (~> 1.0)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
os (1.0.0)
11+
12+
PLATFORMS
13+
ruby
14+
15+
DEPENDENCIES
16+
arduino_ci!
17+
18+
BUNDLED WITH
19+
1.16.0
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# TestSomething
2+
3+
This is a "beater" example that is referenced by tests of the Arduino CI module itself.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <test-something.h>
2+
// if it seems bare, that's because it's only meant to
3+
// demonstrate compilation -- that references work
4+
void setup() {
5+
}
6+
7+
void loop() {
8+
testSomething();
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=arduino-ci-unit-tests
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 CI and unit tests
7+
category=Other
8+
url=https://github.com/ifreecarve/arduino_ci/SampleProjects/DoSomething
9+
architectures=avr,esp8266
10+
includes=do-something.h
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#pragma once
2+
#include <Arduino.h>
3+
int testSomething(void);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <ArduinoUnitTests.h>
2+
#include "../test-something.h"
3+
4+
unittest(library_tests_something)
5+
{
6+
assertEqual(4, testSomething());
7+
}
8+
9+
int main(int argc, char *argv[]) {
10+
return Test::run_and_report(argc, argv);
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <ArduinoUnitTests.h>
2+
3+
unittest(equality_as_vars)
4+
{
5+
int x = 3;
6+
int y = 3;
7+
int z = 3;
8+
assertEqual(x, y);
9+
assertEqual(x, z);
10+
}
11+
12+
unittest(equality_as_values)
13+
{
14+
assertEqual(1, 1);
15+
assertEqual(4, 4);
16+
}
17+
18+
unittest(nothing)
19+
{
20+
}
21+
22+
int main(int argc, char *argv[]) {
23+
return Test::run_and_report(argc, argv);
24+
}

lib/arduino_ci/cpp_library.rb

+2-12
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,7 @@ def test_args(aux_libraries, ci_gcc_config)
123123
ret
124124
end
125125

126-
# run a test of the given unit test file
127-
def test_with_configuration(test_file, aux_libraries, ci_gcc_config)
128-
executable = build_for_test_with_configuration(test_file, aux_libraries, ci_gcc_config)
129-
run_test_file(executable)
130-
end
131-
132-
# run a test of the given unit test file
126+
# build a file for running a test of the given unit test file
133127
def build_for_test_with_configuration(test_file, aux_libraries, ci_gcc_config)
134128
base = File.basename(test_file)
135129
executable = File.expand_path("unittest_#{base}.bin")
@@ -140,15 +134,11 @@ def build_for_test_with_configuration(test_file, aux_libraries, ci_gcc_config)
140134
executable
141135
end
142136

137+
# run a test file
143138
def run_test_file(executable)
144139
Host.run(executable)
145140
end
146141

147-
# legacy shortcut for rspec
148-
def test(test_file)
149-
test_with_configuration(test_file, [], nil)
150-
end
151-
152142
end
153143

154144
end

spec/cpp_library_spec.rb

+32-16
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,67 @@
33
sampleproj_path = File.join(File.dirname(File.dirname(__FILE__)), "SampleProjects")
44

55
RSpec.describe ArduinoCI::CppLibrary do
6-
cpp_lib_path = File.join(sampleproj_path, "DoSomething")
6+
cpp_lib_path = File.join(sampleproj_path, "TestSomething")
77
cpp_library = ArduinoCI::CppLibrary.new(cpp_lib_path)
88
context "cpp_files" do
99
it "finds cpp files in directory" do
10-
dosomething_cpp_files = ["DoSomething/do-something.cpp"]
10+
testsomething_cpp_files = ["TestSomething/test-something.cpp"]
1111
relative_paths = cpp_library.cpp_files.map { |f| f.split("SampleProjects/", 2)[1] }
12-
expect(relative_paths).to match_array(dosomething_cpp_files)
12+
expect(relative_paths).to match_array(testsomething_cpp_files)
1313
end
1414
end
1515

1616
context "header_dirs" do
1717
it "finds directories containing h files" do
18-
dosomething_header_dirs = ["DoSomething"]
18+
testsomething_header_dirs = ["TestSomething"]
1919
relative_paths = cpp_library.header_dirs.map { |f| f.split("SampleProjects/", 2)[1] }
20-
expect(relative_paths).to match_array(dosomething_header_dirs)
20+
expect(relative_paths).to match_array(testsomething_header_dirs)
2121
end
2222
end
2323

2424
context "tests_dir" do
2525
it "locate the tests directory" do
26-
dosomething_header_dirs = ["DoSomething"]
26+
testsomething_header_dirs = ["TestSomething"]
2727
relative_path = cpp_library.tests_dir.split("SampleProjects/", 2)[1]
28-
expect(relative_path).to eq("DoSomething/test")
28+
expect(relative_path).to eq("TestSomething/test")
2929
end
3030
end
3131

3232
context "test_files" do
3333
it "finds cpp files in directory" do
34-
dosomething_test_files = [
35-
"DoSomething/test/good-null.cpp",
36-
"DoSomething/test/good-library.cpp",
37-
"DoSomething/test/bad-null.cpp"
34+
testsomething_test_files = [
35+
"TestSomething/test/good-null.cpp",
36+
"TestSomething/test/good-library.cpp",
37+
"TestSomething/test/bad-null.cpp"
3838
]
3939
relative_paths = cpp_library.test_files.map { |f| f.split("SampleProjects/", 2)[1] }
40-
expect(relative_paths).to match_array(dosomething_test_files)
40+
expect(relative_paths).to match_array(testsomething_test_files)
4141
end
4242
end
4343

4444
context "test" do
45-
arduino_cmd = ArduinoCI::ArduinoInstallation.autolocate!
46-
it "tests libraries" do
45+
after(:each) do |example|
46+
if example.exception
47+
puts "Last command: #{cpp_library.last_cmd}"
48+
puts "========== Stdout:"
49+
puts cpp_library.last_out
50+
puts "========== Stderr:"
51+
puts cpp_library.last_err
52+
end
53+
end
54+
55+
it "is going to test more than one library" do
4756
test_files = cpp_library.test_files
4857
expect(test_files.empty?).to be false
49-
test_files.each do |path|
50-
expect(cpp_library.test(path)).to eq(path.include?("good"))
58+
end
59+
60+
test_files = cpp_library.test_files
61+
test_files.each do |path|
62+
expected = path.include?("good")
63+
it "tests #{File.basename(path)} expecting #{expected}" do
64+
exe = cpp_library.build_for_test_with_configuration(path, [], nil)
65+
expect(exe).not_to be nil
66+
expect(cpp_library.run_test_file(exe)).to eq(expected)
5167
end
5268
end
5369
end

0 commit comments

Comments
 (0)