Skip to content

Commit 9483120

Browse files
author
Federico Fissore
committed
Allowing spaces and tabs between hash and include. Fixes #64
Signed-off-by: Federico Fissore <[email protected]>
1 parent 5ee4585 commit 9483120

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/arduino.cc/builder/includes_finder_with_regexp.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"strings"
3737
)
3838

39-
var INCLUDE_REGEXP = regexp.MustCompile("(?ms)^\\s*#include\\s*[<\"](\\S+)[\">]")
39+
var INCLUDE_REGEXP = regexp.MustCompile("(?ms)^\\s*#[ \t]*include\\s*[<\"](\\S+)[\">]")
4040

4141
type IncludesFinderWithRegExp struct {
4242
ContextField string

src/arduino.cc/builder/test/includes_finder_with_regexp_test.go

+46-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestIncludesFinderWithRegExpCoanOutput(t *testing.T) {
8383
func TestIncludesFinderWithRegExp(t *testing.T) {
8484
context := make(map[string]interface{})
8585

86-
output := "/home/federico/materiale/works_Arduino/arduino-builder/src/arduino.cc/builder/test/sketch_that_checks_if_SPI_has_transactions/sketch.ino:1:17: fatal error: SPI.h: No such file or directory\n" +
86+
output := "/some/path/sketch.ino:1:17: fatal error: SPI.h: No such file or directory\n" +
8787
"#include <SPI.h>\n" +
8888
"^\n" +
8989
"compilation terminated."
@@ -120,7 +120,7 @@ func TestIncludesFinderWithRegExpPreviousIncludes(t *testing.T) {
120120

121121
context[constants.CTX_INCLUDES] = []string{"test.h"}
122122

123-
output := "/home/federico/materiale/works_Arduino/arduino-builder/src/arduino.cc/builder/test/sketch_that_checks_if_SPI_has_transactions/sketch.ino:1:17: fatal error: SPI.h: No such file or directory\n" +
123+
output := "/some/path/sketch.ino:1:17: fatal error: SPI.h: No such file or directory\n" +
124124
"#include <SPI.h>\n" +
125125
"^\n" +
126126
"compilation terminated."
@@ -138,3 +138,47 @@ func TestIncludesFinderWithRegExpPreviousIncludes(t *testing.T) {
138138
require.Equal(t, "SPI.h", includes[0])
139139
require.Equal(t, "test.h", includes[1])
140140
}
141+
142+
func TestIncludesFinderWithRegExpPaddedIncludes(t *testing.T) {
143+
context := make(map[string]interface{})
144+
145+
context[constants.CTX_INCLUDES] = []string{}
146+
147+
output := "/some/path/sketch.ino:1:33: fatal error: Wire.h: No such file or directory\n" +
148+
" # include <Wire.h>\n" +
149+
" ^\n" +
150+
"compilation terminated.\n"
151+
context["source"] = output
152+
153+
parser := builder.IncludesFinderWithRegExp{ContextField: "source"}
154+
err := parser.Run(context)
155+
NoError(t, err)
156+
157+
require.NotNil(t, context[constants.CTX_INCLUDES])
158+
includes := context[constants.CTX_INCLUDES].([]string)
159+
require.Equal(t, 1, len(includes))
160+
sort.Strings(includes)
161+
require.Equal(t, "Wire.h", includes[0])
162+
}
163+
164+
func TestIncludesFinderWithRegExpPaddedIncludes2(t *testing.T) {
165+
context := make(map[string]interface{})
166+
167+
context[constants.CTX_INCLUDES] = []string{}
168+
169+
output := "/some/path/sketch.ino:1:33: fatal error: Wire.h: No such file or directory\n" +
170+
" #\t\t\tinclude <Wire.h>\n" +
171+
" ^\n" +
172+
"compilation terminated.\n"
173+
context["source"] = output
174+
175+
parser := builder.IncludesFinderWithRegExp{ContextField: "source"}
176+
err := parser.Run(context)
177+
NoError(t, err)
178+
179+
require.NotNil(t, context[constants.CTX_INCLUDES])
180+
includes := context[constants.CTX_INCLUDES].([]string)
181+
require.Equal(t, 1, len(includes))
182+
sort.Strings(includes)
183+
require.Equal(t, "Wire.h", includes[0])
184+
}

0 commit comments

Comments
 (0)