Skip to content

Commit 245cd6f

Browse files
committed
Use written files for diffing
1 parent 3372773 commit 245cd6f

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

internal/execute/testsys_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func newTestSys(fileOrFolderList FileMap, cwd string) *testSys {
8080
}
8181

8282
type diffEntry struct {
83-
content string
84-
modTime time.Time
83+
content string
84+
isWritten bool
8585
}
8686

8787
type snapshot struct {
@@ -237,6 +237,7 @@ func (s *testSys) baselineFSwithDiff(baseline io.Writer) {
237237
// todo: baselines the entire fs, possibly doesn't correctly diff all cases of emitted files, since emit isn't fully implemented and doesn't always emit the same way as strada
238238
snap := map[string]*diffEntry{}
239239

240+
testFs := s.testFs()
240241
err := s.fsFromFileMap().WalkDir("/", func(path string, d vfs.DirEntry, e error) error {
241242
if e != nil {
242243
return e
@@ -250,11 +251,7 @@ func (s *testSys) baselineFSwithDiff(baseline io.Writer) {
250251
if !ok {
251252
return nil
252253
}
253-
fileInfo, err := d.Info()
254-
if err != nil {
255-
return nil
256-
}
257-
newEntry := &diffEntry{content: newContents, modTime: fileInfo.ModTime()}
254+
newEntry := &diffEntry{content: newContents, isWritten: testFs.writtenFiles.Has(path)}
258255
snap[path] = newEntry
259256
s.reportFSEntryDiff(baseline, newEntry, path)
260257

@@ -284,6 +281,7 @@ func (s *testSys) baselineFSwithDiff(baseline io.Writer) {
284281
defaultLibs: &defaultLibs,
285282
}
286283
fmt.Fprintln(baseline)
284+
testFs.writtenFiles = collections.SyncSet[string]{} // Reset written files after baseline
287285
}
288286

289287
func (s *testSys) reportFSEntryDiff(baseline io.Writer, newDirContent *diffEntry, path string) {
@@ -302,8 +300,8 @@ func (s *testSys) reportFSEntryDiff(baseline io.Writer, newDirContent *diffEntry
302300
fmt.Fprint(baseline, "//// [", path, "] *deleted*\n")
303301
} else if newDirContent.content != oldDirContent.content {
304302
fmt.Fprint(baseline, "//// [", path, "] *modified* \n", newDirContent.content, "\n")
305-
} else if !newDirContent.modTime.Equal(oldDirContent.modTime) {
306-
fmt.Fprint(baseline, "//// [", path, "] *modified time*\n")
303+
} else if newDirContent.isWritten {
304+
fmt.Fprint(baseline, "//// [", path, "] *rewrite with same content*\n")
307305
} else if defaultLibs != nil && defaultLibs.Has(path) && s.testFs().defaultLibs != nil && !s.testFs().defaultLibs.Has(path) {
308306
// Lib file that was read
309307
fmt.Fprint(baseline, "//// [", path, "] *Lib*\n", newDirContent.content, "\n")

0 commit comments

Comments
 (0)