Skip to content

Allow running tests by line and column #1604

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 13 commits into from
Oct 19, 2021
Merged

Allow running tests by line and column #1604

merged 13 commits into from
Oct 19, 2021

Conversation

jakemac53
Copy link
Contributor

@jakemac53 jakemac53 commented Oct 15, 2021

Fixes #1579

  • Allows querying tests by line & col using test path query strings
  • Matches if any frame in the test stack trace matches up (this allows for lots of flexibility in terms of testing styles and parameterized tests).

This does not currently work on browsers, but I probably could get it to? Not sure how important that ultimately is.

  • If a stack trace formatter is set up for the remote platform, it will use it to format the trace sent back for groups/tests that are discovered (enabling browser/node support).

cc @DanTup

@jakemac53 jakemac53 requested a review from natebosch October 15, 2021 23:24
@google-cla google-cla bot added the cla: yes label Oct 15, 2021
- **full-name**: Requires an match for the name of the test.
- **line**: Matches any test that originates from this line in the test suite.
- Not supported for browser tests.
- **col**: Matches any test that originates from this column in the test suite.
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused who would use this? Is this a specific column? Like the position of the first t in test(?

Copy link
Contributor Author

@jakemac53 jakemac53 Oct 15, 2021

Choose a reason for hiding this comment

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

Yes - only IDEs would use it most likely

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason for it is protection against accidentally running tests the user doesn't expect if they have duplicate names:

// Click "Run" next to this test currently runs both tests, which seems odd to the user
test('foo', () {});

test('foo', () {});

Although the IDE will need to be sure of the package:test version before trying to use these new features.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya and having the col option specifically guards against having two tests on the same line. A rare situation but its trivial to support once we are already supporting filtering by line.

Copy link
Member

Choose a reason for hiding this comment

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

I still don't understand the precise position this matches.

Is it exactly the first t in test? Is it 0 based? Does this match the same frame as the line number, or can the line match one frame and the column match a different frame?

I'll read through the test cases tomorrow to find out more, but I do think we should expand the user facing docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It matches the column position of the function invocation in the stack trace. That is the position of the first character of the name of the function (so if your cursor is to the left of it). It is one based, which matches what the IDE reports (or at least VsCode, I assume this is standard?).

I'll read through the test cases tomorrow to find out more, but I do think we should expand the user facing docs.

There is a sentence after these that says "all filters must match for a test to be ran". I could move it to the top?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I added a mini section under this describing the specific line/col semantics, and also moved the note about all filters matching up to the first paragraph.

@DanTup
Copy link
Contributor

DanTup commented Oct 18, 2021

Matches if any frame in the test stack trace matches up (this allows for lots of flexibility in terms of testing styles and parameterized tests).

I presume this is to support things like testWidgets where the actual test call is inside some helper, and the IDE is passing the line number for the testWidgets call? If so, does it filter the call stack by the filename too?

eg. if I pass my_foo_test.dart?line=10&col=10 I would expect it to match my_foo_test.dart on line/col 10 anywhere in the call stack, but not other files that happens to have a 10:10 in the call stack? (for example, if you happened to create a testWidget that was on the same line as the real test call inside testWidget, you wouldn't want all tests to run).

(although, maybe that wouldn't be a big deal if it's encouraged to always pass a name, even when using line/col).

@jakemac53
Copy link
Contributor Author

I presume this is to support things like testWidgets where the actual test call is inside some helper, and the IDE is passing the line number for the testWidgets call?

Yes exactly, it essentially allows for "parameterized tests". Probably the IDE doesn't have enough info to know about these actual call sites though (the "root_line" etc would be the actual test call still, since its the first frame in the current file).

If so, does it filter the call stack by the filename too?

Yes it must match the test suite path.

@DanTup
Copy link
Contributor

DanTup commented Oct 18, 2021

Great, thanks! :-)

@jakemac53
Copy link
Contributor Author

jakemac53 commented Oct 18, 2021

Added support and a test for browser/node tests, turned out to be pretty easy :)

@jakemac53 jakemac53 requested a review from natebosch October 18, 2021 15:49
- **full-name**: Requires an match for the name of the test.
- **line**: Matches any test that originates from this line in the test suite.
- Not supported for browser tests.
- **col**: Matches any test that originates from this column in the test suite.
Copy link
Member

Choose a reason for hiding this comment

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

I still don't understand the precise position this matches.

Is it exactly the first t in test? Is it 0 based? Does this match the same frame as the line number, or can the line match one frame and the column match a different frame?

I'll read through the test cases tomorrow to find out more, but I do think we should expand the user facing docs.

Co-authored-by: Nate Bosch <[email protected]>
var line = suite.config.line;
var col = suite.config.col;
var trace = test.trace;
if (trace == null && (line != null || col != null)) {
Copy link
Member

Choose a reason for hiding this comment

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

When would we be missing a trace? Should we consider it an error to try to run tests with a line and column when we have no trace available?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure if we get load tests and things through this api. I will try making it an error and see what happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now I am just throwing a StateError, let me know if you think a different one would be more appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a better way to match up (and run?) tests using the analyzer outline info (literal strings for test/group names)
3 participants