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

Add compiler test runner #115

merged 54 commits into from
Jan 10, 2025

Conversation

gabritto
Copy link
Member

@gabritto gabritto commented Nov 29, 2024

This adds a compiler test runner, capable of running compiler tests with error baselines, which is the only kind of baseline we have so far.

Things missing:

  • No tsconfig parsing yet
  • No compiler or harness options parsing yet
  • No symlinks

Things temporary:

  • Program creation is temporary because we don't have a proper createProgram yet, one that takes root files etc.

I also have to move the tests to a compiler_test package or something, but I don't think the tests are useful now, so maybe I'll do that later.

You can run specific compiler tests like so:
$ go test -run TestCompilerBaselines/.*/simpleTestSingleFile github.com/microsoft/typescript-go/internal/testutil/runner

The command for diffing baselines also has to change to something like
git diff --diff-filter=AM --no-index ./testdata/baselines/reference ./testdata/baselines/local

@jakebailey
Copy link
Member

One thing I was envisioning here was that for all existing tests in the TS codebase, we don't acutally check in any test artifacts, but instead diff them against what we have here and check those diffs in; if the diff is missing (or, should be deleted) the test errors out. That way we can slowly pare things down to nothing until we get to parity.

We can add new tests which contribute real baselines, which could be separate, though.

It's not clear that we could do that without all of the other stuff ready, though, e.g. actual program construction. Perhaps that implies that this PR should be restructured to not actually reference testing.T/testing.TB, and instead return all results in a struct for a future test to do with. Then we can diff for some cases, not diff for others.

@jakebailey
Copy link
Member

Of course, I say that, but we still need to use t.Run() to generate the tests in order to be able to target just one...

@gabritto gabritto marked this pull request as draft December 16, 2024 18:33
@gabritto gabritto marked this pull request as ready for review January 6, 2025 23:42
@gabritto gabritto requested a review from jakebailey January 6, 2025 23:42
@jakebailey

This comment was marked as off-topic.

@jakebailey

This comment was marked as off-topic.

@jakebailey jakebailey mentioned this pull request Jan 7, 2025
@gabritto gabritto changed the base branch from main to gabritto/symbolbaseline January 7, 2025 19:30
@jakebailey
Copy link
Member

I approved #191; I assume this PR contains it, so I'll give this a harder look after #191 is merged.

Base automatically changed from gabritto/symbolbaseline to main January 8, 2025 03:25
@@ -0,0 +1,430 @@
package harnessutil
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't put this in testutil because it would cause a cycle with vfstest.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testutil itself is only meant for helpers for writing tests (e.g. an extension to assert) and should be dependency free, so I think what you've done here is good. Potentially we should just move its contents to a package like assertx or xassert (not an uncommon naming convention to "extend" another package), but I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly to me this means that testutil is actually the wrong place for any of this harness/runner stuff; I think I just didn't notice where it was going initially...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I move runner, this one, and baseline to some other folder? Maybe "testharness".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yes, but I don't think it has to be this PR.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be good; the errors and symbols baselines look good so far. I skimmed the rest and didn't notice anything else.

I'm mainly interested in the next stage, running our existing tests and diffing them, but that requires more code and tsconfig parsing, etc.

Comment on lines 21 to 23
compilerBaselineRegex = regexp.MustCompile(`\.tsx?$`)
requireRegex = regexp.MustCompile(`require\(`)
referencesRegex = regexp.MustCompile(`reference\spath`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some level I wonder if these can be dropped, given these seem like things that can be pretty easily found with regular string operations...


func NewCompilerBaselineRunner(testType CompilerTestType) *CompilerBaselineRunner {
testSuitName := testType.String()
basePath := "tests/cases/" + testSuitName
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to change, or is it a part of some other message we're expecting to keep/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand, why would it need to change? basePath is the path within testdata where we get the test files from.

@gabritto gabritto enabled auto-merge (squash) January 10, 2025 02:02
@gabritto gabritto merged commit fcb4ab1 into main Jan 10, 2025
14 checks passed
@gabritto gabritto deleted the gabritto/runner branch January 10, 2025 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants