Skip to content

Commit 5d931ff

Browse files
committed
fix regex and add test
1 parent 08d43a7 commit 5d931ff

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

Diff for: arduino/builder/sketch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/pkg/errors"
2929
)
3030

31-
var includesArduinoH = regexp.MustCompile(`^\s*#\s*include\s*[<\"]Arduino\.h[>\"]`)
31+
var includesArduinoH = regexp.MustCompile(`(?m)^\s*#\s*include\s*[<\"]Arduino\.h[>\"]`)
3232

3333
// QuoteCppString returns the given string as a quoted string for use with the C
3434
// preprocessor. This adds double quotes around it and escapes any

Diff for: arduino/builder/sketch_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"io/ioutil"
2020
"os"
2121
"path/filepath"
22+
"strings"
2223
"testing"
2324

2425
"github.com/arduino/arduino-cli/arduino/builder"
@@ -107,3 +108,13 @@ func TestMergeSketchSources(t *testing.T) {
107108
assert.Equal(t, 2, offset)
108109
assert.Equal(t, string(mergedBytes), source)
109110
}
111+
112+
func TestMergeSketchSourcesArduinoIncluded(t *testing.T) {
113+
s, err := builder.LoadSketch(filepath.Join("testdata", t.Name()), "")
114+
assert.Nil(t, err)
115+
assert.NotNil(t, s)
116+
117+
// ensure not to include Arduino.h when it's already there
118+
_, source := builder.MergeSketchSources(s)
119+
assert.Equal(t, 1, strings.Count(source, "<Arduino.h>"))
120+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// a comment
2+
3+
# include <Arduino.h>
4+
5+
void setup() {
6+
}
7+
8+
void loop() {
9+
}

0 commit comments

Comments
 (0)