From 5d571d64a298d476689dd60113b0fc67fdb7e157 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Thu, 3 Aug 2023 10:03:26 -0700 Subject: [PATCH] Add --fail-fast flag (#2040) Closes #1841 Add a `--fail-fast` flag which stops running test cases after the first failure. - in the engine, check for failed tests immediately after running them. when fast failures are enabled `close()` the engine after any failure. Teardowns and cleanups will run, and any concurrently running tests in other suits will finish, but no further tests will start. - add the argument in `configuration` and parse it with the args. - add a test with a failing case that prevents later tests from running. --- pkgs/test/CHANGELOG.md | 4 +++ pkgs/test/pubspec.yaml | 4 +-- pkgs/test/test/runner/engine_test.dart | 13 +++++++++ pkgs/test/test/runner/runner_test.dart | 1 + pkgs/test/test/utils.dart | 27 ++++++++++++------ pkgs/test_core/CHANGELOG.md | 4 +++ pkgs/test_core/lib/src/runner.dart | 8 ++++-- .../lib/src/runner/configuration.dart | 18 ++++++++++++ .../lib/src/runner/configuration/args.dart | 3 ++ pkgs/test_core/lib/src/runner/engine.dart | 28 +++++++++++++++---- pkgs/test_core/pubspec.yaml | 2 +- 11 files changed, 92 insertions(+), 20 deletions(-) diff --git a/pkgs/test/CHANGELOG.md b/pkgs/test/CHANGELOG.md index f071aa847..d0d24dad0 100644 --- a/pkgs/test/CHANGELOG.md +++ b/pkgs/test/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.24.6-wip + +* Add support for discontinuing after the first failing test with `--fail-fast`. + ## 1.24.5 * Change "compiling " to "loading " message in all cases. Surface diff --git a/pkgs/test/pubspec.yaml b/pkgs/test/pubspec.yaml index 88ae13348..b690cb6f2 100644 --- a/pkgs/test/pubspec.yaml +++ b/pkgs/test/pubspec.yaml @@ -1,5 +1,5 @@ name: test -version: 1.24.5 +version: 1.24.6-wip description: >- A full featured library for writing and running Dart tests across platforms. repository: https://github.com/dart-lang/test/tree/master/pkgs/test @@ -35,7 +35,7 @@ dependencies: # Use an exact version until the test_api and test_core package are stable. test_api: 0.6.1 - test_core: 0.5.5 + test_core: 0.5.6 typed_data: ^1.3.0 web_socket_channel: ^2.0.0 diff --git a/pkgs/test/test/runner/engine_test.dart b/pkgs/test/test/runner/engine_test.dart index 189c548df..428ca0f18 100644 --- a/pkgs/test/test/runner/engine_test.dart +++ b/pkgs/test/test/runner/engine_test.dart @@ -129,6 +129,19 @@ void main() { expect(engine.run(), completion(isFalse)); }); + test('.run() does not run more tests after failure for stopOnFirstFailure', + () async { + var secondTestRan = false; + var engine = declareEngine(() { + test('failure', () => throw 'oh no'); + test('subsequent', () { + secondTestRan = true; + }); + }, stopOnFirstFailure: true); + await expectLater(engine.run(), completion(isFalse)); + expect(secondTestRan, false); + }); + test('.run() may not be called more than once', () { var engine = Engine.withSuites([]); expect(engine.run(), completes); diff --git a/pkgs/test/test/runner/runner_test.dart b/pkgs/test/test/runner/runner_test.dart index e2ae78293..6d9a2ffae 100644 --- a/pkgs/test/test/runner/runner_test.dart +++ b/pkgs/test/test/runner/runner_test.dart @@ -102,6 +102,7 @@ $_runtimeCompilers Must be a 32bit unsigned integer or "random". If "random", pick a random seed to use. If not passed, do not randomize test case execution order. + --[no-]fail-fast Stop running tests after the first failure. Output: -r, --reporter=