Skip to content

Commit 833d393

Browse files
author
Federico Fissore
committed
Testing that AdditionalSketchFilesCopier doesn't copy unchanged files. See #77
Signed-off-by: Federico Fissore <[email protected]>
1 parent 0329b1c commit 833d393

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

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

+41
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"path/filepath"
4040
"sort"
4141
"testing"
42+
"time"
4243
)
4344

4445
type ByFileInfoName []os.FileInfo
@@ -90,3 +91,43 @@ func TestCopyOtherFiles(t *testing.T) {
9091
require.Equal(t, 1, len(files))
9192
require.Equal(t, "helper.h", files[0].Name())
9293
}
94+
95+
func TestCopyOtherFilesOnlyIfChanged(t *testing.T) {
96+
context := make(map[string]interface{})
97+
98+
buildPath := SetupBuildPath(t, context)
99+
defer os.RemoveAll(buildPath)
100+
101+
context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino")
102+
103+
commands := []types.Command{
104+
&builder.SetupHumanLoggerIfMissing{},
105+
&builder.AddAdditionalEntriesToContext{},
106+
&builder.SketchLoader{},
107+
&builder.AdditionalSketchFilesCopier{},
108+
}
109+
110+
for _, command := range commands {
111+
err := command.Run(context)
112+
NoError(t, err)
113+
}
114+
115+
headerStatBefore, err := os.Stat(filepath.Join(buildPath, constants.FOLDER_SKETCH, "header.h"))
116+
NoError(t, err)
117+
118+
time.Sleep(2 * time.Second)
119+
120+
context = make(map[string]interface{})
121+
context[constants.CTX_BUILD_PATH] = buildPath
122+
context[constants.CTX_SKETCH_LOCATION] = filepath.Join("sketch1", "sketch.ino")
123+
124+
for _, command := range commands {
125+
err := command.Run(context)
126+
NoError(t, err)
127+
}
128+
129+
headerStatAfter, err := os.Stat(filepath.Join(buildPath, constants.FOLDER_SKETCH, "header.h"))
130+
NoError(t, err)
131+
132+
require.Equal(t, headerStatBefore.ModTime().Unix(), headerStatAfter.ModTime().Unix())
133+
}

0 commit comments

Comments
 (0)