Skip to content

Commit 25a89ba

Browse files
committed
Added a build-all sketch test
This test tries to build all the test sketch proposed in issues. A possible improvement is to find a way to easily add new sketch to the test suite, possibily without the need to change the source code in try_build_of_problematic_sketch_test.go maybe a "go generate" approach may be investigated in this case. Signed-off-by: Cristian Maglie <[email protected]>
1 parent dfd5f9b commit 25a89ba

File tree

1 file changed

+219
-0
lines changed

1 file changed

+219
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
/*
2+
* This file is part of Arduino Builder.
3+
*
4+
* Arduino Builder is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
28+
* Copyright 2015 Matthijs Kooijman
29+
*/
30+
31+
package test
32+
33+
import (
34+
"arduino.cc/builder"
35+
"arduino.cc/builder/constants"
36+
"os"
37+
"path/filepath"
38+
"testing"
39+
)
40+
41+
func TestTryBuild001(t *testing.T) {
42+
tryBuild(t, "sketch_with_inline_function", "sketch.ino")
43+
}
44+
45+
func TestTryBuild002(t *testing.T) {
46+
tryBuild(t, "sketch_with_function_signature_inside_ifdef", "sketch.ino")
47+
}
48+
49+
func TestTryBuild003(t *testing.T) {
50+
tryPreprocess(t, "sketch_no_functions", "main.ino")
51+
}
52+
53+
func TestTryBuild004(t *testing.T) {
54+
tryBuild(t, "sketch_with_const", "sketch.ino")
55+
}
56+
57+
func TestTryBuild005(t *testing.T) {
58+
tryBuild(t, "sketch_with_old_lib", "sketch.ino")
59+
}
60+
61+
func TestTryBuild006(t *testing.T) {
62+
tryBuild(t, "sketch_with_macosx_garbage", "sketch.ino")
63+
}
64+
65+
func TestTryBuild007(t *testing.T) {
66+
tryBuild(t, "sketch_with_config", "sketch_with_config.ino")
67+
}
68+
69+
// XXX: Failing sketch, typename not supported
70+
//func TestTryBuild008(t *testing.T) {
71+
// tryBuild(t, "sketch_with_typename", "sketch.ino")
72+
//}
73+
74+
func TestTryBuild009(t *testing.T) {
75+
tryBuild(t, "sketch_with_usbcon", "sketch.ino")
76+
}
77+
78+
func TestTryBuild010(t *testing.T) {
79+
tryBuild(t, "sketch_with_namespace", "sketch.ino")
80+
}
81+
82+
func TestTryBuild011(t *testing.T) {
83+
tryBuild(t, "sketch_with_inline_function", "sketch.ino")
84+
}
85+
86+
func TestTryBuild012(t *testing.T) {
87+
tryBuild(t, "sketch_with_default_args", "sketch.ino")
88+
}
89+
90+
func TestTryBuild013(t *testing.T) {
91+
tryBuild(t, "sketch_with_class", "sketch.ino")
92+
}
93+
94+
func TestTryBuild014(t *testing.T) {
95+
tryBuild(t, "sketch_with_backup_files", "sketch.ino")
96+
}
97+
98+
func TestTryBuild015(t *testing.T) {
99+
tryBuild(t, "sketch_with_subfolders")
100+
}
101+
102+
// This is a sketch that fails to build on purpose
103+
//func TestTryBuild016(t *testing.T) {
104+
// tryBuild(t, "sketch_that_checks_if_SPI_has_transactions_and_includes_missing_Ethernet", "sketch.ino")
105+
//}
106+
107+
func TestTryBuild017(t *testing.T) {
108+
tryPreprocess(t, "sketch_no_functions_two_files", "main.ino")
109+
}
110+
111+
func TestTryBuild018(t *testing.T) {
112+
tryBuild(t, "sketch_that_checks_if_SPI_has_transactions", "sketch.ino")
113+
}
114+
115+
func TestTryBuild019(t *testing.T) {
116+
tryBuild(t, "sketch_with_ifdef", "sketch.ino")
117+
}
118+
119+
func TestTryBuild020(t *testing.T) {
120+
context := makeDefaultContext(t)
121+
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"dependent_libraries", "libraries"}
122+
tryPreprocessWithContext(t, context, "sketch_with_dependend_libraries", "sketch.ino")
123+
}
124+
125+
func TestTryBuild021(t *testing.T) {
126+
tryBuild(t, "sketch_with_function_pointer", "sketch.ino")
127+
}
128+
129+
func TestTryBuild022(t *testing.T) {
130+
context := makeDefaultContext(t)
131+
context[constants.CTX_FQBN] = "arduino:samd:arduino_zero_native"
132+
tryBuildWithContext(t, context, "sketch_usbhost", "sketch_usbhost.ino")
133+
}
134+
135+
func TestTryBuild023(t *testing.T) {
136+
tryBuild(t, "sketch1", "sketch.ino")
137+
}
138+
139+
func TestTryBuild024(t *testing.T) {
140+
tryBuild(t, "sketch2", "SketchWithIfDef.ino")
141+
}
142+
143+
// The library for this sketch is missing
144+
//func TestTryBuild025(t *testing.T) {
145+
// tryBuild(t, "sketch3", "Baladuino.ino")
146+
//}
147+
148+
func TestTryBuild026(t *testing.T) {
149+
tryBuild(t, "sketch4", "CharWithEscapedDoubleQuote.ino")
150+
}
151+
152+
func TestTryBuild027(t *testing.T) {
153+
tryBuild(t, "sketch5", "IncludeBetweenMultilineComment.ino")
154+
}
155+
156+
func TestTryBuild028(t *testing.T) {
157+
tryBuild(t, "sketch6", "LineContinuations.ino")
158+
}
159+
160+
func TestTryBuild029(t *testing.T) {
161+
tryBuild(t, "sketch7", "StringWithComment.ino")
162+
}
163+
164+
func TestTryBuild030(t *testing.T) {
165+
tryBuild(t, "sketch8", "SketchWithStruct.ino")
166+
}
167+
168+
func TestTryBuild031(t *testing.T) {
169+
tryBuild(t, "sketch9", "sketch.ino")
170+
}
171+
172+
func TestTryBuild032(t *testing.T) {
173+
tryBuild(t, "sketch10", "sketch.ino")
174+
}
175+
176+
func makeDefaultContext(t *testing.T) map[string]interface{} {
177+
DownloadCoresAndToolsAndLibraries(t)
178+
179+
context := make(map[string]interface{})
180+
buildPath := SetupBuildPath(t, context)
181+
defer os.RemoveAll(buildPath)
182+
183+
context[constants.CTX_HARDWARE_FOLDERS] = []string{filepath.Join("..", "hardware"), "hardware", "downloaded_hardware", "downloaded_board_manager_stuff"}
184+
context[constants.CTX_TOOLS_FOLDERS] = []string{"downloaded_tools", "downloaded_board_manager_stuff"}
185+
context[constants.CTX_BUILT_IN_LIBRARIES_FOLDERS] = []string{"downloaded_libraries"}
186+
context[constants.CTX_FQBN] = "arduino:avr:leonardo"
187+
context[constants.CTX_BUILD_PROPERTIES_RUNTIME_IDE_VERSION] = "10607"
188+
context[constants.CTX_OTHER_LIBRARIES_FOLDERS] = []string{"libraries"}
189+
context[constants.CTX_VERBOSE] = true
190+
context[constants.CTX_DEBUG_PREPROCESSOR] = true
191+
192+
return context
193+
}
194+
195+
func tryBuild(t *testing.T, sketchPath ...string) {
196+
context := makeDefaultContext(t)
197+
tryBuildWithContext(t, context, sketchPath...)
198+
}
199+
200+
func tryBuildWithContext(t *testing.T, context map[string]interface{}, sketchPath ...string) {
201+
sketchLocation := filepath.Join(sketchPath...)
202+
context[constants.CTX_SKETCH_LOCATION] = sketchLocation
203+
204+
err := builder.RunBuilder(context)
205+
NoError(t, err, "Build error for "+sketchLocation)
206+
}
207+
208+
func tryPreprocess(t *testing.T, sketchPath ...string) {
209+
context := makeDefaultContext(t)
210+
tryPreprocessWithContext(t, context, sketchPath...)
211+
}
212+
213+
func tryPreprocessWithContext(t *testing.T, context map[string]interface{}, sketchPath ...string) {
214+
sketchLocation := filepath.Join(sketchPath...)
215+
context[constants.CTX_SKETCH_LOCATION] = sketchLocation
216+
217+
err := builder.RunPreprocess(context)
218+
NoError(t, err, "Build error for "+sketchLocation)
219+
}

0 commit comments

Comments
 (0)