Fix how tests count open SemanticsHandles (#121571)
Fix how tests count open SemanticsHandles
This commit is contained in:
committed by
GitHub
parent
f97a51533b
commit
6de42a70f1
@@ -737,7 +737,6 @@ void main() {
|
||||
|
||||
testWidgets('failure does not throw unexpected errors', (WidgetTester tester) async {
|
||||
final SemanticsHandle handle = tester.ensureSemantics();
|
||||
addTearDown(() => handle.dispose());
|
||||
|
||||
const Key key = Key('semantics');
|
||||
await tester.pumpWidget(Semantics(
|
||||
@@ -789,13 +788,13 @@ void main() {
|
||||
);
|
||||
|
||||
expect(failedExpectation, throwsA(isA<TestFailure>()));
|
||||
handle.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
group('containsSemantics', () {
|
||||
testWidgets('matches SemanticsData', (WidgetTester tester) async {
|
||||
final SemanticsHandle handle = tester.ensureSemantics();
|
||||
addTearDown(() => handle.dispose());
|
||||
|
||||
const Key key = Key('semantics');
|
||||
await tester.pumpWidget(Semantics(
|
||||
@@ -889,6 +888,7 @@ void main() {
|
||||
)),
|
||||
reason: 'onTapHint "scans" should not have matched "scan".',
|
||||
);
|
||||
handle.dispose();
|
||||
});
|
||||
|
||||
testWidgets('can match all semantics flags and actions enabled', (WidgetTester tester) async {
|
||||
@@ -1233,7 +1233,6 @@ void main() {
|
||||
|
||||
testWidgets('failure does not throw unexpected errors', (WidgetTester tester) async {
|
||||
final SemanticsHandle handle = tester.ensureSemantics();
|
||||
addTearDown(() => handle.dispose());
|
||||
|
||||
const Key key = Key('semantics');
|
||||
await tester.pumpWidget(Semantics(
|
||||
@@ -1283,6 +1282,7 @@ void main() {
|
||||
);
|
||||
|
||||
expect(failedExpectation, throwsA(isA<TestFailure>()));
|
||||
handle.dispose();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright 2014 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 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
final List<FlutterErrorDetails> errors = <FlutterErrorDetails>[];
|
||||
|
||||
Future<void> testExecutable(FutureOr<void> Function() testMain) async {
|
||||
reportTestException = (FlutterErrorDetails details, String testDescription) {
|
||||
errors.add(details);
|
||||
};
|
||||
|
||||
// The error that the test throws in their run methods below will be forwarded
|
||||
// to our exception handler above and do not cause the test to fail. The
|
||||
// tearDown method then checks that the test threw the expected exception.
|
||||
await testMain();
|
||||
}
|
||||
|
||||
void pipelineOwnerTestRun() {
|
||||
testWidgets('open SemanticsHandle from PipelineOwner fails test', (WidgetTester tester) async {
|
||||
final int outstandingHandles = tester.binding.pipelineOwner.debugOutstandingSemanticsHandles;
|
||||
tester.binding.pipelineOwner.ensureSemantics();
|
||||
expect(tester.binding.pipelineOwner.debugOutstandingSemanticsHandles, outstandingHandles + 1);
|
||||
// SemanticsHandle is not disposed on purpose to verify in tearDown that
|
||||
// the test failed due to an active SemanticsHandle.
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
expect(errors, hasLength(1));
|
||||
expect(errors.single.toString(), contains('SemanticsHandle was active at the end of the test'));
|
||||
});
|
||||
}
|
||||
|
||||
void semanticsBindingTestRun() {
|
||||
testWidgets('open SemanticsHandle from SemanticsBinding fails test', (WidgetTester tester) async {
|
||||
final int outstandingHandles = tester.binding.debugOutstandingSemanticsHandles;
|
||||
tester.binding.ensureSemantics();
|
||||
expect(tester.binding.debugOutstandingSemanticsHandles, outstandingHandles + 1);
|
||||
// SemanticsHandle is not disposed on purpose to verify in tearDown that
|
||||
// the test failed due to an active SemanticsHandle.
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
expect(errors, hasLength(1));
|
||||
expect(errors.single.toString(), contains('SemanticsHandle was active at the end of the test'));
|
||||
});
|
||||
}
|
||||
|
||||
void failingTestTestRun() {
|
||||
testWidgets('open SemanticsHandle from SemanticsBinding fails test', (WidgetTester tester) async {
|
||||
final int outstandingHandles = tester.binding.debugOutstandingSemanticsHandles;
|
||||
tester.binding.ensureSemantics();
|
||||
expect(tester.binding.debugOutstandingSemanticsHandles, outstandingHandles + 1);
|
||||
|
||||
// Failing expectation to verify that an open semantics handle doesn't
|
||||
// cause any cascading failures and only the failing expectation is
|
||||
// reported.
|
||||
expect(1, equals(2));
|
||||
fail('The test should never have gotten this far.');
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
expect(errors, hasLength(1));
|
||||
expect(errors.single.toString(), contains('Expected: <2>'));
|
||||
expect(errors.single.toString(), contains('Actual: <1>'));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2014 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 'flutter_test_config.dart' as config;
|
||||
|
||||
void main() => config.failingTestTestRun();
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2014 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 'flutter_test_config.dart' as config;
|
||||
|
||||
void main() => config.pipelineOwnerTestRun();
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2014 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 'flutter_test_config.dart' as config;
|
||||
|
||||
void main() => config.semanticsBindingTestRun();
|
||||
Reference in New Issue
Block a user