diff --git a/engine/src/flutter/pubspec.yaml b/engine/src/flutter/pubspec.yaml index 2308fd009e..f38a5defb7 100644 --- a/engine/src/flutter/pubspec.yaml +++ b/engine/src/flutter/pubspec.yaml @@ -86,7 +86,6 @@ workspace: - shell/vmservice - testing/benchmark - testing/dart - - testing/litetest - testing/scenario_app - testing/skia_gold_client - testing/smoke_test_failure @@ -138,8 +137,6 @@ dependencies: smith: any dev_dependencies: - litetest: - path: ./testing/litetest process_fakes: path: ./tools/pkg/process_fakes skia_gold_client: diff --git a/engine/src/flutter/testing/dart/image_events_test.dart b/engine/src/flutter/testing/dart/image_events_test.dart index c81d63c764..1d4bfb429e 100644 --- a/engine/src/flutter/testing/dart/image_events_test.dart +++ b/engine/src/flutter/testing/dart/image_events_test.dart @@ -9,10 +9,6 @@ import 'package:test/test.dart'; void main() { test('Image constructor and dispose invokes onCreate once', () async { - // We test constructor and dispose in one test because - // litetest runs the tests in parallel and static handlers - // are shared between tests. - int onCreateInvokedCount = 0; Image? createdImage; int onDisposeInvokedCount = 0; diff --git a/engine/src/flutter/testing/litetest/README.md b/engine/src/flutter/testing/litetest/README.md deleted file mode 100644 index 5b68112d9f..0000000000 --- a/engine/src/flutter/testing/litetest/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# package:litetest - -This is a wrapper around `package:async_helper` from the Dart SDK source repo -at `//pkg/async_helper` that works in the environment of `flutter_tester`. -This wrapper is needed to ensure that all tests run to completion before the -process exits. This is accomplished by opening a `ReceivePort` for each test, -which is only closed when the test finishes running. - -## Limitations - -This package is intended only for use in the `flutter/engine` repo by unit -tests that run on `flutter_tester`. Even though the API resembles the API -provided by `package:test`, it has all the same limitations that -`package:async_helper` has. diff --git a/engine/src/flutter/testing/litetest/lib/litetest.dart b/engine/src/flutter/testing/litetest/lib/litetest.dart deleted file mode 100644 index b7eb5b388b..0000000000 --- a/engine/src/flutter/testing/litetest/lib/litetest.dart +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:expect/variations.dart' as v; - -import 'src/test_suite.dart'; - -export 'package:expect/expect.dart'; - -export 'src/async_minitest.dart' hide test; -export 'src/matchers.dart'; - -final TestSuite _testSuite = TestSuite(); - -/// Describes the test named [name] given by the function [body]. -/// -/// After all tests are described, they will be run. All calls to [test] must be -/// made in the same event as the program's `main()` function. -void test( - String name, - dynamic Function() body, { - bool skip = false, -}) { - _testSuite.test(name, body, skip: skip); -} - -/// Whether asserts are enabled. -final bool assertStatementsEnabled = v.enabledAsserts; diff --git a/engine/src/flutter/testing/litetest/lib/src/async_minitest.dart b/engine/src/flutter/testing/litetest/lib/src/async_minitest.dart deleted file mode 100644 index 91b3eba48e..0000000000 --- a/engine/src/flutter/testing/litetest/lib/src/async_minitest.dart +++ /dev/null @@ -1,353 +0,0 @@ -// Copyright 2018 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// ignore_for_file: public_member_api_docs - -/// A minimal, dependency-free emulation layer for a subset of the -/// unittest/test API used by the language and core library. -/// -/// Compared with `minitest.dart`, this library supports and expects -/// asynchronous tests. It uses a `Zone` per test to associate a test name with -/// the failure. -/// -/// It does not support `setUp` or `tearDown` methods, -/// and matchers are severely restricted. -/// -/// A number of our language and core library tests were written against the -/// unittest package, which is now deprecated in favor of the new test package. -/// The latter is much better feature-wise, but is also quite complex and has -/// many dependencies. For low-level language and core library tests, we don't -/// want to have to pull in a large number of dependencies and be able to run -/// them correctly in order to run a test, so we want to test them against -/// something simpler. -/// -/// When possible, we just use the tiny expect library. But to avoid rewriting -/// all of the existing tests that use unittest, they can instead use this, -/// which shims the unittest API with as little code as possible and calls into -/// expect. -/// -/// Eventually, it would be good to refactor those tests to use the expect -/// package directly and remove this. -library; - -import 'dart:async'; - -import 'package:async_helper/async_helper.dart'; -import 'package:expect/expect.dart'; - -void group(String name, void Function() body) { - final oldName = _pushName(name); - try { - body(); - } finally { - _popName(oldName); - } -} - -void test(String name, dynamic Function() body) { - final oldName = _pushName(name); - - asyncStart(); - final result = runZoned(body, zoneValues: {_testToken: _currentName}); - if (result is Future) { - result.then((_) { - asyncEnd(); - }); - } else { - // Ensure all tests get to be set up first. - scheduleMicrotask(asyncEnd); - } - - _popName(oldName); -} - -void expect(dynamic value, dynamic matcher, {String reason = ''}) { - Matcher m; - if (matcher is _Matcher) { - m = matcher.call; - } else if (matcher is! Matcher) { - m = equals(matcher); - } else { - m = matcher; - } - m(value); -} - -R Function() expectAsync0(R Function() f, {int count = 1}) { - asyncStart(count); - return () { - final result = f(); - asyncEnd(); - return result; - }; -} - -R Function(A) expectAsync1(R Function(A) f, {int count = 1}) { - asyncStart(count); - return (A a) { - final result = f(a); - asyncEnd(); - return result; - }; -} - -R Function(A, B) expectAsync2(R Function(A, B) f, {int count = 1}) { - asyncStart(count); - return (A a, B b) { - final result = f(a, b); - asyncEnd(); - return result; - }; -} - -dynamic expectAsync(Function f, {int count = 1}) { - final f2 = f; // Avoid type-promoting f, we want dynamic invocations. - if (f2 is void Function(Never, Never, Never, Never, Never)) { - asyncStart(count); - return ([Object? a, Object? b, Object? c, Object? d, Object? e]) { - final result = f(a, b, c, d, e); // ignore: avoid_dynamic_calls - asyncEnd(); - return result; - }; - } - if (f2 is void Function(Never, Never, Never, Never)) { - asyncStart(count); - return ([Object? a, Object? b, Object? c, Object? d]) { - final result = f(a, b, c, d); // ignore: avoid_dynamic_calls - asyncEnd(); - return result; - }; - } - if (f2 is void Function(Never, Never, Never)) { - asyncStart(count); - return ([Object? a, Object? b, Object? c]) { - final result = f(a, b, c); // ignore: avoid_dynamic_calls - asyncEnd(); - return result; - }; - } - if (f2 is void Function(Never, Never)) { - asyncStart(count); - return ([Object? a, Object? b]) { - final result = f(a, b); // ignore: avoid_dynamic_calls - asyncEnd(); - return result; - }; - } - if (f2 is void Function(Never)) { - asyncStart(count); - return ([Object? a]) { - final result = f(a); // ignore: avoid_dynamic_calls - asyncEnd(); - return result; - }; - } - if (f2 is void Function()) { - asyncStart(count); - return () { - final result = f2(); - asyncEnd(); - return result; - }; - } - throw UnsupportedError( - 'expectAsync only accepts up to five argument functions'); -} - -// Matchers -typedef Matcher = void Function(dynamic); - -Matcher same(dynamic o) => (v) { - Expect.identical(o, v); - }; - -Matcher equals(dynamic o) => (v) { - Expect.deepEquals(o, v); - }; - -Matcher greaterThan(num n) => (dynamic v) { - Expect.type(v); - final num value = v as num; - if (value > n) { - return; - } - Expect.fail('$v is not greater than $n'); - }; - -Matcher greaterThanOrEqualTo(num n) => (dynamic v) { - Expect.type(v); - final num value = v as num; - if (value >= n) { - return; - } - Expect.fail('$v is not greater than $n'); - }; - -Matcher lessThan(num n) => (dynamic v) { - Expect.type(v); - final num value = v as num; - if (value < n) { - return; - } - Expect.fail('$v is not less than $n'); - }; - -Matcher lessThanOrEqualTo(num n) => (dynamic v) { - Expect.type(v); - final num value = v as num; - if (value <= n) { - return; - } - Expect.fail('$v is not less than $n'); - }; - -Matcher predicate(bool Function(dynamic value) fn, [String description = '']) => - (dynamic v) { - Expect.isTrue(fn(v), description); - }; - -Matcher anyOf(List expected) => (dynamic actual) { - for (final string in expected) { - if (actual == string) { - return; - } - } - - Expect.fail('Expected $actual to be one of $expected.'); - }; - -void isTrue(dynamic v) { - Expect.isTrue(v); -} - -void isFalse(dynamic v) { - Expect.isFalse(v); -} - -void isNull(dynamic o) { - Expect.isNull(o); -} - -void _checkThrow( - dynamic v, void Function(dynamic error) onError) { - if (v is Future) { - asyncStart(); - v.then((_) { - Expect.fail('Did not throw'); - }, onError: (Object e, s) { - if (e is! T) { - throw e; - } - onError(e); - asyncEnd(); - }); - return; - } - Expect.throws(v as void Function(), (dynamic e) { - onError(e); - return true; - }); -} - -void returnsNormally(dynamic o) { - try { - Expect.type(o); - (o as void Function())(); - } catch (error, trace) { - Expect.fail( - 'Expected function to return normally, but threw:\n$error\n\n$trace'); - } -} - -void throws(dynamic v) { - _checkThrow(v, (_) {}); -} - -Matcher throwsA(dynamic matcher) => (dynamic o) { - _checkThrow(o, (error) { - expect(error, matcher); - }); - }; - -Matcher completion(dynamic matcher) => (dynamic o) { - Expect.type>(o); - final Future future = o as Future; - asyncStart(); - future.then((value) { - expect(value, matcher); - asyncEnd(); - }); - }; - -void completes(dynamic o) { - Expect.type>(o); - final Future future = o as Future; - asyncStart(); - future.then(asyncSuccess); -} - -void isMap(dynamic o) { - Expect.type>(o); -} - -void isList(dynamic o) { - Expect.type>(o); -} - -void isNotNull(dynamic o) { - Expect.isNotNull(o); -} - -abstract class _Matcher { - void call(dynamic o); -} - -// ignore: camel_case_types -class isInstanceOf implements _Matcher { - @override - void call(dynamic o) { - Expect.type(o); - } -} - -void throwsArgumentError(dynamic v) { - _checkThrow(v, (_) {}); -} - -void throwsStateError(dynamic v) { - _checkThrow(v, (_) {}); -} - -void fail(String message) { - Expect.fail(message); -} - -/// Key for zone value holding current test name. -final _testToken = Object(); - -bool _initializedTestNameCallback = false; - -/// The current combined name of the nesting [group] or [test]. -String _currentName = ''; - -String _pushName(String newName) { - // Look up the current test name from the zone created for the test. - if (!_initializedTestNameCallback) { - ExpectException.setTestNameCallback( - () => Zone.current[_testToken] as String); - _initializedTestNameCallback = true; - } - - final oldName = _currentName; - if (oldName == '') { - _currentName = newName; - } else { - _currentName = '$oldName $newName'; - } - return oldName; -} - -void _popName(String oldName) { - _currentName = oldName; -} diff --git a/engine/src/flutter/testing/litetest/lib/src/matchers.dart b/engine/src/flutter/testing/litetest/lib/src/matchers.dart deleted file mode 100644 index a48f533e47..0000000000 --- a/engine/src/flutter/testing/litetest/lib/src/matchers.dart +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:expect/expect.dart'; -import 'async_minitest.dart'; - -/// The epsilon of tolerable double precision error. -/// -/// This is used in various places in the framework to allow for floating point -/// precision loss in calculations. Differences below this threshold are safe -/// to disregard. -const double precisionErrorTolerance = 1e-10; - -/// Asserts that `callback` throws an [AssertionError]. -/// -/// When running in a VM in which assertions are enabled, asserts that the -/// specified callback throws an [AssertionError]. When asserts are not -/// enabled, such as when running using a release-mode VM with default -/// settings, this acts as a no-op. -void expectAssertion(dynamic callback) { - bool assertsEnabled = false; - assert(() { - assertsEnabled = true; - return true; - }()); - if (assertsEnabled) { - throwsA(isInstanceOf())(callback); - } -} - -/// Asserts that `callback` throws an [ArgumentError]. -void expectArgumentError(dynamic callback) { - throwsA(isInstanceOf())(callback); -} - -/// Asserts that `callback` throws some [Exception]. -void throwsException(dynamic callback) { - throwsA(isInstanceOf())(callback); -} - -/// A [Matcher] that matches empty [String]s and [Iterable]s. -void isEmpty(dynamic d) { - if (d is String) { - expect(d.isEmpty, true); - return; - } - expect(d, isInstanceOf>()); - Expect.isEmpty(d as Iterable); -} - -/// A [Matcher] that matches non-empty [String]s and [Iterable]s. -void isNotEmpty(dynamic d) { - if (d is String) { - expect(d.isNotEmpty, true); - return; - } - expect(d, isInstanceOf>()); - Expect.isNotEmpty(d as Iterable); -} - -/// Gives a [Matcher] that asserts that the value being matched is within -/// `tolerance` of `value`. -Matcher closeTo(num value, num tolerance) => (dynamic actual) { - Expect.approxEquals(value, actual as num, tolerance); - }; - -/// A [Matcher] that matches NaN. -void isNaN(dynamic v) { - expect(v, isInstanceOf()); - expect(double.nan.compareTo(v as num) == 0, true); -} - -/// Gives a [Matcher] that asserts that the value being matched is not equal to -/// `unexpected`. -Matcher notEquals(dynamic unexpected) => (dynamic actual) { - Expect.notEquals(unexpected, actual); - }; - -/// A [Matcher] that matches non-zero values. -void isNonZero(dynamic d) { - Expect.notEquals(0, d); -} - -/// A [Matcher] that matches functions that throw a [RangeError] when invoked. -void throwsRangeError(dynamic d) { - Expect.throwsRangeError(d as void Function()); -} - -/// A [Matcher] that matches functions that throw a [RangeError] when invoked. -void throwsFormatException(dynamic d) { - Expect.throwsFormatException(d as void Function()); -} - -/// Gives a [Matcher] that asserts that the value being matched is a [String] -/// that contains `s` as a substring. -Matcher contains(String s) => (dynamic d) { - expect(d, isInstanceOf()); - Expect.contains(s, d as String); - }; - -/// Gives a [Matcher] that asserts that the value being matched is an [Iterable] -/// of length `d`. -Matcher hasLength(int l) => (dynamic d) { - expect(d, isInstanceOf>()); - expect((d as Iterable).length, equals(l)); - }; - -/// Gives a matcher that asserts that the value being matched is a [String] that -/// starts with `s`. -Matcher startsWith(String s) => (dynamic d) { - expect(d, isInstanceOf()); - final String h = d as String; - if (!h.startsWith(s)) { - Expect.fail('Expected "$h" to start with "$s"'); - } - }; - -/// Gives a matcher that asserts that the value being matched is a [String] that -/// ends with `s`. -Matcher endsWith(String s) => (dynamic d) { - expect(d, isInstanceOf()); - final String h = d as String; - if (!h.endsWith(s)) { - Expect.fail('Expected "$h" to end with "$s"'); - } - }; - -/// Gives a matcher that asserts that the value being matched is a [String] that -/// regexp matches with `pattern`. -Matcher hasMatch(String pattern) => (dynamic d) { - expect(d, isInstanceOf()); - final String h = d as String; - final RegExp regExp = RegExp(pattern); - if (!regExp.hasMatch(h)) { - Expect.fail('Expected "$h" to match with "$pattern"'); - } - }; - -/// Gives a matcher that asserts that the value being matched is a -/// `List` that contains the entries in `pattern` in order. -/// There may be values that are not in the pattern interleaved. -Matcher containsStringsInOrder(List pattern) => (dynamic d) { - expect(d, isInstanceOf>()); - final List input = d as List; - int cursor = 0; - for (final String el in input) { - if (cursor == pattern.length) { - break; - } - if (el == pattern[cursor]) { - cursor++; - } - } - if (cursor < pattern.length) { - Expect.fail('Did not find ${pattern[cursor]} in $d'); - } - }; - -/// Gives a matcher that asserts that the value being matched is a -/// `List` that does not contain any of the values in `unexpected`. -Matcher doesNotContainAny(List unexpected) => (dynamic d) { - expect(d, isInstanceOf>()); - final List input = d as List; - for (final String string in input) { - if (unexpected.contains(string)) { - Expect.fail("String '$d' is unexpected"); - } - } - }; diff --git a/engine/src/flutter/testing/litetest/lib/src/test.dart b/engine/src/flutter/testing/litetest/lib/src/test.dart deleted file mode 100644 index ae48d0c3c2..0000000000 --- a/engine/src/flutter/testing/litetest/lib/src/test.dart +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:async'; -import 'dart:io' show stdout; -import 'dart:isolate'; - -import 'package:expect/expect.dart' as e; -import 'async_minitest.dart' as m; - -/// The state that each [Test] may be in. -enum TestState { - /// Initial state of a [Test] after it has been allocated. - allocated, - - /// State of a [Test] when it is on the queue of a [TestSuite]. - queued, - - /// State of a [Test] when it has been started. - started, - - /// State of a [Test] when it has succeeded. - succeeded, - - /// State of a [Test] when it has failed. - failed, -} - -/// A test that a [TestSuite] can enqueue to run. -class Test { - /// Creates a [Test] with the given name, body, logger, and lifecycle. - Test( - this.name, - this.body, { - StringSink? logger, - TestLifecycle? lifecycle, - }) : - _logger = logger ?? stdout, - _lifecycle = lifecycle ?? _DefaultTestLifecycle(name); - - /// The name of the test. - final String name; - - /// The body of the test. - final dynamic Function() body; - - /// The logger that records information about the test. - final StringSink _logger; - - /// The state that the test is in. - TestState state = TestState.allocated; - - final TestLifecycle _lifecycle; - - /// Runs the test. - /// - /// Also signals the test's progress to the [TestLifecycle] object - /// that was provided when the [Test] was constructed, which will eventually - /// call the provided [onDone] callback. - void run({ - void Function()? onDone, - }) { - m.test(name, () async { - await Future(() async { - state = TestState.started; - _logger.writeln('Test "$name": Started'); - try { - await body(); - state = TestState.succeeded; - _logger.writeln('Test "$name": Passed'); - } on e.ExpectException catch (e, st) { - state = TestState.failed; - _logger.writeln('Test "$name": Failed\n$e\n$st'); - } finally { - _lifecycle.onDone(cleanup: onDone); - } - }); - }); - _lifecycle.onStart(); - } -} - -/// Callbacks for the lifecycle of a test. -abstract class TestLifecycle { - /// Called after a test has started. - void onStart(); - - /// Called when a test is finished. - /// - /// The callback should ensure that the [cleanup] function should run - /// eventually if provided. - void onDone({void Function()? cleanup}); -} - -class _DefaultTestLifecycle implements TestLifecycle { - _DefaultTestLifecycle(String name) : _port = ReceivePort(name); - - final ReceivePort _port; - - void Function()? _cleanup; - - @override - void onStart() { - _port.listen((dynamic msg) { - _port.close(); - if (_cleanup != null) { - _cleanup!(); - } - }); - } - - @override - void onDone({void Function()? cleanup}) { - _port.sendPort.send(null); - _cleanup = cleanup; - } -} diff --git a/engine/src/flutter/testing/litetest/lib/src/test_suite.dart b/engine/src/flutter/testing/litetest/lib/src/test_suite.dart deleted file mode 100644 index 7ea0f4505e..0000000000 --- a/engine/src/flutter/testing/litetest/lib/src/test_suite.dart +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:async'; -import 'dart:collection'; -import 'dart:io' show stdout; -import 'dart:isolate'; - -import 'test.dart'; - -/// A suite of tests, added with the [test] method, which will be run in a -/// following event. -class TestSuite { - /// Creates a new [TestSuite] with logs written to [logger] and callbacks - /// given by [lifecycle]. - TestSuite({ - StringSink? logger, - Lifecycle? lifecycle, - }) : - _logger = logger ?? stdout, - _lifecycle = lifecycle ?? _DefaultLifecycle(); - - final Lifecycle _lifecycle; - final StringSink _logger; - bool _testQueuePrimed = false; - final Queue _testQueue = Queue(); - final Map _runningTests = {}; - - /// Adds a test to the test suite. - void test( - String name, - dynamic Function() body, { - bool skip = false, - }) { - if (_runningTests.isNotEmpty) { - throw StateError( - 'Test "$name" added after tests have started to run. ' - 'Calls to test() must be synchronous with main().', - ); - } - if (skip) { - _logger.writeln('Test "$name": Skipped'); - _primeQueue(); - return; - } - _pushTest(name, body); - } - - void _primeQueue() { - if (!_testQueuePrimed) { - // All tests() must be added synchronously with main, so we can enqueue an - // event to start all tests to run after main() is done. - Timer.run(_startAllTests); - _testQueuePrimed = true; - } - } - - void _pushTest( - String name, - dynamic Function() body, - ) { - final Test newTest = Test(name, body, logger: _logger); - _testQueue.add(newTest); - newTest.state = TestState.queued; - _primeQueue(); - } - - void _startAllTests() { - for (final Test t in _testQueue) { - _runningTests[t.name] = t; - t.run(onDone: () { - _runningTests.remove(t.name); - if (_runningTests.isEmpty) { - _lifecycle.onDone(_testQueue); - } - }); - } - _lifecycle.onStart(); - if (_testQueue.isEmpty) { - _logger.writeln('All tests skipped.'); - _lifecycle.onDone(_testQueue); - } - } -} - -/// Callbacks for the lifecycle of a [TestSuite]. -abstract class Lifecycle { - /// Called after a test suite has started. - void onStart(); - - /// Called after the last test in a test suite has completed. - void onDone(Queue tests); -} - -class _DefaultLifecycle implements Lifecycle { - final ReceivePort _suitePort = ReceivePort('Suite port'); - late Queue _tests; - - @override - void onStart() { - _suitePort.listen((dynamic msg) { - _suitePort.close(); - _processResults(); - }); - } - - @override - void onDone(Queue tests) { - _tests = tests; - _suitePort.sendPort.send(null); - } - - void _processResults() { - bool testsSucceeded = true; - for (final Test t in _tests) { - testsSucceeded = testsSucceeded && (t.state == TestState.succeeded); - } - if (!testsSucceeded) { - throw 'A test failed'; - } - } -} diff --git a/engine/src/flutter/testing/litetest/pubspec.yaml b/engine/src/flutter/testing/litetest/pubspec.yaml deleted file mode 100644 index c0cddf570e..0000000000 --- a/engine/src/flutter/testing/litetest/pubspec.yaml +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2013 The Flutter Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -name: litetest -publish_to: none - -# Required for workspace support. -environment: - sdk: ^3.5.0-294.0.dev - -# This package is managed as part of the engine workspace. -resolution: workspace - -dependencies: - async_helper: any - expect: any - meta: any - smith: any diff --git a/engine/src/flutter/testing/litetest/test/litetest_test.dart b/engine/src/flutter/testing/litetest/test/litetest_test.dart deleted file mode 100644 index 61e63df06f..0000000000 --- a/engine/src/flutter/testing/litetest/test/litetest_test.dart +++ /dev/null @@ -1,252 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:async'; -import 'dart:collection'; -import 'dart:isolate'; - -import 'package:async_helper/async_helper.dart'; -import 'package:litetest/src/async_minitest.dart'; -import 'package:litetest/src/test.dart'; -import 'package:litetest/src/test_suite.dart'; - -Future main() async { - asyncStart(); - - test('skip', () async { - final StringBuffer buffer = StringBuffer(); - final TestLifecycle lifecycle = TestLifecycle(); - final TestSuite ts = TestSuite( - logger: buffer, - lifecycle: lifecycle, - ); - - ts.test('Test', () { - expect(1, equals(1)); - }, skip: true); - final bool result = await lifecycle.result; - - expect(result, true); - expect(buffer.toString(), equals( - 'Test "Test": Skipped\nAll tests skipped.\n', - )); - }); - - test('test', () async { - final StringBuffer buffer = StringBuffer(); - final TestLifecycle lifecycle = TestLifecycle(); - final TestSuite ts = TestSuite( - logger: buffer, - lifecycle: lifecycle, - ); - - ts.test('Test', () { - expect(1, equals(1)); - }); - final bool result = await lifecycle.result; - - expect(result, true); - expect(buffer.toString(), equals( - 'Test "Test": Started\nTest "Test": Passed\n', - )); - }); - - test('multiple tests', () async { - final StringBuffer buffer = StringBuffer(); - final TestLifecycle lifecycle = TestLifecycle(); - final TestSuite ts = TestSuite( - logger: buffer, - lifecycle: lifecycle, - ); - - ts.test('Test1', () { - expect(1, equals(1)); - }); - ts.test('Test2', () { - expect(2, equals(2)); - }); - ts.test('Test3', () { - expect(3, equals(3)); - }); - final bool result = await lifecycle.result; - - expect(result, true); - expect(buffer.toString(), equals(''' -Test "Test1": Started -Test "Test1": Passed -Test "Test2": Started -Test "Test2": Passed -Test "Test3": Started -Test "Test3": Passed -''', - )); - }); - - test('multiple tests with failure', () async { - final StringBuffer buffer = StringBuffer(); - final TestLifecycle lifecycle = TestLifecycle(); - final TestSuite ts = TestSuite( - logger: buffer, - lifecycle: lifecycle, - ); - - ts.test('Test1', () { - expect(1, equals(1)); - }); - ts.test('Test2', () { - expect(2, equals(3)); - }); - ts.test('Test3', () { - expect(3, equals(3)); - }); - final bool result = await lifecycle.result; - final String output = buffer.toString(); - - expect(result, false); - expect(output.contains('Test "Test1": Started'), true); - expect(output.contains('Test "Test1": Passed'), true); - expect(output.contains('Test "Test2": Started'), true); - expect(output.contains('Test "Test2": Failed'), true); - expect(output.contains( - 'In test "Test2" Expect.deepEquals(expected: <3>, actual: <2>, \'[]\') fails.', - ), true); - expect(output.contains('Test "Test3": Started'), true); - expect(output.contains('Test "Test3": Passed'), true); - }); - - test('test fail', () async { - final StringBuffer buffer = StringBuffer(); - final TestLifecycle lifecycle = TestLifecycle(); - final TestSuite ts = TestSuite( - logger: buffer, - lifecycle: lifecycle, - ); - - ts.test('Test', () { - expect(1, equals(2)); - }); - final bool result = await lifecycle.result; - final String output = buffer.toString(); - - expect(result, false); - expect(output.contains('Test "Test": Started'), true); - expect(output.contains('Test "Test": Failed'), true); - expect( - output.contains( - 'In test "Test" Expect.deepEquals(expected: <2>, actual: <1>, \'[]\') fails.', - ), - true, - ); - }); - - test('async test', () async { - final StringBuffer buffer = StringBuffer(); - final TestLifecycle lifecycle = TestLifecycle(); - final TestSuite ts = TestSuite( - logger: buffer, - lifecycle: lifecycle, - ); - - ts.test('Test', () async { - final Completer completer = Completer(); - Timer.run(() { - completer.complete(); - }); - await completer.future; - expect(1, equals(1)); - }); - final bool result = await lifecycle.result; - - expect(result, true); - expect(buffer.toString(), equals( - 'Test "Test": Started\nTest "Test": Passed\n', - )); - }); - - test('async test fail', () async { - final StringBuffer buffer = StringBuffer(); - final TestLifecycle lifecycle = TestLifecycle(); - final TestSuite ts = TestSuite( - logger: buffer, - lifecycle: lifecycle, - ); - - ts.test('Test', () async { - final Completer completer = Completer(); - Timer.run(() { - completer.complete(); - }); - await completer.future; - expect(1, equals(2)); - }); - final bool result = await lifecycle.result; - final String output = buffer.toString(); - - expect(result, false); - expect(output.contains('Test "Test": Started'), true); - expect(output.contains('Test "Test": Failed'), true); - expect( - output.contains( - 'In test "Test" Expect.deepEquals(expected: <2>, actual: <1>, \'[]\') fails.', - ), - true, - ); - }); - - test('throws StateError on async test() call', () async { - final StringBuffer buffer = StringBuffer(); - final TestLifecycle lifecycle = TestLifecycle(); - final TestSuite ts = TestSuite( - logger: buffer, - lifecycle: lifecycle, - ); - - ts.test('Test', () { - expect(1, equals(1)); - }); - - bool caughtError = false; - try { - await Future(() async { - ts.test('Bad Test', () {}); - }); - } on StateError catch (e) { - caughtError = true; - expect(e.message.contains( - 'Test "Bad Test" added after tests have started to run.', - ), true); - } - expect(caughtError, true); - - final bool result = await lifecycle.result; - - expect(result, true); - expect(buffer.toString(), equals( - 'Test "Test": Started\nTest "Test": Passed\n', - )); - }); - - asyncEnd(); -} - -class TestLifecycle implements Lifecycle { - final ReceivePort port = ReceivePort(); - - final Completer _testCompleter = Completer(); - - Future get result => _testCompleter.future; - - @override - void onStart() {} - - @override - void onDone(Queue tests) { - bool testsSucceeded = true; - for (final Test t in tests) { - testsSucceeded = testsSucceeded && (t.state == TestState.succeeded); - } - _testCompleter.complete(testsSucceeded); - port.close(); - } -} diff --git a/engine/src/flutter/testing/run_tests.py b/engine/src/flutter/testing/run_tests.py index aae1fc1a16..560bf83c63 100755 --- a/engine/src/flutter/testing/run_tests.py +++ b/engine/src/flutter/testing/run_tests.py @@ -979,7 +979,6 @@ def build_dart_host_test_list(build_dir): dart_host_tests = [ (os.path.join('flutter', 'ci'), []), (os.path.join('flutter', 'flutter_frontend_server'), []), - (os.path.join('flutter', 'testing', 'litetest'), []), (os.path.join('flutter', 'testing', 'skia_gold_client'), []), (os.path.join('flutter', 'testing', 'scenario_app'), []), ( diff --git a/engine/src/flutter/tools/pub_get_offline.py b/engine/src/flutter/tools/pub_get_offline.py index ad5c88c348..2bf6b8ace5 100644 --- a/engine/src/flutter/tools/pub_get_offline.py +++ b/engine/src/flutter/tools/pub_get_offline.py @@ -29,7 +29,6 @@ ALL_PACKAGES = [ os.path.join(ENGINE_DIR, 'shell', 'vmservice'), os.path.join(ENGINE_DIR, 'testing', 'benchmark'), os.path.join(ENGINE_DIR, 'testing', 'dart'), - os.path.join(ENGINE_DIR, 'testing', 'litetest'), os.path.join(ENGINE_DIR, 'testing', 'scenario_app'), os.path.join(ENGINE_DIR, 'testing', 'skia_gold_client'), os.path.join(ENGINE_DIR, 'testing', 'smoke_test_failure'),