Skip to content

Commit 14d364c

Browse files
Fix sketch_source_merger_test.go to use full paths in #line directives
This uses the text/template package to process the sketch file, allowing it access to the full context. This is a bit overkill, but it is easy and might be useful for more complex testcases later.
1 parent 40b4af9 commit 14d364c

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#line 1 "sketch.ino"
1+
#line 1 "{{.sketch.MainFile.Name}}"
22
void setup() {
33

44
}
55

66
void loop() {
77

88
}
9-
#line 1 "old.pde"
9+
#line 1 "{{(index .sketch.OtherSketchFiles 0).Name}}"
1010

11-
#line 1 "other.ino"
11+
#line 1 "{{(index .sketch.OtherSketchFiles 1).Name}}"
1212
String hello() {
1313
return "world";
1414
}

Diff for: src/arduino.cc/builder/test/sketch_source_merger_test.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ import (
3434
"arduino.cc/builder/constants"
3535
"arduino.cc/builder/types"
3636
"github.com/stretchr/testify/require"
37-
"io/ioutil"
3837
"path/filepath"
3938
"strings"
4039
"testing"
40+
"text/template"
41+
"bytes"
4142
)
4243

44+
4345
func TestMergeSketch(t *testing.T) {
4446
context := make(map[string]interface{})
4547
context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino")
@@ -57,9 +59,13 @@ func TestMergeSketch(t *testing.T) {
5759

5860
source := context[constants.CTX_SOURCE].(string)
5961

60-
bytes, err1 := ioutil.ReadFile(filepath.Join("sketch1", "merged_sketch.txt"))
62+
tpl, err1 := template.ParseFiles(filepath.Join("sketch1", "merged_sketch.txt"))
6163
NoError(t, err1)
6264

63-
expected_source := string(bytes)
65+
var buf bytes.Buffer
66+
err2 := tpl.Execute(&buf, context)
67+
NoError(t, err2)
68+
69+
expected_source := buf.String()
6470
require.Equal(t, expected_source, strings.Replace(source, "\r\n", "\n", -1))
6571
}

0 commit comments

Comments
 (0)