Skip to content

Commit ce2aa2a

Browse files
committed
Fixed unit-test
1 parent 18ae29d commit ce2aa2a

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

internal/arduino/builder/internal/utils/utils_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package utils
1717

1818
import (
1919
"os"
20+
"strings"
2021
"testing"
2122
"time"
2223

@@ -50,6 +51,12 @@ func tempFile(t *testing.T, prefix string) *paths.Path {
5051
return paths.New(file.Name())
5152
}
5253

54+
func quoteForDep(in string) string {
55+
// On Windows paths contains "\" as separator so we need to quote it
56+
// to use it in .d files.
57+
return strings.ReplaceAll(in, "\\", "\\\\")
58+
}
59+
5360
func TestObjFileIsUpToDateObjMissing(t *testing.T) {
5461
sourceFile := tempFile(t, "source")
5562
defer sourceFile.RemoveAll()
@@ -119,7 +126,9 @@ func TestObjFileIsUpToDateDepIsNewer(t *testing.T) {
119126
headerFile := tempFile(t, "header")
120127
defer headerFile.RemoveAll()
121128

122-
data := objFile.String() + ": \\\n\t" + sourceFile.String() + " \\\n\t" + headerFile.String()
129+
data := quoteForDep(objFile.String()) + ": \\\n\t" +
130+
quoteForDep(sourceFile.String()) + " \\\n\t" +
131+
quoteForDep(headerFile.String())
123132
depFile.WriteFile([]byte(data))
124133

125134
upToDate, err := ObjFileIsUpToDate(sourceFile, objFile, depFile)
@@ -141,7 +150,9 @@ func TestObjFileIsUpToDateDepIsOlder(t *testing.T) {
141150
depFile := tempFile(t, "dep")
142151
defer depFile.RemoveAll()
143152

144-
res := objFile.String() + ": \\\n\t" + sourceFile.String() + " \\\n\t" + headerFile.String()
153+
res := quoteForDep(objFile.String()) + ": \\\n\t" +
154+
quoteForDep(sourceFile.String()) + " \\\n\t" +
155+
quoteForDep(headerFile.String())
145156
depFile.WriteFile([]byte(res))
146157

147158
upToDate, err := ObjFileIsUpToDate(sourceFile, objFile, depFile)
@@ -165,7 +176,9 @@ func TestObjFileIsUpToDateDepIsWrong(t *testing.T) {
165176
headerFile := tempFile(t, "header")
166177
defer headerFile.RemoveAll()
167178

168-
res := sourceFile.String() + ": \\\n\t" + sourceFile.String() + " \\\n\t" + headerFile.String()
179+
res := quoteForDep(sourceFile.String()) + ": \\\n\t" +
180+
quoteForDep(sourceFile.String()) + " \\\n\t" +
181+
quoteForDep(headerFile.String())
169182
depFile.WriteFile([]byte(res))
170183

171184
upToDate, err := ObjFileIsUpToDate(sourceFile, objFile, depFile)

0 commit comments

Comments
 (0)