@@ -141,6 +141,7 @@ type snapshot struct {
141
141
type testSys struct {
142
142
currentWrite * strings.Builder
143
143
programBaselines strings.Builder
144
+ programIncludeBaselines strings.Builder
144
145
tracer * harnessutil.TracerForBaselining
145
146
serializedDiff * snapshot
146
147
forIncrementalCorrectness bool
@@ -287,18 +288,23 @@ func (s *testSys) GetTrace(w io.Writer) func(str string) {
287
288
}
288
289
}
289
290
290
- func (s * testSys ) OnProgram ( program * incremental.Program ) {
291
- if s . programBaselines .Len () != 0 {
292
- s . programBaselines .WriteString ("\n " )
291
+ func (s * testSys ) writeHeaderToBaseline ( builder * strings. Builder , program * incremental.Program ) {
292
+ if builder .Len () != 0 {
293
+ builder .WriteString ("\n " )
293
294
}
294
295
295
- testingData := program .GetTestingData ()
296
296
if configFilePath := program .Options ().ConfigFilePath ; configFilePath != "" {
297
- s . programBaselines .WriteString (tspath .GetRelativePathFromDirectory (s .cwd , configFilePath , tspath.ComparePathsOptions {
297
+ builder .WriteString (tspath .GetRelativePathFromDirectory (s .cwd , configFilePath , tspath.ComparePathsOptions {
298
298
UseCaseSensitiveFileNames : s .FS ().UseCaseSensitiveFileNames (),
299
299
CurrentDirectory : s .GetCurrentDirectory (),
300
300
}) + "::\n " )
301
301
}
302
+ }
303
+
304
+ func (s * testSys ) OnProgram (program * incremental.Program ) {
305
+ s .writeHeaderToBaseline (& s .programBaselines , program )
306
+
307
+ testingData := program .GetTestingData ()
302
308
s .programBaselines .WriteString ("SemanticDiagnostics::\n " )
303
309
for _ , file := range program .GetProgram ().GetSourceFiles () {
304
310
if diagnostics , ok := testingData .SemanticDiagnosticsPerFile .Load (file .Path ()); ok {
@@ -324,11 +330,44 @@ func (s *testSys) OnProgram(program *incremental.Program) {
324
330
}
325
331
}
326
332
}
333
+
334
+ var filesWithoutIncludeReason []string
335
+ var fileNotInProgramWithIncludeReason []string
336
+ includeReasons := program .GetProgram ().GetIncludeReasons ()
337
+ for _ , file := range program .GetProgram ().GetSourceFiles () {
338
+ if _ , ok := includeReasons [file .Path ()]; ! ok {
339
+ filesWithoutIncludeReason = append (filesWithoutIncludeReason , string (file .Path ()))
340
+ }
341
+ }
342
+ for path := range includeReasons {
343
+ if program .GetProgram ().GetSourceFileByPath (path ) == nil && ! program .GetProgram ().IsMissingPath (path ) {
344
+ fileNotInProgramWithIncludeReason = append (fileNotInProgramWithIncludeReason , string (path ))
345
+ }
346
+ }
347
+ if len (filesWithoutIncludeReason ) > 0 || len (fileNotInProgramWithIncludeReason ) > 0 {
348
+ s .writeHeaderToBaseline (& s .programIncludeBaselines , program )
349
+ s .programIncludeBaselines .WriteString ("!!! Expected all files to have include reasons\n filesWithoutIncludeReason::\n " )
350
+ for _ , file := range filesWithoutIncludeReason {
351
+ s .programIncludeBaselines .WriteString (" " + file + "\n " )
352
+ }
353
+ s .programIncludeBaselines .WriteString ("filesNotInProgramWithIncludeReason::\n " )
354
+ for _ , file := range fileNotInProgramWithIncludeReason {
355
+ s .programIncludeBaselines .WriteString (" " + file + "\n " )
356
+ }
357
+ }
327
358
}
328
359
329
- func (s * testSys ) baselinePrograms (baseline * strings.Builder ) {
360
+ func (s * testSys ) baselinePrograms (baseline * strings.Builder , header string ) string {
330
361
baseline .WriteString (s .programBaselines .String ())
331
362
s .programBaselines .Reset ()
363
+ var result string
364
+ if s .programIncludeBaselines .Len () > 0 {
365
+ result += fmt .Sprintf ("\n \n %s\n !!! Include reasons expectations don't match pls review!!!\n " , header )
366
+ result += s .programIncludeBaselines .String ()
367
+ s .programIncludeBaselines .Reset ()
368
+ baseline .WriteString (result )
369
+ }
370
+ return result
332
371
}
333
372
334
373
func (s * testSys ) serializeState (baseline * strings.Builder ) {
0 commit comments