Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit66a62bf

Browse files
committed
Incremental correctness
1 parentac20ac4 commit66a62bf

File tree

9 files changed

+324
-268
lines changed

9 files changed

+324
-268
lines changed

‎internal/execute/testfs_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,33 @@ import (
55
"github.com/microsoft/typescript-go/internal/vfs"
66
)
77

8-
typetestFsTrackingLibsstruct {
8+
typetestFsstruct {
99
vfs.FS
10-
defaultLibs*collections.SyncSet[string]
10+
defaultLibs*collections.SyncSet[string]
11+
writtenFiles collections.SyncSet[string]
1112
}
1213

13-
funcNewFSTrackingLibs(fs vfs.FS)*testFsTrackingLibs {
14-
return&testFsTrackingLibs{FS:fs}
15-
}
16-
17-
func (f*testFsTrackingLibs)removeIgnoreLibPath(pathstring) {
14+
func (f*testFs)removeIgnoreLibPath(pathstring) {
1815
iff.defaultLibs!=nil&&f.defaultLibs.Has(path) {
1916
f.defaultLibs.Delete(path)
2017
}
2118
}
2219

2320
// ReadFile reads the file specified by path and returns the content.
2421
// If the file fails to be read, ok will be false.
25-
func (f*testFsTrackingLibs)ReadFile(pathstring) (contentsstring,okbool) {
22+
func (f*testFs)ReadFile(pathstring) (contentsstring,okbool) {
2623
f.removeIgnoreLibPath(path)
2724
returnf.FS.ReadFile(path)
2825
}
2926

30-
func (f*testFsTrackingLibs)WriteFile(pathstring,datastring,writeByteOrderMarkbool)error {
27+
func (f*testFs)WriteFile(pathstring,datastring,writeByteOrderMarkbool)error {
3128
f.removeIgnoreLibPath(path)
29+
f.writtenFiles.Add(path)
3230
returnf.FS.WriteFile(path,data,writeByteOrderMark)
3331
}
3432

3533
// Removes `path` and all its contents. Will return the first error it encounters.
36-
func (f*testFsTrackingLibs)Remove(pathstring)error {
34+
func (f*testFs)Remove(pathstring)error {
3735
f.removeIgnoreLibPath(path)
3836
returnf.FS.Remove(path)
3937
}

‎internal/execute/testsys_test.go

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ func newTestSys(fileOrFolderList FileMap, cwd string) *testSys {
5555
cwd="/home/src/workspaces/project"
5656
}
5757
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+
},
5963
defaultLibraryPath:tscLibPath,
6064
cwd:cwd,
6165
files:slices.Collect(maps.Keys(fileOrFolderList)),
@@ -91,7 +95,7 @@ type testSys struct {
9195
currentWrite*strings.Builder
9296
serializedDiff*snapshot
9397

94-
fs*testFsTrackingLibs
98+
fs*incrementaltestutil.FsHandlingBuildInfo
9599
defaultLibraryPathstring
96100
cwdstring
97101
files []string
@@ -114,18 +118,22 @@ func (s *testSys) FS() vfs.FS {
114118
returns.fs
115119
}
116120

117-
func (s*testSys)TestFS()*incrementaltestutil.FsHandlingBuildInfo {
118-
returns.fs.FS.(*incrementaltestutil.FsHandlingBuildInfo)
121+
func (s*testSys)testFs()*testFs {
122+
returns.fs.FS.(*testFs)
123+
}
124+
125+
func (s*testSys)fsFromFileMap() vfs.FS {
126+
returns.testFs().FS
119127
}
120128

121129
func (s*testSys)ensureLibPathExists(pathstring) {
122130
path=tscLibPath+"/"+path
123-
if_,ok:=s.TestFS().ReadFile(path);!ok {
124-
ifs.fs.defaultLibs==nil {
125-
s.fs.defaultLibs=&collections.SyncSet[string]{}
131+
if_,ok:=s.fsFromFileMap().ReadFile(path);!ok {
132+
ifs.testFs().defaultLibs==nil {
133+
s.testFs().defaultLibs=&collections.SyncSet[string]{}
126134
}
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)
129137
iferr!=nil {
130138
panic("Failed to write default library file: "+err.Error())
131139
}
@@ -223,14 +231,17 @@ func (s *testSys) baselineOutput(baseline io.Writer) {
223231
}
224232
// todo screen clears
225233
s.printOutputs(baseline)
234+
}
235+
236+
func (s*testSys)clearOutput() {
226237
s.output= []string{}
227238
}
228239

229240
func (s*testSys)baselineFSwithDiff(baseline io.Writer) {
230241
// 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
231242
snap:=map[string]*diffEntry{}
232243

233-
err:=s.FS().WalkDir("/",func(pathstring,d vfs.DirEntry,eerror)error {
244+
err:=s.fsFromFileMap().WalkDir("/",func(pathstring,d vfs.DirEntry,eerror)error {
234245
ife!=nil {
235246
returne
236247
}
@@ -239,7 +250,7 @@ func (s *testSys) baselineFSwithDiff(baseline io.Writer) {
239250
returnnil
240251
}
241252

242-
newContents,ok:=s.TestFS().InnerReadFile(path)
253+
newContents,ok:=s.fsFromFileMap().ReadFile(path)
243254
if!ok {
244255
returnnil
245256
}
@@ -258,16 +269,16 @@ func (s *testSys) baselineFSwithDiff(baseline io.Writer) {
258269
}
259270
ifs.serializedDiff!=nil {
260271
forpath:=ranges.serializedDiff.snap {
261-
_,ok:=s.TestFS().InnerReadFile(path)
272+
_,ok:=s.fsFromFileMap().ReadFile(path)
262273
if!ok {
263274
// report deleted
264275
s.reportFSEntryDiff(baseline,nil,path)
265276
}
266277
}
267278
}
268279
vardefaultLibs collections.SyncSet[string]
269-
ifs.fs.defaultLibs!=nil {
270-
s.fs.defaultLibs.Range(func(libPathstring)bool {
280+
ifs.testFs().defaultLibs!=nil {
281+
s.testFs().defaultLibs.Range(func(libPathstring)bool {
271282
defaultLibs.Add(libPath)
272283
returntrue
273284
})
@@ -288,7 +299,7 @@ func (s *testSys) reportFSEntryDiff(baseline io.Writer, newDirContent *diffEntry
288299
}
289300
// todo handle more cases of fs changes
290301
ifoldDirContent==nil {
291-
ifs.fs.defaultLibs==nil||!s.fs.defaultLibs.Has(path) {
302+
ifs.testFs().defaultLibs==nil||!s.testFs().defaultLibs.Has(path) {
292303
fmt.Fprint(baseline,"//// [",path,"] *new*\n",newDirContent.content,"\n")
293304
}
294305
}elseifnewDirContent==nil {
@@ -297,7 +308,7 @@ func (s *testSys) reportFSEntryDiff(baseline io.Writer, newDirContent *diffEntry
297308
fmt.Fprint(baseline,"//// [",path,"] *modified*\n",newDirContent.content,"\n")
298309
}elseifnewDirContent.fileInfo.ModTime()!=oldDirContent.fileInfo.ModTime() {
299310
fmt.Fprint(baseline,"//// [",path,"] *modified time*\n")
300-
}elseifdefaultLibs!=nil&&defaultLibs.Has(path)&&s.fs.defaultLibs!=nil&&!s.fs.defaultLibs.Has(path) {
311+
}elseifdefaultLibs!=nil&&defaultLibs.Has(path)&&s.testFs().defaultLibs!=nil&&!s.testFs().defaultLibs.Has(path) {
301312
// Lib file that was read
302313
fmt.Fprint(baseline,"//// [",path,"] *Lib*\n",newDirContent.content,"\n")
303314
}
@@ -308,33 +319,33 @@ func (s *testSys) printOutputs(baseline io.Writer) {
308319
fmt.Fprint(baseline,strings.Join(s.output,"\n"))
309320
}
310321

311-
func (s*testSys)WriteFileNoError(pathstring,contentstring,writeByteOrderMarkbool) {
312-
iferr:=s.FS().WriteFile(path,content,writeByteOrderMark);err!=nil {
322+
func (s*testSys)writeFileNoError(pathstring,contentstring,writeByteOrderMarkbool) {
323+
iferr:=s.fsFromFileMap().WriteFile(path,content,writeByteOrderMark);err!=nil {
313324
panic(err)
314325
}
315326
}
316327

317-
func (s*testSys)ReplaceFileText(pathstring,oldTextstring,newTextstring) {
318-
content,ok:=s.FS().ReadFile(path)
328+
func (s*testSys)replaceFileText(pathstring,oldTextstring,newTextstring) {
329+
content,ok:=s.fsFromFileMap().ReadFile(path)
319330
if!ok {
320331
panic("File not found: "+path)
321332
}
322333
content=strings.Replace(content,oldText,newText,1)
323-
s.WriteFileNoError(path,content,false)
334+
s.writeFileNoError(path,content,false)
324335
}
325336

326-
func (s*testSys)AppendFile(pathstring,textstring) {
327-
content,ok:=s.FS().ReadFile(path)
337+
func (s*testSys)appendFile(pathstring,textstring) {
338+
content,ok:=s.fsFromFileMap().ReadFile(path)
328339
if!ok {
329340
panic("File not found: "+path)
330341
}
331-
s.WriteFileNoError(path,content+text,false)
342+
s.writeFileNoError(path,content+text,false)
332343
}
333344

334-
func (s*testSys)PrependFile(pathstring,textstring) {
335-
content,ok:=s.FS().ReadFile(path)
345+
func (s*testSys)prependFile(pathstring,textstring) {
346+
content,ok:=s.fsFromFileMap().ReadFile(path)
336347
if!ok {
337348
panic("File not found: "+path)
338349
}
339-
s.WriteFileNoError(path,text+content,false)
350+
s.writeFileNoError(path,text+content,false)
340351
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp