-
Notifications
You must be signed in to change notification settings - Fork 63
[test_reflective_loader] Use test groups instead of combining names #2107
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: main
Are you sure you want to change the base?
Conversation
@scheglov this is not a priority, but if you have chance to confirm this change wouldn't negatively affect you, I will work on some tests and changelog/etc. |
With this change everything works fine for me. The presentation is obviously slightly different
vs new
We seem to not include With separators it was a tiny bit easier to read, but this is very small, and probably should be solved the way it was, with combining names, but in the test reporter instead. |
I think if the generated groups have the name like |
It will probably look bad in VS Code then, which is the point of this change :-) |
Ah, well spotted, I'll look into that (and ensure there are tests).
Hmm, I'm not sure how we could do this without affecting other uses of group('foo', () {
test('bar', () { And package test joins them automatically with spaces. I think usually they are written in a way that this makes sense, but I agree it seems odd here. @jakemac53 do you know if there are any existing ways in package:test to control how the names would be combined, without inserting characters into the name that would show up in the JSON (and therefore the VS Code tree)?
Actually, I'm not sure about this, I'll have to do some testing. The |
Sure, the default behavior is to join with spaces as separators, and not everyone wants or likes using something different. My guess is that we might theoretically have a separate |
Not that I know of, no. |
I have some recollection that you can't control the reporter unless running from Although, if you're likely to continue to run from the terminal with a patched version of I'll tidy this PR up and add some tests (and fix the |
It turns out that I only handled I've pushed changes to handle this - essentially we know create our own hierarchy of group/tests now, and then walk that tree in I diffed the output versus the current version for analyzer, and everything seemed the same (besides pipes, and some differences in the printed timestamps). |
This happens if |
Ah, interesting. One of the failures was |
Oh, I see the problem... It's these
(some of those tests like They do not await anything so the tests that have I don't know why it works the other way though (not calling any |
With the latest changes I see spamming on the console when I have a single
|
Oh, good spot. I think this is This isn't good though - if there's no way to suppress this (@jakemac53?) then we might have to switch back to handling it locally and just not calling group/test for those things. |
It is imo good for it to have the same behavior as regular package:test. If we want to change the default way package:test handles |
"Just to avoid spam" is a quite important reason for me. |
I am not saying it shouldn't spam, its just that we should address that issue in package:test itself, its not an issue specific to this use case. |
Ah, that way of solving this problem I do like. If |
We do have |
I agree that changing this in |
@scheglov do you know if you are using the expanded reporter also? If you are seeing spam for passed tests it indicates you are probably not getting the compact reporter. Update: I did just confirm that skipped tests always spam even in compact mode, we should just fix that imo. |
Do I have choice? I'm running using PatchYou can add a headerdiff --git a/pkgs/test_api/lib/src/backend/invoker.dart b/pkgs/test_api/lib/src/backend/invoker.dart
index 58f1001d..57201df8 100644
--- a/pkgs/test_api/lib/src/backend/invoker.dart
+++ b/pkgs/test_api/lib/src/backend/invoker.dart
@@ -378,7 +378,7 @@ class Invoker {
_controller.setState(const State(Status.running, Result.success));
_runCount++;
- Chain.capture(() {
+ // Chain.capture(() {
_guardIfGuarded(() {
runZoned(() async {
// Run the test asynchronously so that the "running" state change
@@ -415,7 +415,7 @@ class Invoker {
zoneSpecification:
ZoneSpecification(print: (_, __, ___, line) => _print(line)));
});
- }, when: liveTest.test.metadata.chainStackTraces, errorZone: false);
+ // }, when: liveTest.test.metadata.chainStackTraces, errorZone: false);
}
/// Runs [callback], in a [Invoker.guard] context if [_guarded] is `true`.
diff --git a/pkgs/test_core/lib/src/scaffolding.dart b/pkgs/test_core/lib/src/scaffolding.dart
index ffcb0083..d060623b 100644
--- a/pkgs/test_core/lib/src/scaffolding.dart
+++ b/pkgs/test_core/lib/src/scaffolding.dart
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
+import 'dart:io';
import 'package:meta/meta.dart' show isTest, isTestGroup;
import 'package:path/path.dart' as p;
@@ -13,6 +14,7 @@ import 'package:test_api/src/backend/invoker.dart'; // ignore: implementation_im
import 'runner/engine.dart';
import 'runner/plugin/environment.dart';
+import 'runner/reporter/compact.dart';
import 'runner/reporter/expanded.dart';
import 'runner/runner_suite.dart';
import 'runner/suite.dart';
@@ -60,7 +62,8 @@ Declarer get _declarer {
var engine = Engine();
engine.suiteSink.add(suite);
engine.suiteSink.close();
- ExpandedReporter.watch(engine, PrintSink(),
+// ExpandedReporter.watch(engine, PrintSink(),
+ CompactReporter.watch(engine, stdout,
color: true, printPath: false, printPlatform: false);
var success = await runZoned(() => Invoker.guard(engine.run),
diff --git a/pkgs/test_core/lib/src/util/io.dart b/pkgs/test_core/lib/src/util/io.dart
index 98bb23b2..39259b29 100644
--- a/pkgs/test_core/lib/src/util/io.dart
+++ b/pkgs/test_core/lib/src/util/io.dart
@@ -20,7 +20,7 @@ import 'pretty_print.dart';
/// The default line length for output when there isn't a terminal attached to
/// stdout.
-const _defaultLineLength = 200;
+const _defaultLineLength = 100;
/// Whether the test runner is running on Google-internal infrastructure.
final bool inGoogle = Platform.version.contains('(google3)'); |
The default reporter is the compact reporter when using the test runner, if you are just directly invoking the test files though then maybe that is the code path you are editing? All kinds of things won't work doing that though and you should move to just using |
Using If using |
@scheglov interested in your thoughts on the above... is using It does remove the hierarchy that is currently added by the |
/gemini review |
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.
Code Review
This pull request refactors the test discovery logic to use package:test
's group()
function, creating a more organized, hierarchical test structure. I've identified a critical syntax error in the _Test
constructor call that needs to be addressed, as well as a medium-severity suggestion to improve performance by caching the regular expression. Addressing these points will enhance the code's correctness and efficiency.
_addTest( | ||
_Test( | ||
memberName, | ||
timeout: timeout?._timeout, | ||
location: memberMirror.testLocation, | ||
solo: isSolo, | ||
skip: isSkipped, | ||
() => expectFail | ||
? _runFailingTest(classMirror, symbol) | ||
: _runTest(classMirror, symbol)), | ||
); |
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.
The _Test
constructor's parameters are not in the correct order. In Dart, positional arguments must precede named arguments. The function literal, intended as the second positional argument, is placed after named arguments, leading to a syntax error.
_addTest(
_Test(
memberName,
() => expectFail
? _runFailingTest(classMirror, symbol)
: _runTest(classMirror, symbol),
location: memberMirror.testLocation,
solo: isSolo,
skip: isSkipped,
timeout: timeout?._timeout
),
);
} | ||
// prepare information about the method | ||
var memberName = MirrorSystem.getName(symbol); | ||
var isTest = memberName.startsWith(RegExp('(solo_|fail_|skip_)*test_')); |
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.
Consider defining the regular expression RegExp('(solo_|fail_|skip_)*test_')
as a top-level constant for improved performance and readability. Caching the RegExp
avoids re-compilation on each method evaluation, aligning with Effective Dart's performance guidelines.
final _testMethodRegExp = RegExp('(solo_|fail_|skip_)*test_');
var isTest = _testMethodRegExp.hasMatch(memberName);
@DanTup sorry for using your PR to test the Gemini code review feature ;) |
@mosuem heh, np - I've been using it lately too on Dart-Code. It's been generally giving me better comments than Copilot and has pointed out a few good bugs. Although the "critical" issue above is not so good 😄 |
But the signature is actually this - or what am I missing? _Test(
super.name,
this.function, {
required super.location,
required super.solo,
required this.skip,
required this.timeout,
}); |
@mosuem yep, but "In Dart, positional arguments must precede named arguments" has not been the case for a long time (Dart 2.17 - see dart-lang/language#1072). |
TIL! |
@scheglov this change switches to using
package:test
groups instead of just combining names (#2104). This would improve how things appear in the VS Code test runner because there would be groups instead of everything being flat at the top:I don't know if it might negatively affect you - one difference when running from the terminal (without the test runner) is that there won't be pipe-separated names, they will just be space-separated (which is what
package:test
does for groups/tests:If we want to go ahead, this will need a little more work (tests, versions/changelog updating etc.) but I wanted to get your input first.