Skip to content

Test line/col/filenames are incorrect when using package:test_reflective_loader #2029

Closed
@DanTup

Description

@DanTup

Usually when we run tests with the JSON reporter, we get the file/line/col of the test back. We can now also run tests by line number.

However, the file/line/col information is incorrect for tests using package:test_reflective_loader so if we try to run by line then things don't work right. Or if you try to "Go to Test" that goes to the wrong place. I believe the issue is that when the test() function is run, the actual location of the test method isn't on the stack at all, so what we end up with is the location of the call to defineReflectiveSuite:

danny@Dannys-MacBook-Pro analysis_server % dart test -r json test/lsp/call_hierarchy_test.dart --plain-name "PrepareCallHierarchyTest | test_method"

// snip ...

"line": 175,
"column": 28,
"url": "package:test_reflective_loader/test_reflective_loader.dart",
// This is the call to defineReflectiveSuite
"root_line": 12,
"root_column": 3,
"root_url": "file:///Users/danny/Dev/Google/dart-sdk/sdk/pkg/analysis_server/test/lsp/call_hierarchy_test.dart"

// snip ...

So, the request is to support this style of test in a way that the correct location can be reported. The code that's calling test() lives here:

https://github.com/dart-lang/test_reflective_loader/blob/40d61b16647cd61b02d806fea46362ef07e7c502/lib/test_reflective_loader.dart#L175

Looking at the code, it has a MethodMirror at the point where test is called, and that has a .location that looks like it's probably the values we want. However I can't see a way it could pass them to package:test. Would it be feasible to allow passing an overridden location to test() (or having some similar API that supported this)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions