Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove uses of deprecated test_api imports #124732

Merged
merged 6 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,8 +4,7 @@

import 'package:flutter_gallery/demo/calculator/logic.dart';

// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;

void main() {
test('Test order of operations: 12 + 3 * 4 = 24', () {
Expand Down
2 changes: 1 addition & 1 deletion dev/missing_dependency_tests/trivial_test.dart
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;

void main() {
test('Trivial test', () {
Expand Down
3 changes: 1 addition & 2 deletions examples/layers/test/smoketests/raw/canvas_test.dart
Expand Up @@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher, isInstanceOf;

import '../../../raw/canvas.dart' as demo;

Expand Down
3 changes: 1 addition & 2 deletions examples/layers/test/smoketests/raw/hello_world_test.dart
Expand Up @@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher, isInstanceOf;

import '../../../raw/hello_world.dart' as demo;

Expand Down
Expand Up @@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher, isInstanceOf;

import '../../../raw/spinning_square.dart' as demo;

Expand Down
3 changes: 1 addition & 2 deletions examples/layers/test/smoketests/raw/text_test.dart
Expand Up @@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher, isInstanceOf;

import '../../../raw/text.dart' as demo;

Expand Down
3 changes: 1 addition & 2 deletions examples/layers/test/smoketests/raw/touch_input_test.dart
Expand Up @@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher, isInstanceOf;

import '../../../raw/touch_input.dart' as demo;

Expand Down
Expand Up @@ -4,8 +4,7 @@

import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher, isInstanceOf;

import '../../../rendering/custom_coordinate_systems.dart' as demo;

Expand Down
Expand Up @@ -4,8 +4,7 @@

import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher, isInstanceOf;

import '../../../rendering/flex_layout.dart' as demo;

Expand Down
Expand Up @@ -4,8 +4,7 @@

import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher, isInstanceOf;

import '../../../rendering/hello_world.dart' as demo;

Expand Down
Expand Up @@ -4,8 +4,7 @@

import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher, isInstanceOf;

import '../../../rendering/spinning_square.dart' as demo;

Expand Down
Expand Up @@ -4,8 +4,7 @@

import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
import 'package:flutter_test/flutter_test.dart' hide TypeMatcher, isInstanceOf;

import '../../../rendering/touch_input.dart' as demo;

Expand Down
6 changes: 3 additions & 3 deletions packages/flutter_driver/test/common.dart
Expand Up @@ -5,10 +5,10 @@
import 'dart:io';

import 'package:flutter_driver/src/common/error.dart';
import 'package:test_api/test_api.dart'; // ignore: deprecated_member_use
import 'package:test/test.dart';

export 'package:test_api/fake.dart'; // ignore: deprecated_member_use
export 'package:test_api/test_api.dart'; // ignore: deprecated_member_use
export 'package:test/fake.dart';
export 'package:test/test.dart';

void tryToDelete(Directory directory) {
// This should not be necessary, but it turns out that
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_test/lib/src/_goldens_io.dart
Expand Up @@ -8,8 +8,8 @@ import 'dart:math' as math;
import 'dart:ui';

import 'package:flutter/foundation.dart';
import 'package:matcher/expect.dart' show fail;
import 'package:path/path.dart' as path;
import 'package:test_api/expect.dart' show fail;

import 'goldens.dart';
import 'test_async_utils.dart';
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_test/lib/src/_goldens_web.dart
Expand Up @@ -6,7 +6,7 @@ import 'dart:convert';
import 'dart:html' as html;
import 'dart:typed_data';

import 'package:test_api/expect.dart' show fail;
import 'package:matcher/expect.dart' show fail;

import 'goldens.dart';

Expand Down
5 changes: 3 additions & 2 deletions packages/flutter_test/lib/src/_matchers_io.dart
Expand Up @@ -7,8 +7,9 @@ import 'dart:ui' as ui;

import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:test_api/src/expect/async_matcher.dart'; // ignore: implementation_imports
import 'package:test_api/test_api.dart'; // ignore: deprecated_member_use
import 'package:matcher/expect.dart';
import 'package:matcher/src/expect/async_matcher.dart'; // ignore: implementation_imports
import 'package:test_api/hooks.dart' show TestFailure;

import 'binding.dart';
import 'finders.dart';
Expand Down
5 changes: 3 additions & 2 deletions packages/flutter_test/lib/src/_matchers_web.dart
Expand Up @@ -6,8 +6,9 @@ import 'dart:ui' as ui;

import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:test_api/src/expect/async_matcher.dart'; // ignore: implementation_imports
import 'package:test_api/test_api.dart'; // ignore: deprecated_member_use
import 'package:matcher/expect.dart';
import 'package:matcher/src/expect/async_matcher.dart'; // ignore: implementation_imports
import 'package:test_api/hooks.dart' show TestFailure;

import 'binding.dart';
import 'finders.dart';
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_test/lib/src/buffer_matcher.dart
Expand Up @@ -4,7 +4,7 @@

import 'dart:typed_data';

import 'package:test_api/src/expect/async_matcher.dart'; // ignore: implementation_imports
import 'package:matcher/src/expect/async_matcher.dart'; // ignore: implementation_imports
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own understanding, why is this one not part of the public API of package:matcher? Could it be? Seems like we are using it in a lot of places...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own understanding, why is this one not part of the public API of package:matcher?

AsyncMatcher was originally a hack in package:test. It's not a very easy class to use, and it's behavior is contradictory to the rest of package:matcher.

Could it be?

Now that is has been moved into package:matcher it would be a little less strange to expose it. I'd still be a bit wary to do so, since we don't want to spend effort on things like improving the documentation and compatibility with AsyncMatcher.

I think a better use of time is to focus on the transition to package:checks where async checks are fully supported.

// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' show Description, TestFailure;

Expand Down
6 changes: 2 additions & 4 deletions packages/flutter_test/lib/src/matchers.dart
Expand Up @@ -10,10 +10,8 @@ import 'package:flutter/material.dart' show Card;
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:test_api/src/expect/async_matcher.dart'; // ignore: implementation_imports
// 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';
import 'package:matcher/expect.dart';
import 'package:matcher/src/expect/async_matcher.dart'; // ignore: implementation_imports

import '_matchers_io.dart' if (dart.library.html) '_matchers_web.dart' show MatchesGoldenFile, captureImage;
import 'accessibility.dart';
Expand Down
41 changes: 20 additions & 21 deletions packages/flutter_test/lib/src/widget_tester.dart
Expand Up @@ -9,6 +9,7 @@ import 'package:flutter/material.dart' show Tooltip;
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:matcher/expect.dart' as matcher_expect;
import 'package:meta/meta.dart';

// The test_api package is not for general use... it's literally for our use.
Expand All @@ -28,7 +29,14 @@ import 'test_text_input.dart';

// Keep users from needing multiple imports to test semantics.
export 'package:flutter/rendering.dart' show SemanticsHandle;

// We re-export the matcher package minus some features that we reimplement.
//
// - 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).
//
export 'package:matcher/expect.dart' hide expect, isInstanceOf;
// We re-export the test package minus some features that we reimplement.
//
// Specifically:
Expand All @@ -38,23 +46,14 @@ export 'package:flutter/rendering.dart' show SemanticsHandle;
// 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.
export 'package:test_api/hooks.dart' show TestFailure;
// ignore: deprecated_member_use
export 'package:test_api/test_api.dart' hide
expect,
group,
isInstanceOf,
setUp,
setUpAll,
tearDown,
tearDownAll,
test;
export 'package:test_api/scaffolding.dart'
hide group, setUp, setUpAll, tearDown, tearDownAll, test;
// ignore: implementation_imports
export 'package:test_api/src/scaffolding/utils.dart' show registerException;

/// Signature for callback to [testWidgets] and [benchmarkWidgets].
typedef WidgetTesterCallback = Future<void> Function(WidgetTester widgetTester);
Expand Down Expand Up @@ -442,7 +441,7 @@ Future<void> benchmarkWidgets(

/// Assert that `actual` matches `matcher`.
///
/// See [test_package.expect] for details. This is a variant of that function
/// See [matcher_expect.expect] for details. This is a variant of that function
/// that additionally verifies that there are no asynchronous APIs
/// that have not yet resolved.
///
Expand All @@ -456,12 +455,12 @@ void expect(
dynamic skip, // true or a String
}) {
TestAsyncUtils.guardSync();
test_package.expect(actual, matcher, reason: reason, skip: skip);
matcher_expect.expect(actual, matcher, reason: reason, skip: skip);
}

/// Assert that `actual` matches `matcher`.
///
/// See [test_package.expect] for details. This variant will _not_ check that
/// See [matcher_expect.expect] for details. This variant will _not_ check that
/// there are no outstanding asynchronous API requests. As such, it can be
/// called from, e.g., callbacks that are run during build or layout, or in the
/// completion handlers of futures that execute in response to user input.
Expand All @@ -473,13 +472,13 @@ void expectSync(
dynamic matcher, {
String? reason,
}) {
test_package.expect(actual, matcher, reason: reason);
matcher_expect.expect(actual, matcher, reason: reason);
}

/// Just like [expect], but returns a [Future] that completes when the matcher
/// has finished matching.
///
/// See [test_package.expectLater] for details.
/// See [matcher_expect.expectLater] for details.
///
/// If the matcher fails asynchronously, that failure is piped to the returned
/// future where it can be handled by user code. If it is not handled by user
Expand All @@ -493,7 +492,7 @@ Future<void> expectLater(
// We can't wrap the delegate in a guard, or we'll hit async barriers in
// [TestWidgetsFlutterBinding] while we're waiting for the matcher to complete
TestAsyncUtils.guardSync();
return test_package.expectLater(actual, matcher, reason: reason, skip: skip)
return matcher_expect.expectLater(actual, matcher, reason: reason, skip: skip)
.then<void>((dynamic value) => null);
}

Expand Down
5 changes: 1 addition & 4 deletions packages/flutter_test/test/bindings_test.dart
Expand Up @@ -16,9 +16,6 @@ import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

// ignore: deprecated_member_use
import 'package:test_api/test_api.dart' as test_package;

void main() {
final AutomatedTestWidgetsFlutterBinding binding = AutomatedTestWidgetsFlutterBinding();

Expand All @@ -31,7 +28,7 @@ void main() {

group(AutomatedTestWidgetsFlutterBinding, () {
test('allows setting defaultTestTimeout to 5 minutes', () {
binding.defaultTestTimeout = const test_package.Timeout(Duration(minutes: 5));
binding.defaultTestTimeout = const Timeout(Duration(minutes: 5));
expect(binding.defaultTestTimeout.duration, const Duration(minutes: 5));
});
});
Expand Down