Skip to content

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

Closed

Description

@KevinShiCA

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

Activity

  1. added this to the v3.6.0 milestone on Oct 16, 2019
  2. DanTup commented on Oct 16, 2019

    @DanTup
    Member

    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?

  3. added 2 commits that reference this issue on Oct 16, 2019
    917c0ef
    249954a
  4. scheglov commented on Oct 16, 2019

    @scheglov

    @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?

  5. scheglov commented on Oct 16, 2019

    @scheglov

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

  6. DanTup commented on Oct 17, 2019

    @DanTup
    Member

    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).

  7. added 2 commits that reference this issue on Oct 17, 2019
    4bc5d66
    fb6923f
  8. scheglov commented on Oct 17, 2019

    @scheglov

    Thank you for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresis bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions