Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* Disable throttling in chrome launch arguments.
* Allow package_config `3.x.x`.
* Require `analyzer: '>=13.0.0 <15.0.0'`
* Use the compact or failures-only reporters by default for tests run directly
instead of through the test runner.

## 1.31.1

Expand Down
18 changes: 16 additions & 2 deletions pkgs/test/test/runner/runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,13 @@ $_usage''');
await d.file('test.dart', _success).create();
var test = await runDart(['test.dart']);

expect(test.stdout, emitsThrough(contains('All tests passed!')));
expect(
test.stdout,
allOf(
neverEmits(contains('success')),
emitsThrough(contains('All tests passed!')),
),
);
await test.shouldExit(0);
});

Expand Down Expand Up @@ -444,7 +450,15 @@ $_usage''');

test('directly', () async {
var test = await runDart(['test.dart']);
expect(test.stdout, emitsThrough(contains('All tests passed!')));

expect(
test.stdout,
allOf(
neverEmits(anyElement(contains('success 1'))),
neverEmits(anyElement(contains('success 2'))),
emits(contains('All tests passed!')),
),
);
await test.shouldExit(0);
});
});
Expand Down
2 changes: 2 additions & 0 deletions pkgs/test_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Allow package_config `3.x.x`.
* Require `analyzer: '>=13.0.0 <15.0.0'`
* Update `parse_metadata.dart` to be compatible with `analyzer >=13.0.0 <15.0.0`.
* Use the compact or failures-only reporters by default for tests run directly
instead of through the test runner.

## 0.6.18

Expand Down
12 changes: 2 additions & 10 deletions pkgs/test_core/lib/src/direct_run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import 'dart:collection';
import 'package:path/path.dart' as p;
import 'package:test_api/backend.dart';

import 'runner/configuration.dart';
import 'runner/engine.dart';
import 'runner/plugin/environment.dart';
import 'runner/reporter.dart';
import 'runner/reporter/expanded.dart';
import 'runner/reporter/direct.dart';
import 'runner/runner_suite.dart';
import 'runner/suite.dart';
import 'util/os.dart';
import 'util/print_sink.dart';

/// Runs all unskipped test cases declared in [testMain].
///
Expand Down Expand Up @@ -64,13 +62,7 @@ Future<bool> _directRunTests(
String? fullTestName,
required bool allowDuplicateTestNames,
}) async {
reporterFactory ??= (engine) => ExpandedReporter.watch(
engine,
PrintSink(),
color: Configuration.empty.color,
printPath: false,
printPlatform: false,
);
reporterFactory ??= createDirectReporter;
final declarer = Declarer(
fullTestName: fullTestName,
allowDuplicateTestNames: allowDuplicateTestNames,
Expand Down
5 changes: 5 additions & 0 deletions pkgs/test_core/lib/src/runner/reporter/direct.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

export 'direct_stub.dart' if (dart.library.io) 'direct_io.dart';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: maybe add a comment to this library explaining what it is

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

26 changes: 26 additions & 0 deletions pkgs/test_core/lib/src/runner/reporter/direct_io.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import '../../util/io.dart';
import '../../util/print_sink.dart';
import '../engine.dart';
import '../reporter.dart';
import 'compact.dart';
import 'failures_only.dart';

Reporter createDirectReporter(Engine engine) => canUseSpecialChars
? CompactReporter.watch(
engine,
PrintSink(),
color: true,
printPath: false,
printPlatform: false,
)
: FailuresOnlyReporter.watch(
engine,
PrintSink(),
color: false,
printPath: false,
printPlatform: false,
);
16 changes: 16 additions & 0 deletions pkgs/test_core/lib/src/runner/reporter/direct_stub.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import '../../util/print_sink.dart';
import '../engine.dart';
import '../reporter.dart';
import 'failures_only.dart';

Reporter createDirectReporter(Engine engine) => FailuresOnlyReporter.watch(
engine,
PrintSink(),
color: false,
printPath: false,
printPlatform: false,
);
11 changes: 2 additions & 9 deletions pkgs/test_core/lib/src/scaffolding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import 'package:test_api/scaffolding.dart' show Timeout, pumpEventQueue;

import 'runner/engine.dart';
import 'runner/plugin/environment.dart';
import 'runner/reporter/expanded.dart';
import 'runner/reporter/direct.dart';
import 'runner/runner_suite.dart';
import 'runner/suite.dart';
import 'util/os.dart';
import 'util/print_sink.dart';

// Hide implementations which don't support being run directly.
// This file is an almost direct copy of import below, but with the global
Expand Down Expand Up @@ -58,13 +57,7 @@ Declarer get _declarer {
var engine = Engine();
engine.suiteSink.add(suite);
engine.suiteSink.close();
ExpandedReporter.watch(
engine,
PrintSink(),
color: true,
printPath: false,
printPlatform: false,
);
createDirectReporter(engine);

var success = await runZoned(
() => Invoker.guard(engine.run),
Expand Down
Loading