Skip to content

Add compiler test runner #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
0635c55
WIP: add compiler runner
gabritto Nov 15, 2024
5094176
add test config functions
gabritto Nov 18, 2024
a08b658
Merge branch 'main' into gabritto/runner
gabritto Nov 18, 2024
292a7c5
add compiler test creation
gabritto Nov 18, 2024
daca070
add more things
gabritto Nov 22, 2024
d4b05d6
Merge branch 'main' into gabritto/runner
gabritto Nov 22, 2024
6c59b48
merge vfs
gabritto Nov 22, 2024
cce7a22
initial test for test runner
gabritto Nov 22, 2024
120b02e
Merge branch 'main' into gabritto/runner
gabritto Nov 23, 2024
01246be
add rootless files to MapFS
gabritto Nov 25, 2024
7f3515a
minor fixes
gabritto Nov 25, 2024
bf6eb2a
add temporary copy of lib to test data
gabritto Nov 25, 2024
e5b77a1
more path fixes; test with multiple files
gabritto Nov 26, 2024
32c1802
update comments
gabritto Nov 27, 2024
c6db098
Merge branch 'main' into gabritto/runner
gabritto Nov 27, 2024
c26c629
change test name so we can use -run, and add descriptions
gabritto Nov 27, 2024
f25e6fa
refactor
gabritto Nov 28, 2024
fd7cd05
remove local baselines before running test
gabritto Nov 29, 2024
5b74f1b
organize functions
gabritto Nov 29, 2024
fdb762d
make one subtest for each type of compiler
gabritto Nov 29, 2024
7f98f96
add conformance test
gabritto Nov 29, 2024
c7ba10e
add symbol baseline generation
gabritto Dec 14, 2024
a31164b
fix compiler errors
gabritto Dec 17, 2024
ef47b9a
Merge branch 'main' into gabritto/runner
gabritto Dec 17, 2024
d68d781
Merge branch 'gabritto/symbolbaseline' into gabritto/runner
gabritto Dec 17, 2024
04ff9cc
add symbol baselines
gabritto Dec 18, 2024
68de1dc
remove unnecessary code
gabritto Dec 18, 2024
e892a68
pass down options instead of pointer
gabritto Dec 18, 2024
619db63
use testing.T in baselines
gabritto Jan 3, 2025
7bd349e
run type and symbol baselines as subtests
gabritto Jan 3, 2025
9b18529
Merge branch 'main' into gabritto/symbolbaseline
gabritto Jan 3, 2025
4f61e6d
fix fmt and merge bug
gabritto Jan 3, 2025
6b4ef82
Merge branch 'gabritto/symbolbaseline' into gabritto/runner
gabritto Jan 3, 2025
7809902
move harness utils into own package to avoid cycle
gabritto Jan 3, 2025
a1b87f1
use bundled lib, update baselines
gabritto Jan 3, 2025
4aaed88
fix regex and helper for symbol baselines
gabritto Jan 3, 2025
de51332
remove useless checkDuplicateName
gabritto Jan 6, 2025
eaaa9d5
Merge branch 'gabritto/symbolbaseline' into gabritto/runner
gabritto Jan 6, 2025
1c25899
remove lib copying for testing, disable type baselines stub
gabritto Jan 6, 2025
53d0c5e
pass subfolder for baselines, update existing baselines
gabritto Jan 6, 2025
09bd8af
Merge branch 'main' into gabritto/runner
gabritto Jan 6, 2025
3d7f5ad
Merge branch 'main' into gabritto/symbolbaseline
gabritto Jan 6, 2025
1842745
add CI step to print baselines
gabritto Jan 6, 2025
2066cd3
fix header of symbol baselines to be relative path
gabritto Jan 6, 2025
4deff4e
skip compiler baselines if noembed
gabritto Jan 6, 2025
bef677d
Merge branch 'main' into gabritto/runner
gabritto Jan 6, 2025
024e9b9
create public versions of getSymbolAtLocation and symbolToString
gabritto Jan 7, 2025
dbc0a63
Merge branch 'main' into gabritto/symbolbaseline
gabritto Jan 7, 2025
ff755f9
Merge branch 'gabritto/symbolbaseline' into gabritto/runner
gabritto Jan 7, 2025
19f8111
Merge branch 'main' into gabritto/runner
gabritto Jan 8, 2025
7a29ff5
readd space to yml
gabritto Jan 8, 2025
7778f5e
cleanup
gabritto Jan 8, 2025
f56ce9d
simplify require regex to string
gabritto Jan 10, 2025
4b305ec
Merge branch 'main' into gabritto/runner
gabritto Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,8 @@ go.work.sum
# Benchmarking results
*.txt

# Re-add baseline references
!testdata/baselines/reference/**/*.txt

# Local baselines
testdata/baselines/local
5 changes: 0 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ linters:
- unconvert
- usestdlibvars
- whitespace
- wrapcheck

# Need to add headers
# - goheader
Expand All @@ -56,10 +55,6 @@ linters:
# - unused

linters-settings:
wrapcheck:
ignorePackageGlobs:
- encoding/*
- github.com/go-json-experiment/*
# revive:
# enable-all-rules: true
# rules:
Expand Down
2 changes: 1 addition & 1 deletion internal/compiler/error_reporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func WriteFormatDiagnostic(output *strings.Builder, diagnostic *ast.Diagnostic,
fmt.Fprintf(output, "%s(%d,%d): ", relativeFileName, line+1, character+1)
}

fmt.Fprintf(output, "%s TS%d: ", diagnostic.Category().String(), diagnostic.Code())
fmt.Fprintf(output, "%s TS%d: ", diagnostic.Category().Name(), diagnostic.Code())
WriteFlattenedDiagnosticMessage(output, diagnostic, formatOpts.NewLine)
output.WriteString(formatOpts.NewLine)
}
12 changes: 12 additions & 0 deletions internal/core/compileroptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type CompilerOptions struct {
AllowUnusedLabels Tristate `json:"allowUnusedLabels"`
CheckJs Tristate `json:"checkJs"`
CustomConditions []string `json:"customConditions"`
Declaration Tristate `json:"declaration"`
ESModuleInterop Tristate `json:"esModuleInterop"`
ExactOptionalPropertyTypes Tristate `json:"exactOptionalPropertyTypes"`
ExperimentalDecorators Tristate `json:"experimentalDecorators"`
Expand All @@ -25,6 +26,8 @@ type CompilerOptions struct {
ModuleKind ModuleKind `json:"module"`
ModuleResolution ModuleResolutionKind `json:"moduleResolution"`
ModuleSuffixes []string `json:"moduleSuffixes"`
NewLine NewLineKind `json:"newLine"`
NoErrorTruncation Tristate `json:"noErrorTruncation"`
NoFallthroughCasesInSwitch Tristate `json:"noFallthroughCasesInSwitch"`
NoImplicitAny Tristate `json:"noImplicitAny"`
NoImplicitThis Tristate `json:"noImplicitThis"`
Expand All @@ -36,6 +39,7 @@ type CompilerOptions struct {
ResolveJsonModule Tristate `json:"resolveJsonModule"`
ResolvePackageJsonExports Tristate `json:"resolvePackageJsonExports"`
ResolvePackageJsonImports Tristate `json:"resolvePackageJsonImports"`
SkipLibCheck Tristate `json:"skipLibCheck"`
Strict Tristate `json:"strict"`
StrictBindCallApply Tristate `json:"strictBindCallApply"`
StrictNullChecks Tristate `json:"strictNullChecks"`
Expand Down Expand Up @@ -245,3 +249,11 @@ const (
ScriptTargetJSON ScriptTarget = 100
ScriptTargetLatest ScriptTarget = ScriptTargetESNext
)

type NewLineKind int32

const (
NewLineKindNone NewLineKind = 0
NewLineKindCRLF NewLineKind = 1
NewLineKindLF NewLineKind = 2
)
35 changes: 15 additions & 20 deletions internal/testutil/baseline/error_baseline.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/compiler"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/testutil"
"github.com/microsoft/typescript-go/internal/tspath"
"gotest.tools/v3/assert"
"gotest.tools/v3/assert/cmp"
Expand All @@ -28,24 +29,18 @@ var formatOpts = &compiler.DiagnosticsFormattingOptions{
NewLine: harnessNewLine,
}

type TestFile struct {
unitName string
content string
fileOptions map[string]string
}

var diagnosticsLocationPrefix = regexp.MustCompile(`(?im)^(lib.*\.d\.ts)\(\d+,\d+\)`)
var diagnosticsLocationPattern = regexp.MustCompile(`(?i)(lib.*\.d\.ts):\d+:\d+`)

func DoErrorBaseline(t testing.TB, baselinePath string, inputFiles []*TestFile, errors []*ast.Diagnostic, pretty bool) {
func DoErrorBaseline(t testing.TB, baselinePath string, inputFiles []*testutil.TestFile, errors []*ast.Diagnostic, pretty bool, subfolder string) {
baselinePath = tsExtension.ReplaceAllString(baselinePath, ".errors.txt")
var errorBaseline string
if len(errors) > 0 {
errorBaseline = getErrorBaseline(t, inputFiles, errors, pretty)
} else {
errorBaseline = NoContent
}
Run(t, baselinePath, errorBaseline, Options{})
Run(t, baselinePath, errorBaseline, Options{Subfolder: subfolder})
}

func minimalDiagnosticsToString(diagnostics []*ast.Diagnostic, pretty bool) string {
Expand All @@ -58,7 +53,7 @@ func minimalDiagnosticsToString(diagnostics []*ast.Diagnostic, pretty bool) stri
return output.String()
}

func getErrorBaseline(t testing.TB, inputFiles []*TestFile, diagnostics []*ast.Diagnostic, pretty bool) string {
func getErrorBaseline(t testing.TB, inputFiles []*testutil.TestFile, diagnostics []*ast.Diagnostic, pretty bool) string {
t.Helper()
outputLines := iterateErrorBaseline(t, inputFiles, diagnostics, pretty)

Expand All @@ -74,7 +69,7 @@ func getErrorBaseline(t testing.TB, inputFiles []*TestFile, diagnostics []*ast.D
return strings.Join(outputLines, "")
}

func iterateErrorBaseline(t testing.TB, inputFiles []*TestFile, inputDiagnostics []*ast.Diagnostic, pretty bool) []string {
func iterateErrorBaseline(t testing.TB, inputFiles []*testutil.TestFile, inputDiagnostics []*ast.Diagnostic, pretty bool) []string {
t.Helper()
diagnostics := slices.Clone(inputDiagnostics)
slices.SortFunc(diagnostics, compiler.CompareDiagnostics)
Expand Down Expand Up @@ -105,7 +100,7 @@ func iterateErrorBaseline(t testing.TB, inputFiles []*TestFile, inputDiagnostics
if len(line) < 0 {
continue
}
out := fmt.Sprintf("!!! %s TS%d: %s", diag.Category().String(), diag.Code(), line)
out := fmt.Sprintf("!!! %s TS%d: %s", diag.Category().Name(), diag.Code(), line)
errLines = append(errLines, out)
}

Expand Down Expand Up @@ -158,35 +153,35 @@ func iterateErrorBaseline(t testing.TB, inputFiles []*TestFile, inputDiagnostics

// 'merge' the lines of each input file with any errors associated with it
dupeCase := map[string]int{}
nonEmptyFiles := core.Filter(inputFiles, func(f *TestFile) bool { return len(f.content) > 0 })
nonEmptyFiles := core.Filter(inputFiles, func(f *testutil.TestFile) bool { return len(f.Content) > 0 })
for _, inputFile := range nonEmptyFiles {
// Filter down to the errors in the file
fileErrors := core.Filter(diagnostics, func(e *ast.Diagnostic) bool {
return e.File() != nil &&
tspath.ComparePaths(removeTestPathPrefixes(e.File().FileName(), false), removeTestPathPrefixes(inputFile.unitName, false), tspath.ComparePathsOptions{}) == 0
tspath.ComparePaths(removeTestPathPrefixes(e.File().FileName(), false), removeTestPathPrefixes(inputFile.UnitName, false), tspath.ComparePathsOptions{}) == 0
})

// Header
fmt.Fprintf(&outputLines,
"%s==== %s (%d errors) ====",
newLine(),
removeTestPathPrefixes(inputFile.unitName, false),
removeTestPathPrefixes(inputFile.UnitName, false),
len(fileErrors),
)

// Make sure we emit something for every error
markedErrorCount := 0
// For each line, emit the line followed by any error squiggles matching this line

lineStarts := core.ComputeLineStarts(inputFile.content)
lines := lineDelimiter.Split(inputFile.content, -1)
lineStarts := core.ComputeLineStarts(inputFile.Content)
lines := lineDelimiter.Split(inputFile.Content, -1)

for lineIndex, line := range lines {
thisLineStart := int(lineStarts[lineIndex])
var nextLineStart int
// On the last line of the file, fake the next line start number so that we handle errors on the last character of the file correctly
if lineIndex == len(lines)-1 {
nextLineStart = len(inputFile.content)
nextLineStart = len(inputFile.Content)
} else {
nextLineStart = int(lineStarts[lineIndex+1])
}
Expand Down Expand Up @@ -220,9 +215,9 @@ func iterateErrorBaseline(t testing.TB, inputFiles []*TestFile, inputDiagnostics
}

// Verify we didn't miss any errors in this file
assert.Check(t, cmp.Equal(markedErrorCount, len(fileErrors)), "count of errors in "+inputFile.unitName)
_, isDupe := dupeCase[sanitizeTestFilePath(inputFile.unitName)]
checkDuplicatedFileName(inputFile.unitName, dupeCase)
assert.Check(t, cmp.Equal(markedErrorCount, len(fileErrors)), "count of errors in "+inputFile.UnitName)
_, isDupe := dupeCase[sanitizeTestFilePath(inputFile.UnitName)]
checkDuplicatedFileName(inputFile.UnitName, dupeCase)
result = append(result, outputLines.String())
if isDupe {
// Case-duplicated files on a case-insensitive build will have errors reported in both the dupe and the original
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/baseline/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var testPathPrefix = regexp.MustCompile(`(?:(file:\/{3})|\/)\.(?:ts|lib|src)\/`)
var testPathCharacters = regexp.MustCompile(`[\^<>:"|?*%]`)
var testPathDotDot = regexp.MustCompile(`\.\.\/`)

var libFolder = "built/local/"
var libFolder = "built/local/" // !!! This needs to change
var builtFolder = "/.ts"

func removeTestPathPrefixes(text string, retainTrailingDirectorySeparator bool) string {
Expand Down
Loading