Skip to content
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

Run/debug test buttons disappears if test description has double quotes #2053

Closed
KevinShiCA opened this issue Oct 15, 2019 · 5 comments · Fixed by #2054
Closed

Run/debug test buttons disappears if test description has double quotes #2053

KevinShiCA opened this issue Oct 15, 2019 · 5 comments · Fixed by #2054
Labels
in editor Relates to code editing or language features is bug
Milestone

Comments

@KevinShiCA
Copy link

When you write a test (including flutter widget tests), the plugin provides a very helpful button to run/debug the test:

Screen Shot 2019-10-15 at 3 06 18 PM

If the test description has a double quote ", then those buttons disappear for some reason:

Screen Shot 2019-10-15 at 3 08 07 PM

@DanTup DanTup added in editor Relates to code editing or language features is bug labels Oct 16, 2019
@DanTup DanTup added this to the v3.6.0 milestone Oct 16, 2019
@DanTup
Copy link
Member

DanTup commented Oct 16, 2019

Thanks for the report! It looks like the outline data for these tests always comes through with double quotes, so when there's a double quote in the name we get this:

 test('danny', () {});
{
    "kind": "UNIT_TEST_TEST",
    "name": "test(\"dan \"ny\")",
    // ...
}

This confuses the code I wrote to extract the test name (where I wanted to avoid having to handle all the details of Dart string parsing in TypeScript). I'll see if I can tweak it a little - in theory it can probably just strip test(" from the start and ") from the end, and then remove any unescape any remaining quotes. It'll never be completely reliable, since you could put variables and things inside them in Dart which wouldn't come through in the outline.

@scheglov is it expected that the quotes come through like this (the single quotes in the source code became double quotes in the outline node element name, even though there were quotes contained within), or is that also a bug?

DanTup added a commit that referenced this issue Oct 16, 2019
DanTup added a commit that referenced this issue Oct 16, 2019
@scheglov
Copy link

@DanTup Well, it is implemented as wrapping "description" into double quotes. The description is either the string literal values of AstNode.toSource() for cases when the name if a variable. It was intended to give the user a way to navigate between groups and tests, and the name is to give some description to them. It seems that you are using it now for something more than just a hint to the user. So, I don't know what it the right answer here. How do you use it?

@scheglov
Copy link

I prototyped a CL, but Paul gave me an idea that maybe we should not just change, but first analyze what the clients need :-)

@DanTup
Copy link
Member

DanTup commented Oct 17, 2019

Ah, I see :)

In VS Code we add these "code lens" links above each test/group (the run/debug links):

Screenshot 2019-10-17 at 8 48 52 am

Clicking these will run just that test - but in order to do that we need to run pub run test --name "^test name$" (where test name is the name of the test). This means we need to extract the test name from the Outline data. It's not foolproof - if your test is named "test $counter" or similar, it's not going to work - but things that are just static strings should.

I've improved this for now by just stripping the test(" and ") from the string and using the rest as-is (after escaping and wrapping quotes for executing via a shell), so if there's not a clear improvement for the analyzer, then don't worry about changing anything. It looked weird to have "string " string", but unless there was a field that didn't include the test(" ") part, I don't think it's be easy to represent (and since the outline is pretty generic, adding test-specific fields might not make sense).

DanTup added a commit that referenced this issue Oct 17, 2019
DanTup added a commit that referenced this issue Oct 17, 2019
@scheglov
Copy link

Thank you for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in editor Relates to code editing or language features is bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants