Skip to content

Commit 72edb9e

Browse files
authored
Updatess to tsc tests (#1589)
1 parent ae2bacc commit 72edb9e

File tree

55 files changed

+690
-247
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+690
-247
lines changed

cmd/tsgo/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ func runMain() int {
2020
return runAPI(args[1:])
2121
}
2222
}
23-
result := execute.CommandLine(newSystem(), args, false)
23+
result := execute.CommandLine(newSystem(), args, nil)
2424
return int(result.Status)
2525
}

cmd/tsgo/sys.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@ func (s *osSys) Writer() io.Writer {
4646
return s.writer
4747
}
4848

49-
func (s *osSys) EndWrite() {
50-
// do nothing, this is needed in the interface for testing
51-
// todo: revisit if improving tsc/build/watch unittest baselines
52-
}
53-
5449
func (s *osSys) WriteOutputIsTTY() bool {
5550
return term.IsTerminal(int(os.Stdout.Fd()))
5651
}

internal/diagnosticwriter/diagnosticwriter.go

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,41 @@ func FormatDiagnosticsWithColorAndContext(output io.Writer, diags []*ast.Diagnos
4444
if i > 0 {
4545
fmt.Fprint(output, formatOpts.NewLine)
4646
}
47+
FormatDiagnosticWithColorAndContext(output, diagnostic, formatOpts)
48+
}
49+
}
4750

48-
if diagnostic.File() != nil {
49-
file := diagnostic.File()
50-
pos := diagnostic.Loc().Pos()
51-
WriteLocation(output, file, pos, formatOpts, writeWithStyleAndReset)
52-
fmt.Fprint(output, " - ")
53-
}
51+
func FormatDiagnosticWithColorAndContext(output io.Writer, diagnostic *ast.Diagnostic, formatOpts *FormattingOptions) {
52+
if diagnostic.File() != nil {
53+
file := diagnostic.File()
54+
pos := diagnostic.Loc().Pos()
55+
WriteLocation(output, file, pos, formatOpts, writeWithStyleAndReset)
56+
fmt.Fprint(output, " - ")
57+
}
5458

55-
writeWithStyleAndReset(output, diagnostic.Category().Name(), getCategoryFormat(diagnostic.Category()))
56-
fmt.Fprintf(output, "%s TS%d: %s", foregroundColorEscapeGrey, diagnostic.Code(), resetEscapeSequence)
57-
WriteFlattenedDiagnosticMessage(output, diagnostic, formatOpts.NewLine)
59+
writeWithStyleAndReset(output, diagnostic.Category().Name(), getCategoryFormat(diagnostic.Category()))
60+
fmt.Fprintf(output, "%s TS%d: %s", foregroundColorEscapeGrey, diagnostic.Code(), resetEscapeSequence)
61+
WriteFlattenedDiagnosticMessage(output, diagnostic, formatOpts.NewLine)
5862

59-
if diagnostic.File() != nil && diagnostic.Code() != diagnostics.File_appears_to_be_binary.Code() {
60-
fmt.Fprint(output, formatOpts.NewLine)
61-
writeCodeSnippet(output, diagnostic.File(), diagnostic.Pos(), diagnostic.Len(), getCategoryFormat(diagnostic.Category()), "", formatOpts)
62-
fmt.Fprint(output, formatOpts.NewLine)
63-
}
63+
if diagnostic.File() != nil && diagnostic.Code() != diagnostics.File_appears_to_be_binary.Code() {
64+
fmt.Fprint(output, formatOpts.NewLine)
65+
writeCodeSnippet(output, diagnostic.File(), diagnostic.Pos(), diagnostic.Len(), getCategoryFormat(diagnostic.Category()), "", formatOpts)
66+
fmt.Fprint(output, formatOpts.NewLine)
67+
}
6468

65-
if (diagnostic.RelatedInformation() != nil) && (len(diagnostic.RelatedInformation()) > 0) {
66-
for _, relatedInformation := range diagnostic.RelatedInformation() {
67-
file := relatedInformation.File()
68-
if file != nil {
69-
fmt.Fprint(output, formatOpts.NewLine)
70-
fmt.Fprint(output, " ")
71-
pos := relatedInformation.Pos()
72-
WriteLocation(output, file, pos, formatOpts, writeWithStyleAndReset)
73-
fmt.Fprint(output, " - ")
74-
WriteFlattenedDiagnosticMessage(output, relatedInformation, formatOpts.NewLine)
75-
writeCodeSnippet(output, file, pos, relatedInformation.Len(), foregroundColorEscapeCyan, " ", formatOpts)
76-
}
69+
if (diagnostic.RelatedInformation() != nil) && (len(diagnostic.RelatedInformation()) > 0) {
70+
for _, relatedInformation := range diagnostic.RelatedInformation() {
71+
file := relatedInformation.File()
72+
if file != nil {
7773
fmt.Fprint(output, formatOpts.NewLine)
74+
fmt.Fprint(output, " ")
75+
pos := relatedInformation.Pos()
76+
WriteLocation(output, file, pos, formatOpts, writeWithStyleAndReset)
77+
fmt.Fprint(output, " - ")
78+
WriteFlattenedDiagnosticMessage(output, relatedInformation, formatOpts.NewLine)
79+
writeCodeSnippet(output, file, pos, relatedInformation.Len(), foregroundColorEscapeCyan, " ", formatOpts)
7880
}
81+
fmt.Fprint(output, formatOpts.NewLine)
7982
}
8083
}
8184
}

internal/execute/outputs.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,18 @@ func getFormatOptsOfSys(sys System) *diagnosticwriter.FormattingOptions {
3131

3232
type diagnosticReporter = func(*ast.Diagnostic)
3333

34+
func quietDiagnosticReporter(diagnostic *ast.Diagnostic) {}
3435
func createDiagnosticReporter(sys System, options *core.CompilerOptions) diagnosticReporter {
3536
if options.Quiet.IsTrue() {
36-
return func(diagnostic *ast.Diagnostic) {}
37+
return quietDiagnosticReporter
3738
}
3839

3940
formatOpts := getFormatOptsOfSys(sys)
40-
if !shouldBePretty(sys, options) {
41-
return func(diagnostic *ast.Diagnostic) {
42-
diagnosticwriter.WriteFormatDiagnostic(sys.Writer(), diagnostic, formatOpts)
43-
sys.EndWrite()
44-
}
45-
}
41+
writeDiagnostic := core.IfElse(shouldBePretty(sys, options), diagnosticwriter.FormatDiagnosticWithColorAndContext, diagnosticwriter.WriteFormatDiagnostic)
42+
4643
return func(diagnostic *ast.Diagnostic) {
47-
diagnosticwriter.FormatDiagnosticsWithColorAndContext(sys.Writer(), []*ast.Diagnostic{diagnostic}, formatOpts)
48-
sys.EndWrite()
44+
writeDiagnostic(sys.Writer(), diagnostic, formatOpts)
45+
fmt.Fprint(sys.Writer(), formatOpts.NewLine)
4946
}
5047
}
5148

@@ -132,15 +129,18 @@ func createReportErrorSummary(sys System, options *core.CompilerOptions) func(di
132129
formatOpts := getFormatOptsOfSys(sys)
133130
return func(diagnostics []*ast.Diagnostic) {
134131
diagnosticwriter.WriteErrorSummaryText(sys.Writer(), diagnostics, formatOpts)
135-
sys.EndWrite()
136132
}
137133
}
138134
return func(diagnostics []*ast.Diagnostic) {}
139135
}
140136

141-
func reportStatistics(sys System, program *compiler.Program, result compileAndEmitResult, memStats *runtime.MemStats) {
137+
func reportStatistics(sys System, program *compiler.Program, result compileAndEmitResult, memStats *runtime.MemStats, testing CommandLineTesting) {
142138
var stats table
143139

140+
if testing != nil {
141+
testing.OnStatisticsStart()
142+
defer testing.OnStatisticsEnd()
143+
}
144144
stats.add("Files", len(program.SourceFiles()))
145145
stats.add("Lines", program.LineCount())
146146
stats.add("Identifiers", program.IdentifierCount())
@@ -175,7 +175,6 @@ func reportStatistics(sys System, program *compiler.Program, result compileAndEm
175175

176176
func printVersion(sys System) {
177177
fmt.Fprintln(sys.Writer(), diagnostics.Version_0.Format(core.Version()))
178-
sys.EndWrite()
179178
}
180179

181180
func printHelp(sys System, commandLine *tsoptions.ParsedCommandLine) {
@@ -268,7 +267,6 @@ func printEasyHelp(sys System, simpleOptions []*tsoptions.CommandLineOption) {
268267
for _, chunk := range output {
269268
fmt.Fprint(sys.Writer(), chunk)
270269
}
271-
sys.EndWrite()
272270
}
273271

274272
func generateSectionOptionsOutput(

internal/execute/system.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
type System interface {
1111
Writer() io.Writer
12-
EndWrite() // needed for testing
1312
FS() vfs.FS
1413
DefaultLibraryPath() string
1514
GetCurrentDirectory() string

0 commit comments

Comments
 (0)