Remove all references to litetest from the engine repo. (flutter/engine#55163)

Closes https://github.com/flutter/flutter/issues/133569.
This commit is contained in:
Matan Lurey
2024-09-12 16:26:25 -07:00
committed by GitHub
parent cf2deecf07
commit 425e6c707d
12 changed files with 0 additions and 1087 deletions

View File

@@ -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:

View File

@@ -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;

View File

@@ -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.

View File

@@ -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;

View File

@@ -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<dynamic>) {
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>(R Function() f, {int count = 1}) {
asyncStart(count);
return () {
final result = f();
asyncEnd();
return result;
};
}
R Function(A) expectAsync1<R, A>(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, A, B>(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<num>(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<num>(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<num>(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<num>(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<String> 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<T extends Object>(
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<T>(v as void Function(), (dynamic e) {
onError(e);
return true;
});
}
void returnsNormally(dynamic o) {
try {
Expect.type<void Function()>(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<Object>(v, (_) {});
}
Matcher throwsA(dynamic matcher) => (dynamic o) {
_checkThrow<Object>(o, (error) {
expect(error, matcher);
});
};
Matcher completion(dynamic matcher) => (dynamic o) {
Expect.type<Future<dynamic>>(o);
final Future<dynamic> future = o as Future<dynamic>;
asyncStart();
future.then((value) {
expect(value, matcher);
asyncEnd();
});
};
void completes(dynamic o) {
Expect.type<Future<dynamic>>(o);
final Future<dynamic> future = o as Future<dynamic>;
asyncStart();
future.then<void>(asyncSuccess);
}
void isMap(dynamic o) {
Expect.type<Map<dynamic, dynamic>>(o);
}
void isList(dynamic o) {
Expect.type<List<dynamic>>(o);
}
void isNotNull(dynamic o) {
Expect.isNotNull(o);
}
abstract class _Matcher {
void call(dynamic o);
}
// ignore: camel_case_types
class isInstanceOf<T> implements _Matcher {
@override
void call(dynamic o) {
Expect.type<T>(o);
}
}
void throwsArgumentError(dynamic v) {
_checkThrow<ArgumentError>(v, (_) {});
}
void throwsStateError(dynamic v) {
_checkThrow<StateError>(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;
}

View File

@@ -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<AssertionError>())(callback);
}
}
/// Asserts that `callback` throws an [ArgumentError].
void expectArgumentError(dynamic callback) {
throwsA(isInstanceOf<ArgumentError>())(callback);
}
/// Asserts that `callback` throws some [Exception].
void throwsException(dynamic callback) {
throwsA(isInstanceOf<Exception>())(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<Iterable<dynamic>>());
Expect.isEmpty(d as Iterable<dynamic>);
}
/// 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<Iterable<dynamic>>());
Expect.isNotEmpty(d as Iterable<dynamic>);
}
/// 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<num>());
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<String>());
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<Iterable<dynamic>>());
expect((d as Iterable<dynamic>).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<String>());
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<String>());
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<String>());
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<String>` that contains the entries in `pattern` in order.
/// There may be values that are not in the pattern interleaved.
Matcher containsStringsInOrder(List<String> pattern) => (dynamic d) {
expect(d, isInstanceOf<List<String>>());
final List<String> input = d as List<String>;
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<String>` that does not contain any of the values in `unexpected`.
Matcher doesNotContainAny(List<String> unexpected) => (dynamic d) {
expect(d, isInstanceOf<List<String>>());
final List<String> input = d as List<String>;
for (final String string in input) {
if (unexpected.contains(string)) {
Expect.fail("String '$d' is unexpected");
}
}
};

View File

@@ -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<void>(() 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;
}
}

View File

@@ -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<Test> _testQueue = Queue<Test>();
final Map<String, Test> _runningTests = <String, Test>{};
/// 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<Test> tests);
}
class _DefaultLifecycle implements Lifecycle {
final ReceivePort _suitePort = ReceivePort('Suite port');
late Queue<Test> _tests;
@override
void onStart() {
_suitePort.listen((dynamic msg) {
_suitePort.close();
_processResults();
});
}
@override
void onDone(Queue<Test> 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';
}
}
}

View File

@@ -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

View File

@@ -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<void> 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<void> completer = Completer<void>();
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<void> completer = Completer<void>();
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<void>(() 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<bool> _testCompleter = Completer<bool>();
Future<bool> get result => _testCompleter.future;
@override
void onStart() {}
@override
void onDone(Queue<Test> tests) {
bool testsSucceeded = true;
for (final Test t in tests) {
testsSucceeded = testsSucceeded && (t.state == TestState.succeeded);
}
_testCompleter.complete(testsSucceeded);
port.close();
}
}

View File

@@ -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'), []),
(

View File

@@ -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'),