Skip to content

Commit c84c4e1

Browse files
committed
Use written files for diffing
1 parent 3372773 commit c84c4e1

11 files changed

+79
-81
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")

testdata/baselines/reference/tsc/incremental/change-to-modifier-of-class-expression-field-with-declaration-emit-enabled.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ Errors Files
195195
1 MessageablePerson.ts:6
196196
1 main.ts:3
197197

198-
//// [/home/src/workspaces/project/MessageablePerson.d.ts] *modified time*
199-
//// [/home/src/workspaces/project/MessageablePerson.js] *modified time*
200-
//// [/home/src/workspaces/project/main.d.ts] *modified time*
201-
//// [/home/src/workspaces/project/main.js] *modified time*
198+
//// [/home/src/workspaces/project/MessageablePerson.d.ts] *rewrite with same content*
199+
//// [/home/src/workspaces/project/MessageablePerson.js] *rewrite with same content*
200+
//// [/home/src/workspaces/project/main.d.ts] *rewrite with same content*
201+
//// [/home/src/workspaces/project/main.js] *rewrite with same content*
202202
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified*
203203
{"version":"FakeTSVersion","fileNames":["../../tslibs/TS/Lib/lib.d.ts","./MessageablePerson.ts","./main.ts"],"fileInfos":[{"version":"4454fdb8db546b8967485a3a7254c948e6876fb850a20e51972933eaf60b5b21-/// \u003creference no-default-lib=\"true\"/\u003e\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array\u003cT\u003e { length: number; [n: number]: T; }\ninterface ReadonlyArray\u003cT\u003e {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };\ntype ReturnType\u003cT extends (...args: any) =\u003e any\u003e = T extends (...args: any) =\u003e infer R ? R : any;\ntype InstanceType\u003cT extends abstract new (...args: any) =\u003e any\u003e = T extends abstract new (...args: any) =\u003e infer R ? R : any;","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"7605d26cb18fccfe18cf0d5b1771a538d665f6b2bb331c9617ebdf38d7c93b29-const Messageable = () =\u003e {\n return class MessageableClass {\n protected message = 'hello';\n }\n};\nconst wrapper = () =\u003e Messageable();\ntype MessageablePerson = InstanceType\u003cReturnType\u003ctypeof wrapper\u003e\u003e;\nexport default MessageablePerson;","signature":"34f86a1082929a2d2c6b784bde116fadfb61a9ee55f5141d4906ef4ce16a89c9-declare const wrapper: () =\u003e {\n new (): {\n message: string;\n };\n};\ntype MessageablePerson = InstanceType\u003cReturnType\u003ctypeof wrapper\u003e\u003e;\nexport default MessageablePerson;\n\n(116,7): error4094: Property 'message' of exported anonymous class type may not be private or protected.\n(116,7): error9027: Add a type annotation to the variable wrapper.","impliedNodeFormat":1},{"version":"1fe1ef024191a0efa3b3b0ec73ee8e703a58d44f6d62caf49268591964dce1de-import MessageablePerson from './MessageablePerson.js';\nfunction logMessage( person: MessageablePerson ) {\n console.log( person.message );\n}","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881-export {};\n","impliedNodeFormat":1}],"fileIdsList":[[2]],"options":{"declaration":true,"module":99},"referencedMap":[[3,1]],"semanticDiagnosticsPerFile":[[3,[{"pos":131,"end":138,"code":2445,"category":1,"message":"Property 'message' is protected and only accessible within class 'MessageableClass' and its subclasses."}]]],"emitDiagnosticsPerFile":[[2,[{"pos":116,"end":123,"code":4094,"category":1,"message":"Property 'message' of exported anonymous class type may not be private or protected.","relatedInformation":[{"pos":116,"end":123,"code":9027,"category":1,"message":"Add a type annotation to the variable wrapper."}]}]]]}
204204
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *modified*
@@ -333,8 +333,8 @@ Errors Files
333333
1 MessageablePerson.ts:6
334334
1 main.ts:3
335335

336-
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified time*
337-
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *modified time*
336+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *rewrite with same content*
337+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *rewrite with same content*
338338

339339
SemanticDiagnostics::
340340
Signatures::
@@ -354,10 +354,10 @@ export default MessageablePerson;
354354
tsgo --incremental
355355
ExitStatus:: Success
356356
Output::
357-
//// [/home/src/workspaces/project/MessageablePerson.d.ts] *modified time*
358-
//// [/home/src/workspaces/project/MessageablePerson.js] *modified time*
359-
//// [/home/src/workspaces/project/main.d.ts] *modified time*
360-
//// [/home/src/workspaces/project/main.js] *modified time*
357+
//// [/home/src/workspaces/project/MessageablePerson.d.ts] *rewrite with same content*
358+
//// [/home/src/workspaces/project/MessageablePerson.js] *rewrite with same content*
359+
//// [/home/src/workspaces/project/main.d.ts] *rewrite with same content*
360+
//// [/home/src/workspaces/project/main.js] *rewrite with same content*
361361
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified*
362362
{"version":"FakeTSVersion","fileNames":["../../tslibs/TS/Lib/lib.d.ts","./MessageablePerson.ts","./main.ts"],"fileInfos":[{"version":"4454fdb8db546b8967485a3a7254c948e6876fb850a20e51972933eaf60b5b21-/// \u003creference no-default-lib=\"true\"/\u003e\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array\u003cT\u003e { length: number; [n: number]: T; }\ninterface ReadonlyArray\u003cT\u003e {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };\ntype ReturnType\u003cT extends (...args: any) =\u003e any\u003e = T extends (...args: any) =\u003e infer R ? R : any;\ntype InstanceType\u003cT extends abstract new (...args: any) =\u003e any\u003e = T extends abstract new (...args: any) =\u003e infer R ? R : any;","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"3be6695caa91776ec738c01ffbc1250eb86f9bca0c22b02335b5e5c7c63bcbaa-const Messageable = () =\u003e {\n return class MessageableClass {\n public message = 'hello';\n }\n};\nconst wrapper = () =\u003e Messageable();\ntype MessageablePerson = InstanceType\u003cReturnType\u003ctypeof wrapper\u003e\u003e;\nexport default MessageablePerson;","signature":"6ec1f7bdc192ba06258caff3fa202fd577f8f354d676f548500eeb232155cbbe-declare const wrapper: () =\u003e {\n new (): {\n message: string;\n };\n};\ntype MessageablePerson = InstanceType\u003cReturnType\u003ctypeof wrapper\u003e\u003e;\nexport default MessageablePerson;\n","impliedNodeFormat":1},{"version":"1fe1ef024191a0efa3b3b0ec73ee8e703a58d44f6d62caf49268591964dce1de-import MessageablePerson from './MessageablePerson.js';\nfunction logMessage( person: MessageablePerson ) {\n console.log( person.message );\n}","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881-export {};\n","impliedNodeFormat":1}],"fileIdsList":[[2]],"options":{"declaration":true,"module":99},"referencedMap":[[3,1]]}
363363
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *modified*

testdata/baselines/reference/tsc/incremental/change-to-modifier-of-class-expression-field.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ Output::
156156

157157
Found 1 error in main.ts:3
158158

159-
//// [/home/src/workspaces/project/MessageablePerson.js] *modified time*
160-
//// [/home/src/workspaces/project/main.js] *modified time*
159+
//// [/home/src/workspaces/project/MessageablePerson.js] *rewrite with same content*
160+
//// [/home/src/workspaces/project/main.js] *rewrite with same content*
161161
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified*
162162
{"version":"FakeTSVersion","fileNames":["../../tslibs/TS/Lib/lib.d.ts","./MessageablePerson.ts","./main.ts"],"fileInfos":[{"version":"4454fdb8db546b8967485a3a7254c948e6876fb850a20e51972933eaf60b5b21-/// \u003creference no-default-lib=\"true\"/\u003e\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array\u003cT\u003e { length: number; [n: number]: T; }\ninterface ReadonlyArray\u003cT\u003e {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };\ntype ReturnType\u003cT extends (...args: any) =\u003e any\u003e = T extends (...args: any) =\u003e infer R ? R : any;\ntype InstanceType\u003cT extends abstract new (...args: any) =\u003e any\u003e = T extends abstract new (...args: any) =\u003e infer R ? R : any;","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"7605d26cb18fccfe18cf0d5b1771a538d665f6b2bb331c9617ebdf38d7c93b29-const Messageable = () =\u003e {\n return class MessageableClass {\n protected message = 'hello';\n }\n};\nconst wrapper = () =\u003e Messageable();\ntype MessageablePerson = InstanceType\u003cReturnType\u003ctypeof wrapper\u003e\u003e;\nexport default MessageablePerson;","signature":"34f86a1082929a2d2c6b784bde116fadfb61a9ee55f5141d4906ef4ce16a89c9-declare const wrapper: () =\u003e {\n new (): {\n message: string;\n };\n};\ntype MessageablePerson = InstanceType\u003cReturnType\u003ctypeof wrapper\u003e\u003e;\nexport default MessageablePerson;\n\n(116,7): error4094: Property 'message' of exported anonymous class type may not be private or protected.\n(116,7): error9027: Add a type annotation to the variable wrapper.","impliedNodeFormat":1},{"version":"1fe1ef024191a0efa3b3b0ec73ee8e703a58d44f6d62caf49268591964dce1de-import MessageablePerson from './MessageablePerson.js';\nfunction logMessage( person: MessageablePerson ) {\n console.log( person.message );\n}","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881-export {};\n","impliedNodeFormat":1}],"fileIdsList":[[2]],"options":{"module":99},"referencedMap":[[3,1]],"semanticDiagnosticsPerFile":[[3,[{"pos":131,"end":138,"code":2445,"category":1,"message":"Property 'message' is protected and only accessible within class 'MessageableClass' and its subclasses."}]]]}
163163
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *modified*
@@ -274,8 +274,8 @@ export default MessageablePerson;
274274
tsgo --incremental
275275
ExitStatus:: Success
276276
Output::
277-
//// [/home/src/workspaces/project/MessageablePerson.js] *modified time*
278-
//// [/home/src/workspaces/project/main.js] *modified time*
277+
//// [/home/src/workspaces/project/MessageablePerson.js] *rewrite with same content*
278+
//// [/home/src/workspaces/project/main.js] *rewrite with same content*
279279
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified*
280280
{"version":"FakeTSVersion","fileNames":["../../tslibs/TS/Lib/lib.d.ts","./MessageablePerson.ts","./main.ts"],"fileInfos":[{"version":"4454fdb8db546b8967485a3a7254c948e6876fb850a20e51972933eaf60b5b21-/// \u003creference no-default-lib=\"true\"/\u003e\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array\u003cT\u003e { length: number; [n: number]: T; }\ninterface ReadonlyArray\u003cT\u003e {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };\ntype ReturnType\u003cT extends (...args: any) =\u003e any\u003e = T extends (...args: any) =\u003e infer R ? R : any;\ntype InstanceType\u003cT extends abstract new (...args: any) =\u003e any\u003e = T extends abstract new (...args: any) =\u003e infer R ? R : any;","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"3be6695caa91776ec738c01ffbc1250eb86f9bca0c22b02335b5e5c7c63bcbaa-const Messageable = () =\u003e {\n return class MessageableClass {\n public message = 'hello';\n }\n};\nconst wrapper = () =\u003e Messageable();\ntype MessageablePerson = InstanceType\u003cReturnType\u003ctypeof wrapper\u003e\u003e;\nexport default MessageablePerson;","signature":"6ec1f7bdc192ba06258caff3fa202fd577f8f354d676f548500eeb232155cbbe-declare const wrapper: () =\u003e {\n new (): {\n message: string;\n };\n};\ntype MessageablePerson = InstanceType\u003cReturnType\u003ctypeof wrapper\u003e\u003e;\nexport default MessageablePerson;\n","impliedNodeFormat":1},{"version":"1fe1ef024191a0efa3b3b0ec73ee8e703a58d44f6d62caf49268591964dce1de-import MessageablePerson from './MessageablePerson.js';\nfunction logMessage( person: MessageablePerson ) {\n console.log( person.message );\n}","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881-export {};\n","impliedNodeFormat":1}],"fileIdsList":[[2]],"options":{"module":99},"referencedMap":[[3,1]]}
281281
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *modified*

0 commit comments

Comments
 (0)