Align more closely with package:test (#77118) (#78343)

This commit is contained in:
Ian Hickson
2021-03-16 13:58:02 -07:00
committed by GitHub
parent 0cf1007276
commit f3c25fa07a
105 changed files with 173 additions and 328 deletions

View File

@@ -9,8 +9,7 @@ import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:test_api/src/frontend/async_matcher.dart'; // ignore: implementation_imports
// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:test_api/test_api.dart'; // ignore: deprecated_member_use
import 'binding.dart';
import 'finders.dart';

View File

@@ -7,8 +7,7 @@ import 'dart:ui' as ui;
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:test_api/src/frontend/async_matcher.dart'; // ignore: implementation_imports
// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:test_api/test_api.dart'; // ignore: deprecated_member_use
import 'binding.dart';
import 'finders.dart';

View File

@@ -7,10 +7,9 @@ import 'dart:typed_data';
import 'dart:ui' as ui;
import 'dart:ui';
// This import is discouraged in general, but we need it to implement flutter_test.
// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' as test_package show TypeMatcher;
import 'package:test_api/test_api.dart';
import 'package:test_api/src/frontend/async_matcher.dart'; // ignore: implementation_imports
import 'package:flutter/foundation.dart';
@@ -196,7 +195,7 @@ final Matcher throwsAssertionError = throwsA(isAssertionError);
///
/// * [throwsFlutterError], to test if a function throws a [FlutterError].
/// * [isAssertionError], to test if any object is any kind of [AssertionError].
final test_package.TypeMatcher<FlutterError> isFlutterError = isA<FlutterError>();
final TypeMatcher<FlutterError> isFlutterError = isA<FlutterError>();
/// A matcher for [AssertionError].
///
@@ -206,11 +205,12 @@ final test_package.TypeMatcher<FlutterError> isFlutterError = isA<FlutterError>(
///
/// * [throwsAssertionError], to test if a function throws any [AssertionError].
/// * [isFlutterError], to test if any object is a [FlutterError].
final test_package.TypeMatcher<AssertionError> isAssertionError = isA<AssertionError>();
final TypeMatcher<AssertionError> isAssertionError = isA<AssertionError>();
/// A matcher that compares the type of the actual value to the type argument T.
// TODO(ianh): Remove this once https://github.com/dart-lang/matcher/issues/98 is fixed
test_package.TypeMatcher<T> isInstanceOf<T>() => isA<T>();
///
/// This is identical to [isA] and is included for backwards compatibility.
TypeMatcher<T> isInstanceOf<T>() => isA<T>();
/// Asserts that two [double]s are equal, within some tolerated error.
///

View File

@@ -11,6 +11,7 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
// The test_api package is not for general use... it's literally for our use.
// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' as test_package;
@@ -25,13 +26,26 @@ import 'test_compat.dart';
import 'test_pointer.dart';
import 'test_text_input.dart';
/// Keep users from needing multiple imports to test semantics.
// Keep users from needing multiple imports to test semantics.
export 'package:flutter/rendering.dart' show SemanticsHandle;
// We re-export the test package minus some features that we reimplement.
//
// Specifically:
//
// - test, group, setUpAll, tearDownAll, setUp, tearDown, and expect would
// conflict with our own implementations in test_compat.dart. This handles
// setting up a declarer when one is not defined, which can happen when a
// test is executed via `flutter run`.
//
// - expect is reimplemented below, to catch incorrect async usage.
//
// - isInstanceOf is reimplemented in matchers.dart because we don't want to
// mark it as deprecated (ours is just a method, not a class).
//
// The test_api package has a deprecation warning to discourage direct use but
// that doesn't apply here.
// ignore: deprecated_member_use
/// Hide these imports so that they do not conflict with our own implementations in
/// test_compat.dart. This handles setting up a declarer when one is not defined, which
/// can happen when a test is executed via flutter_run.
export 'package:test_api/test_api.dart' hide
test,
group,
@@ -39,9 +53,8 @@ export 'package:test_api/test_api.dart' hide
tearDownAll,
setUp,
tearDown,
expect, // we have our own wrapper below
TypeMatcher, // matcher's TypeMatcher conflicts with the one in the Flutter framework
isInstanceOf; // we have our own wrapper in matchers.dart
expect,
isInstanceOf;
/// Signature for callback to [testWidgets] and [benchmarkWidgets].
typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);