-
Notifications
You must be signed in to change notification settings - Fork 217
Allow specifying an explicit location for test/groups #2481
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
base: master
Are you sure you want to change the base?
Conversation
Usually test locations (which are used both to report the location of tests in the json reporter, and also for filtering tests by line/col) are inferred from the call stack when test() is called. This changes adds a new `location` parameter to group/test to allow this information to be provided explicitly. This can be useful where the call to `test()` doesn't contain the actual location of the declaration in the call stack (for example when using `pkg:test_reflective_loader`). See dart-lang#2029 See Dart-Code/Dart-Code#5480
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jakemac53 this doesn't quite work yet - see comments on the test about filtering groups.
I'm also not sure if the API changes I've made are reasonable, so interested in feedback on that too.
test('test 1 inferred', () {}); | ||
tearDownAll(() {}); | ||
}); | ||
group('group 2 custom', location: TestLocation('file:///foo/group', 123, 234), () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe these URIs should be package root relative? Or at least support that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added test cases for org-dartlang-app:///
for the filtering, although it's not clear to me what supporting org-dartlang-app
here would mean for the JSON... I think the clients of the JSON reporters would always expect file paths? If we supported org-dartlang-app
here, would they need to be translated to real file paths somewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I do think it will mess up some of these use cases - one thing we can try externally is running tests with build_web_compilers (build_runner test -- -p chrome), and see what all it takes to get things working.
Ultimately none of this works today anyways, so its probably ok if we just leave it in a state where it still doesn't work, as long as internally package:test does something sensible and we can leave any extra bits for later.
@jakemac53 I think this all works as required now, but I'm unsure about:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a pubspec/changelog update as well
I've added this to all three changelogs that this affected. I used the same description but let me know if these should be more specific (the changes only really work together, and I presume these are always shipped/updated together). I've also tested with Flutter locally and this doesn't seem to affect anything there (at least, no analysis errors, and no failures from the tests I ran). |
pkgs/test/CHANGELOG.md
Outdated
@@ -1,5 +1,9 @@ | |||
## 1.25.16-wip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new feature (new apis) so lets release it as such.
## 1.25.16-wip | |
## 1.26.0-wip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, I'm having a hard time making this work (although I'm bumping the minor part for all three packages - is that what you meant?)
By bumping these versions, the matcher
constraint doesn't match. So I tried bumping that, but test
depends back on matcher
, so I end up with:
[test] dart pub get --no-example
Resolving dependencies...
Because matcher >=0.12.16+1 depends on test_api >=0.5.0 <0.8.0 and matcher >=0.12.16 <0.12.16+1 depends on test_api >=0.5.0 <0.7.0, matcher >=0.12.16 requires test_api >=0.5.0 <0.8.0.
So, because test depends on matcher >=0.12.16 <0.12.18 and test_workspace depends on test_api, version solving failed.
exit code 1
Do I need to also bump the major versions on matcher
/checks
and increase their constraints to match the new versions of everything else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For test_api and test_core, since they are on the 0
major version - all the semantic versions are shifted to the right so they were actually fine (already feature releases). Only package:test needed to be updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah!
I've done that, though I now see this (fairly unspecific) error:
[test] dart pub get --no-example
Resolving dependencies...
Because test_core depends on test_api 0.7.4 and test_workspace depends on test_api, version solving failed.
exit code 1
However, I'm also seeing that when I revert all of my changes - so I've pushed here so you can kick the bots while I figure out if this is just a me problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, it was my change and it was because I bumped the test_api version (because the current version had already been published), but there were still references to the old one - see 888a9e8.
I'm not sure if having -wip
on the end of those versions is ideal, but they're not yet published - let me know if there's something better I should do there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That change lgtm
PR HealthChangelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. |
@jakemac53 looks like the asserts I added caused a lot of failures. This is because in test/pkgs/test_api/lib/src/backend/group.dart Lines 61 to 67 in 3ac991f
I'm not sure how to handle this.. should we keep the parent pointing at the original group (not the new platform-scoped one), or do we need to clone the child entries? |
Looksl ike some legit test failures in the non-null asserts @DanTup |
Oh, ignore me - we are cloning tests already, but not setup/teardown. I think it's an easy fix, I'll have a go :) |
@jakemac53 could you check whether 990f13f seems reasonable (and if so, kick the bots off again)? Edit: hang on, I think there are other issues - lemme take another look. |
@jakemac53 I think some of this might be test issues, but I'm not sure how to handle it. For example this test here: test/pkgs/test/test/runner/engine_test.dart Lines 16 to 32 in 3ac991f
It creates some tests with So I don't think that's a bug, but rather just a consequence of how the test works. Cloning the tests here might work, but it also feels like a burden on tests (I think there are quite a lot that do similar). |
Hmmm, I do think the asserts are generally helpful, bashing over a parent is never intended, so ideally the tests would be updated to copy tests before reparenting them. We could possibly file a TODO for this, but it makes me a bit uneasy to remove the asserts. |
Yep, I agree - but is there something nicer we could do than changing all of these tests from something like: runnerSuite(Group.root(tests.take(2))), to: runnerSuite(Group.root(tests.take(2).map(_clone)), Maybe a version of runnerSuiteTests(tests.take(2)), |
Either way sounds fine to me |
@jakemac53 assuming I'm running them all correctly, I believe the tests are all passing now. I made two further changes:
If these look reasonable, please can you trigger the bots again? Thanks! |
Usually test locations (which are used both to report the location of tests in the json reporter, and also for filtering tests by line/col) are inferred from the call stack when test() is called.
This changes adds a new
location
parameter to group/test to allow this information to be provided explicitly. This can be useful where the call totest()
doesn't contain the actual location of the declaration in the call stack (for example when usingpkg:test_reflective_loader
).See #2029
See Dart-Code/Dart-Code#5480