@@ -55,7 +55,11 @@ func newTestSys(fileOrFolderList FileMap, cwd string) *testSys {
55
55
cwd = "/home/src/workspaces/project"
56
56
}
57
57
sys := & testSys {
58
- fs : NewFSTrackingLibs (incrementaltestutil .NewFsHandlingBuildInfo (vfstest .FromMap (fileOrFolderList , true /*useCaseSensitiveFileNames*/ ))),
58
+ fs : & incrementaltestutil.FsHandlingBuildInfo {
59
+ FS : & testFs {
60
+ FS : vfstest .FromMap (fileOrFolderList , true /*useCaseSensitiveFileNames*/ ),
61
+ },
62
+ },
59
63
defaultLibraryPath : tscLibPath ,
60
64
cwd : cwd ,
61
65
files : slices .Collect (maps .Keys (fileOrFolderList )),
@@ -91,7 +95,7 @@ type testSys struct {
91
95
currentWrite * strings.Builder
92
96
serializedDiff * snapshot
93
97
94
- fs * testFsTrackingLibs
98
+ fs * incrementaltestutil. FsHandlingBuildInfo
95
99
defaultLibraryPath string
96
100
cwd string
97
101
files []string
@@ -114,18 +118,22 @@ func (s *testSys) FS() vfs.FS {
114
118
return s .fs
115
119
}
116
120
117
- func (s * testSys ) TestFS () * incrementaltestutil.FsHandlingBuildInfo {
118
- return s .fs .FS .(* incrementaltestutil.FsHandlingBuildInfo )
121
+ func (s * testSys ) testFs () * testFs {
122
+ return s .fs .FS .(* testFs )
123
+ }
124
+
125
+ func (s * testSys ) fsFromFileMap () vfs.FS {
126
+ return s .testFs ().FS
119
127
}
120
128
121
129
func (s * testSys ) ensureLibPathExists (path string ) {
122
130
path = tscLibPath + "/" + path
123
- if _ , ok := s .TestFS ().ReadFile (path ); ! ok {
124
- if s .fs .defaultLibs == nil {
125
- s .fs .defaultLibs = & collections.SyncSet [string ]{}
131
+ if _ , ok := s .fsFromFileMap ().ReadFile (path ); ! ok {
132
+ if s .testFs () .defaultLibs == nil {
133
+ s .testFs () .defaultLibs = & collections.SyncSet [string ]{}
126
134
}
127
- s .fs .defaultLibs .Add (path )
128
- err := s .TestFS ().WriteFile (path , tscDefaultLibContent , false )
135
+ s .testFs () .defaultLibs .Add (path )
136
+ err := s .fsFromFileMap ().WriteFile (path , tscDefaultLibContent , false )
129
137
if err != nil {
130
138
panic ("Failed to write default library file: " + err .Error ())
131
139
}
@@ -223,14 +231,17 @@ func (s *testSys) baselineOutput(baseline io.Writer) {
223
231
}
224
232
// todo screen clears
225
233
s .printOutputs (baseline )
234
+ }
235
+
236
+ func (s * testSys ) clearOutput () {
226
237
s .output = []string {}
227
238
}
228
239
229
240
func (s * testSys ) baselineFSwithDiff (baseline io.Writer ) {
230
241
// 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
231
242
snap := map [string ]* diffEntry {}
232
243
233
- err := s .FS ().WalkDir ("/" , func (path string , d vfs.DirEntry , e error ) error {
244
+ err := s .fsFromFileMap ().WalkDir ("/" , func (path string , d vfs.DirEntry , e error ) error {
234
245
if e != nil {
235
246
return e
236
247
}
@@ -239,7 +250,7 @@ func (s *testSys) baselineFSwithDiff(baseline io.Writer) {
239
250
return nil
240
251
}
241
252
242
- newContents , ok := s .TestFS ().InnerReadFile (path )
253
+ newContents , ok := s .fsFromFileMap ().ReadFile (path )
243
254
if ! ok {
244
255
return nil
245
256
}
@@ -258,16 +269,16 @@ func (s *testSys) baselineFSwithDiff(baseline io.Writer) {
258
269
}
259
270
if s .serializedDiff != nil {
260
271
for path := range s .serializedDiff .snap {
261
- _ , ok := s .TestFS ().InnerReadFile (path )
272
+ _ , ok := s .fsFromFileMap ().ReadFile (path )
262
273
if ! ok {
263
274
// report deleted
264
275
s .reportFSEntryDiff (baseline , nil , path )
265
276
}
266
277
}
267
278
}
268
279
var defaultLibs collections.SyncSet [string ]
269
- if s .fs .defaultLibs != nil {
270
- s .fs .defaultLibs .Range (func (libPath string ) bool {
280
+ if s .testFs () .defaultLibs != nil {
281
+ s .testFs () .defaultLibs .Range (func (libPath string ) bool {
271
282
defaultLibs .Add (libPath )
272
283
return true
273
284
})
@@ -288,7 +299,7 @@ func (s *testSys) reportFSEntryDiff(baseline io.Writer, newDirContent *diffEntry
288
299
}
289
300
// todo handle more cases of fs changes
290
301
if oldDirContent == nil {
291
- if s .fs .defaultLibs == nil || ! s .fs .defaultLibs .Has (path ) {
302
+ if s .testFs () .defaultLibs == nil || ! s .testFs () .defaultLibs .Has (path ) {
292
303
fmt .Fprint (baseline , "//// [" , path , "] *new* \n " , newDirContent .content , "\n " )
293
304
}
294
305
} else if newDirContent == nil {
@@ -297,7 +308,7 @@ func (s *testSys) reportFSEntryDiff(baseline io.Writer, newDirContent *diffEntry
297
308
fmt .Fprint (baseline , "//// [" , path , "] *modified* \n " , newDirContent .content , "\n " )
298
309
} else if newDirContent .fileInfo .ModTime () != oldDirContent .fileInfo .ModTime () {
299
310
fmt .Fprint (baseline , "//// [" , path , "] *modified time*\n " )
300
- } else if defaultLibs != nil && defaultLibs .Has (path ) && s .fs .defaultLibs != nil && ! s .fs .defaultLibs .Has (path ) {
311
+ } else if defaultLibs != nil && defaultLibs .Has (path ) && s .testFs () .defaultLibs != nil && ! s .testFs () .defaultLibs .Has (path ) {
301
312
// Lib file that was read
302
313
fmt .Fprint (baseline , "//// [" , path , "] *Lib*\n " , newDirContent .content , "\n " )
303
314
}
@@ -308,33 +319,33 @@ func (s *testSys) printOutputs(baseline io.Writer) {
308
319
fmt .Fprint (baseline , strings .Join (s .output , "\n " ))
309
320
}
310
321
311
- func (s * testSys ) WriteFileNoError (path string , content string , writeByteOrderMark bool ) {
312
- if err := s .FS ().WriteFile (path , content , writeByteOrderMark ); err != nil {
322
+ func (s * testSys ) writeFileNoError (path string , content string , writeByteOrderMark bool ) {
323
+ if err := s .fsFromFileMap ().WriteFile (path , content , writeByteOrderMark ); err != nil {
313
324
panic (err )
314
325
}
315
326
}
316
327
317
- func (s * testSys ) ReplaceFileText (path string , oldText string , newText string ) {
318
- content , ok := s .FS ().ReadFile (path )
328
+ func (s * testSys ) replaceFileText (path string , oldText string , newText string ) {
329
+ content , ok := s .fsFromFileMap ().ReadFile (path )
319
330
if ! ok {
320
331
panic ("File not found: " + path )
321
332
}
322
333
content = strings .Replace (content , oldText , newText , 1 )
323
- s .WriteFileNoError (path , content , false )
334
+ s .writeFileNoError (path , content , false )
324
335
}
325
336
326
- func (s * testSys ) AppendFile (path string , text string ) {
327
- content , ok := s .FS ().ReadFile (path )
337
+ func (s * testSys ) appendFile (path string , text string ) {
338
+ content , ok := s .fsFromFileMap ().ReadFile (path )
328
339
if ! ok {
329
340
panic ("File not found: " + path )
330
341
}
331
- s .WriteFileNoError (path , content + text , false )
342
+ s .writeFileNoError (path , content + text , false )
332
343
}
333
344
334
- func (s * testSys ) PrependFile (path string , text string ) {
335
- content , ok := s .FS ().ReadFile (path )
345
+ func (s * testSys ) prependFile (path string , text string ) {
346
+ content , ok := s .fsFromFileMap ().ReadFile (path )
336
347
if ! ok {
337
348
panic ("File not found: " + path )
338
349
}
339
- s .WriteFileNoError (path , text + content , false )
350
+ s .writeFileNoError (path , text + content , false )
340
351
}
0 commit comments