Commit 3656f477 authored by Massimiliano Pippi's avatar Massimiliano Pippi

fix regex and add test

parent ae3881b5
......@@ -28,7 +28,7 @@ import (
"github.com/pkg/errors"
)
var includesArduinoH = regexp.MustCompile(`^\s*#\s*include\s*[<\"]Arduino\.h[>\"]`)
var includesArduinoH = regexp.MustCompile(`(?m)^\s*#\s*include\s*[<\"]Arduino\.h[>\"]`)
// QuoteCppString returns the given string as a quoted string for use with the C
// preprocessor. This adds double quotes around it and escapes any
......
......@@ -19,6 +19,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"github.com/arduino/arduino-cli/arduino/builder"
......@@ -107,3 +108,13 @@ func TestMergeSketchSources(t *testing.T) {
assert.Equal(t, 2, offset)
assert.Equal(t, string(mergedBytes), source)
}
func TestMergeSketchSourcesArduinoIncluded(t *testing.T) {
s, err := builder.LoadSketch(filepath.Join("testdata", t.Name()), "")
assert.Nil(t, err)
assert.NotNil(t, s)
// ensure not to include Arduino.h when it's already there
_, source := builder.MergeSketchSources(s)
assert.Equal(t, 1, strings.Count(source, "<Arduino.h>"))
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment