Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -4,6 +4,8 @@
* Require Dart 3.7
* Add `--coverage-path` and `--branch-coverage` options to `dart test`.
* Serve dart2wasm source map files.
* Change `--version` to use a hard coded value instead of reading it from the
pubspec.lock, this is more efficient and supports workspaces.

## 1.26.3

Expand Down
3 changes: 2 additions & 1 deletion pkgs/test/lib/src/executable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:test_core/src/runner/hack_register_platform.dart'; // ignore: im

import 'runner/browser/platform.dart';
import 'runner/node/platform.dart';
import 'version.dart';

Future<void> main(List<String> args) async {
registerPlatformPlugin([Runtime.nodeJS], NodePlatform.new);
Expand All @@ -19,5 +20,5 @@ Future<void> main(List<String> args) async {
Runtime.safari,
], BrowserPlatform.start);

await executable.main(args);
await executable.main(args, testVersion: testVersion);
}
9 changes: 9 additions & 0 deletions pkgs/test/lib/src/version.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2025, 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.

/// The version of the `test` package.
///
/// Must match what is in the pubspec.yaml, and enforced by
/// test/version_test.dart.
const String testVersion = '1.27.0-wip';
1 change: 1 addition & 0 deletions pkgs/test/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies:
dev_dependencies:
fake_async: ^1.0.0
glob: ^2.0.0
pubspec_parse: ^1.2.0
test_descriptor: ^2.0.0
test_process: ^2.0.0

Expand Down
2 changes: 1 addition & 1 deletion pkgs/test/test/runner/json_reporter_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import 'dart:convert';

import 'package:path/path.dart' as p;
import 'package:test/src/version.dart';
import 'package:test/test.dart';
import 'package:test_core/src/runner/version.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;

/// Asserts that the outputs from running tests with a JSON reporter match the
Expand Down
20 changes: 20 additions & 0 deletions pkgs/test/test/version_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2023, 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.

@TestOn('vm')
library;

import 'dart:io';

import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:test/src/version.dart';
import 'package:test/test.dart';

void main() {
test('testVersion is up to date', () {
final file = File('pubspec.yaml');
final pubspec = Pubspec.parse(file.readAsStringSync(), sourceUrl: file.uri);
expect(pubspec.version.toString(), testVersion);
});
}
2 changes: 2 additions & 0 deletions pkgs/test_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Restrict to latest version of analyzer package.
* Require Dart 3.7
* Add `--coverage-path` and `--branch-coverage` options to `dart test`.
* Change `--version` to use a hard coded value instead of reading it from the
pubspec.lock, this is more efficient and supports workspaces.

## 0.6.12

Expand Down
16 changes: 8 additions & 8 deletions pkgs/test_core/lib/src/executable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'runner.dart';
import 'runner/application_exception.dart';
import 'runner/configuration.dart';
import 'runner/no_tests_found_exception.dart';
import 'runner/version.dart';
import 'util/errors.dart';
import 'util/exit_codes.dart' as exit_codes;
import 'util/io.dart';
Expand All @@ -34,8 +33,10 @@ final String _globalConfigPath = () {
}
}();

Future<void> main(List<String> args) async {
await _execute(args);
/// Main entrypoint for the executable, the [version] is the version of the
/// test runner executing this function.
Future<void> main(List<String> args, {String? testVersion}) async {
await _execute(args, testVersion: testVersion);
completeShutdown();
}

Expand All @@ -54,7 +55,7 @@ void completeShutdown() {
cancelStdinLines();
}

Future<void> _execute(List<String> args) async {
Future<void> _execute(List<String> args, {String? testVersion}) async {
/// A merged stream of all signals that tell the test runner to shut down
/// gracefully.
///
Expand Down Expand Up @@ -87,12 +88,11 @@ Future<void> _execute(List<String> args) async {
}

if (configuration.version) {
var version = testVersion;
if (version == null) {
if (testVersion == null) {
stderr.writeln("Couldn't find version number.");
exitCode = exit_codes.data;
} else {
print(version);
print(testVersion);
}
return;
}
Expand Down Expand Up @@ -157,7 +157,7 @@ Future<void> _execute(List<String> args) async {
});

try {
runner = Runner(configuration);
runner = Runner(configuration, testVersion: testVersion);
exitCode = (await runner.run()) ? 0 : 1;
} on ApplicationException catch (error) {
stderr.writeln(error.message);
Expand Down
59 changes: 32 additions & 27 deletions pkgs/test_core/lib/src/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,40 @@ class Runner {
/// Sinks created for each file reporter (if there are any).
final List<IOSink> _sinks;

/// Creates a new runner based on [configuration].
factory Runner(Configuration config) => config.asCurrent(() {
var engine = Engine(
concurrency: config.concurrency,
coverage: config.coverage,
coverageLcov: config.coverageLcov,
testRandomizeOrderingSeed: config.testRandomizeOrderingSeed,
stopOnFirstFailure: config.stopOnFirstFailure,
);
/// Creates a new runner based on [config].
///
/// The [testVersion] is the test runner version.
factory Runner(Configuration config, {String? testVersion}) =>
config.asCurrent(() {
var engine = Engine(
concurrency: config.concurrency,
coverage: config.coverage,
coverageLcov: config.coverageLcov,
testRandomizeOrderingSeed: config.testRandomizeOrderingSeed,
stopOnFirstFailure: config.stopOnFirstFailure,
testVersion: testVersion,
);

var sinks = <IOSink>[];
Reporter createFileReporter(String reporterName, String filepath) {
final sink = (File(filepath)..createSync(recursive: true)).openWrite();
sinks.add(sink);
return allReporters[reporterName]!.factory(config, engine, sink);
}
var sinks = <IOSink>[];
Reporter createFileReporter(String reporterName, String filepath) {
final sink =
(File(filepath)..createSync(recursive: true)).openWrite();
sinks.add(sink);
return allReporters[reporterName]!.factory(config, engine, sink);
}

return Runner._(
engine,
MultiplexReporter([
// Standard reporter.
allReporters[config.reporter]!.factory(config, engine, stdout),
// File reporters.
for (var reporter in config.fileReporters.keys)
createFileReporter(reporter, config.fileReporters[reporter]!),
]),
sinks,
);
});
return Runner._(
engine,
MultiplexReporter([
// Standard reporter.
allReporters[config.reporter]!.factory(config, engine, stdout),
// File reporters.
for (var reporter in config.fileReporters.keys)
createFileReporter(reporter, config.fileReporters[reporter]!),
]),
sinks,
);
});

Runner._(this._engine, this._reporter, this._sinks);

Expand Down
12 changes: 6 additions & 6 deletions pkgs/test_core/lib/src/runner/configuration/reporters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final UnmodifiableMapView<String, ReporterDetails> allReporters =
final _allReporters = <String, ReporterDetails>{
'compact': ReporterDetails(
'A single line, updated continuously.',
(config, engine, sink) => CompactReporter.watch(
(config, engine, sink, {version}) => CompactReporter.watch(
engine,
sink,
color: config.color,
Expand All @@ -47,7 +47,7 @@ final _allReporters = <String, ReporterDetails>{
),
'expanded': ReporterDetails(
'A separate line for each update.',
(config, engine, sink) => ExpandedReporter.watch(
(config, engine, sink, {version}) => ExpandedReporter.watch(
engine,
sink,
color: config.color,
Expand All @@ -61,7 +61,7 @@ final _allReporters = <String, ReporterDetails>{
),
'failures-only': ReporterDetails(
'A separate line for failing tests with no output for passing tests',
(config, engine, sink) => FailuresOnlyReporter.watch(
(config, engine, sink, {version}) => FailuresOnlyReporter.watch(
engine,
sink,
color: config.color,
Expand All @@ -76,7 +76,7 @@ final _allReporters = <String, ReporterDetails>{
'github': ReporterDetails(
'A custom reporter for GitHub Actions '
'(the default reporter when running on GitHub Actions).',
(config, engine, sink) => GithubReporter.watch(
(config, engine, sink, {version}) => GithubReporter.watch(
engine,
sink,
printPath:
Expand All @@ -90,13 +90,13 @@ final _allReporters = <String, ReporterDetails>{
'json': ReporterDetails(
'A machine-readable format (see '
'https://dart.dev/go/test-docs/json_reporter.md).',
(config, engine, sink) =>
(config, engine, sink, {version}) =>
JsonReporter.watch(engine, sink, isDebugRun: config.debug),
),
'silent': ReporterDetails(
'A reporter with no output. '
'May be useful when only the exit code is meaningful.',
(config, engine, sink) => SilentReporter(),
(config, engine, sink, {version}) => SilentReporter(),
),
};

Expand Down
8 changes: 7 additions & 1 deletion pkgs/test_core/lib/src/runner/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ class Engine {
/// `false` to `true`.
Stream get onIdle => _group.onIdle;

/// The version of the test reporter (generally, the `test` package).
///
/// Can be `null` if not running using the test runner.
final String? testVersion;

/// Creates an [Engine] that will run all tests provided via [suiteSink].
///
/// [concurrency] controls how many suites are loaded and ran at once, and
Expand All @@ -218,13 +223,14 @@ class Engine {
/// [coverage] specifies a directory to output coverage information.
///
/// If [stopOnFirstFailure] then a single failing test will cause the engine
/// to [close] and stop ruunning further tests.
/// to [close] and stop running further tests.
Engine({
int? concurrency,
String? coverage,
String? coverageLcov,
this.testRandomizeOrderingSeed,
bool stopOnFirstFailure = false,
this.testVersion,
}) : _runPool = Pool(concurrency ?? 1),
_stopOnFirstFailure = stopOnFirstFailure,
_coverage = coverage,
Expand Down
3 changes: 1 addition & 2 deletions pkgs/test_core/lib/src/runner/reporter/json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import '../../platform.dart';
import '../engine.dart';
import '../load_suite.dart';
import '../reporter.dart';
import '../version.dart';

/// A reporter that prints machine-readable JSON-formatted test results.
class JsonReporter implements Reporter {
Expand Down Expand Up @@ -89,7 +88,7 @@ class JsonReporter implements Reporter {

_emit('start', {
'protocolVersion': '0.1.1',
'runnerVersion': testVersion,
'runnerVersion': _engine.testVersion,
'pid': pid,
});
}
Expand Down
61 changes: 0 additions & 61 deletions pkgs/test_core/lib/src/runner/version.dart

This file was deleted.

Loading