@@ -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
}
@@ -219,14 +227,17 @@ func (s *testSys) baselineOutput(baseline io.Writer) {
219
227
}
220
228
// todo screen clears
221
229
s .printOutputs (baseline )
230
+ }
231
+
232
+ func (s * testSys ) clearOutput () {
222
233
s .output = []string {}
223
234
}
224
235
225
236
func (s * testSys ) baselineFSwithDiff (baseline io.Writer ) {
226
237
// 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
227
238
snap := map [string ]* diffEntry {}
228
239
229
- err := s .FS ().WalkDir ("/" , func (path string , d vfs.DirEntry , e error ) error {
240
+ err := s .fsFromFileMap ().WalkDir ("/" , func (path string , d vfs.DirEntry , e error ) error {
230
241
if e != nil {
231
242
return e
232
243
}
@@ -235,7 +246,7 @@ func (s *testSys) baselineFSwithDiff(baseline io.Writer) {
235
246
return nil
236
247
}
237
248
238
- newContents , ok := s .TestFS ().InnerReadFile (path )
249
+ newContents , ok := s .fsFromFileMap ().ReadFile (path )
239
250
if ! ok {
240
251
return nil
241
252
}
@@ -254,16 +265,16 @@ func (s *testSys) baselineFSwithDiff(baseline io.Writer) {
254
265
}
255
266
if s .serializedDiff != nil {
256
267
for path := range s .serializedDiff .snap {
257
- _ , ok := s .TestFS ().InnerReadFile (path )
268
+ _ , ok := s .fsFromFileMap ().ReadFile (path )
258
269
if ! ok {
259
270
// report deleted
260
271
s .reportFSEntryDiff (baseline , nil , path )
261
272
}
262
273
}
263
274
}
264
275
var defaultLibs collections.SyncSet [string ]
265
- if s .fs .defaultLibs != nil {
266
- s .fs .defaultLibs .Range (func (libPath string ) bool {
276
+ if s .testFs () .defaultLibs != nil {
277
+ s .testFs () .defaultLibs .Range (func (libPath string ) bool {
267
278
defaultLibs .Add (libPath )
268
279
return true
269
280
})
@@ -284,7 +295,7 @@ func (s *testSys) reportFSEntryDiff(baseline io.Writer, newDirContent *diffEntry
284
295
}
285
296
// todo handle more cases of fs changes
286
297
if oldDirContent == nil {
287
- if s .fs .defaultLibs == nil || ! s .fs .defaultLibs .Has (path ) {
298
+ if s .testFs () .defaultLibs == nil || ! s .testFs () .defaultLibs .Has (path ) {
288
299
fmt .Fprint (baseline , "//// [" , path , "] *new* \n " , newDirContent .content , "\n " )
289
300
}
290
301
} else if newDirContent == nil {
@@ -293,7 +304,7 @@ func (s *testSys) reportFSEntryDiff(baseline io.Writer, newDirContent *diffEntry
293
304
fmt .Fprint (baseline , "//// [" , path , "] *modified* \n " , newDirContent .content , "\n " )
294
305
} else if newDirContent .fileInfo .ModTime () != oldDirContent .fileInfo .ModTime () {
295
306
fmt .Fprint (baseline , "//// [" , path , "] *modified time*\n " )
296
- } else if defaultLibs != nil && defaultLibs .Has (path ) && s .fs .defaultLibs != nil && ! s .fs .defaultLibs .Has (path ) {
307
+ } else if defaultLibs != nil && defaultLibs .Has (path ) && s .testFs () .defaultLibs != nil && ! s .testFs () .defaultLibs .Has (path ) {
297
308
// Lib file that was read
298
309
fmt .Fprint (baseline , "//// [" , path , "] *Lib*\n " , newDirContent .content , "\n " )
299
310
}
@@ -304,33 +315,33 @@ func (s *testSys) printOutputs(baseline io.Writer) {
304
315
fmt .Fprint (baseline , strings .Join (s .output , "\n " ))
305
316
}
306
317
307
- func (s * testSys ) WriteFileNoError (path string , content string , writeByteOrderMark bool ) {
308
- if err := s .FS ().WriteFile (path , content , writeByteOrderMark ); err != nil {
318
+ func (s * testSys ) writeFileNoError (path string , content string , writeByteOrderMark bool ) {
319
+ if err := s .fsFromFileMap ().WriteFile (path , content , writeByteOrderMark ); err != nil {
309
320
panic (err )
310
321
}
311
322
}
312
323
313
- func (s * testSys ) ReplaceFileText (path string , oldText string , newText string ) {
314
- content , ok := s .FS ().ReadFile (path )
324
+ func (s * testSys ) replaceFileText (path string , oldText string , newText string ) {
325
+ content , ok := s .fsFromFileMap ().ReadFile (path )
315
326
if ! ok {
316
327
panic ("File not found: " + path )
317
328
}
318
329
content = strings .Replace (content , oldText , newText , 1 )
319
- s .WriteFileNoError (path , content , false )
330
+ s .writeFileNoError (path , content , false )
320
331
}
321
332
322
- func (s * testSys ) AppendFile (path string , text string ) {
323
- content , ok := s .FS ().ReadFile (path )
333
+ func (s * testSys ) appendFile (path string , text string ) {
334
+ content , ok := s .fsFromFileMap ().ReadFile (path )
324
335
if ! ok {
325
336
panic ("File not found: " + path )
326
337
}
327
- s .WriteFileNoError (path , content + text , false )
338
+ s .writeFileNoError (path , content + text , false )
328
339
}
329
340
330
- func (s * testSys ) PrependFile (path string , text string ) {
331
- content , ok := s .FS ().ReadFile (path )
341
+ func (s * testSys ) prependFile (path string , text string ) {
342
+ content , ok := s .fsFromFileMap ().ReadFile (path )
332
343
if ! ok {
333
344
panic ("File not found: " + path )
334
345
}
335
- s .WriteFileNoError (path , text + content , false )
346
+ s .writeFileNoError (path , text + content , false )
336
347
}
0 commit comments