@@ -39,6 +39,7 @@ import (
3939 "path/filepath"
4040 "sort"
4141 "testing"
42+ "time"
4243)
4344
4445type 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