Skip to content

Conversation

@johnniwinther
Copy link
Member

The global declarer is used by package:test_reflective_loader which has no means of configuring the test output. It is for instance used to run all tests in package:analyzer, and the current output prints a line for each test (of which there is currently >32000) and uses colors in the output. This makes it very hard to output to find failing tests, since the failures are hidden within all the succeeding tests and piping the output to a file for easier search still leaves the color in the output.

This change adds .fromEnvironment variables to the creation of the global declarer, such that it can be configured at the command line. This allow for enabling compact output which only displays the failing tests, and whether to use colors in the output.

The global declarer is used by package:test_reflective_loader which has no means of configuring the test output. It is for instance used to run all tests in package:analyzer, and the current output prints a line for each test (of which there is currently >32000) and uses colors in the output. This makes it very hard to output to find failing tests, since the failures are hidden within all the succeeding tests and piping the output to a file for easier search still leaves the color in the output.

This change adds .fromEnvironment variables to the creation of the global declarer, such that it can be configured at the command line. This allow for enabling compact output which only displays the failing tests, and whether to use colors in the output.
@johnniwinther johnniwinther requested a review from a team as a code owner November 19, 2025 10:20
@github-actions
Copy link

github-actions bot commented Nov 19, 2025

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

@@ -1,3 +1,6 @@
## 0.6.14
* Support environment flags for configuring the global declarer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a bit more explicit here?

It'd also be nice to update this section of the readme – so this feature isn't lost.

https://github.com/dart-lang/test/tree/master/pkgs/test#selecting-a-test-reporter

I have a few packages where I'd use this, too!

@jakemac53
Copy link
Contributor

jakemac53 commented Nov 19, 2025

There are many more issues than just this with running tests directly as opposed to through the test runner - test annotations won't be respected and test configuration files also won't be respected (and probably many more such as timeouts etc).

Is it possible to just use the test runner here?

@jakemac53
Copy link
Contributor

I also think it is potentially confusing that these environment variables are only supported by the global declarer and don't more generally set the defaults of test reporters as a whole.

Copy link
Member

@natebosch natebosch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you'd prefer I open a PR with an implementation matching my comments. I think it is reasonable to support at least one or two of the Dart compile environment variables.

@@ -0,0 +1,32 @@
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this file? Is there a particular reason is it written so non-idiomatically for a Dart unit test?

Can we get by with a String in the file that needs this?

For historical reasons most of the test for test_core are still living under the test package so most of the utility code for running meta-tests is there. It might be easier to locate this test there for now as well.

});
});

group('printPath', () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a specific use case in mind for the printPath and printPlatform configuration? I cannot imagine a use case where the invoker of Dart binary wouldn't be a better place to deal with knowledge of the platform for instance.

I think it's preferable to only add configuration support for the specific values we need (I think that's control over the reporter and use colors IIRC?) and we can add further support later if we need to.

List<Pattern> contains = const [],
List<String>? doesNotContain,
}) async {
if (debugPrint) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typical way we'd handle this is with printOnFailure.

printPath: false,
printPlatform: false,
var useCompactReporter = const bool.fromEnvironment(
'test_core.compactReporter',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to match the args format for consistency. -Dtest_core.reporter=compact

We can't import the json reporter, but I don't see any reason not to support at least the failures-only reporter (which could be useful) and the github reporter (which is trivial to support) from the start.

}
}

List<Pattern> _generateExpectedOutput({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional] I don't think we need to verify every character of the output. It might be easier to test that the compact output does contain a carriage return and the expanded output doesn't. We already test the particular details of the reporters in other tests, we just need to test for any sign that the config is plumbed through correctly.

@@ -1,3 +1,6 @@
## 0.6.14
* Support environment flags for configuring the global declarer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads like we support reading from Platform.environment.

I wonder, should we be trying to do that instead? For the VM case it's probably little consequence either way, for AOT native we'd probably prefer Platform.environment support, and for web we'd prefer what's implemented.

Would there be value in supporting a Platform.environment fallback in places where we can import it? I'd be happy to write up the conditional import version if we think it's useful.

@natebosch
Copy link
Member

Is it possible to just use the test runner here?

+1 to this - it's likely that the direct-run use case will continue to have a long-tail of UX rough edges and it's unlikely we'll prioritize that as a first class route for running tests.

That said, I don't thinks I see a significant downside to reading from either String.fromEnvironment or Platform.environment or both to override this behavior in the direct run case.

I also think it is potentially confusing that these environment variables are only supported by the global declarer and don't more generally set the defaults of test reporters as a whole.

I don't think I share this concern, although it maybe pushes me a little towards taking back my suggestion about supporting Environment.platform config. If we limit this to -D dart environment variables then it's already restricted in usage to places that have stepped of the golden path for the test runner and I don't think it serves as motivation on it's own to step off the golden path.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants