Unverified Commit df3662b1 authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

use throwsA (#82238)

parent 7b9a1755
...@@ -24,14 +24,15 @@ void main() { ...@@ -24,14 +24,15 @@ void main() {
return processRunner.runProcess(commandLine); return processRunner.runProcess(commandLine);
})(<String>['this_executable_better_not_exist_2857632534321']), })(<String>['this_executable_better_not_exist_2857632534321']),
throwsA(isA<PreparePackageException>())); throwsA(isA<PreparePackageException>()));
try {
await processRunner.runProcess(<String>['this_executable_better_not_exist_2857632534321']); await expectLater(
} on PreparePackageException catch (e) { () => processRunner.runProcess(<String>['this_executable_better_not_exist_2857632534321']),
expect( throwsA(isA<PreparePackageException>().having(
e.message, (PreparePackageException error) => error.message,
'message',
contains('ProcessException: Failed to find "this_executable_better_not_exist_2857632534321" in the search path'), contains('ProcessException: Failed to find "this_executable_better_not_exist_2857632534321" in the search path'),
); )),
} );
}); });
for (final String platformName in <String>['macos', 'linux', 'windows']) { for (final String platformName in <String>['macos', 'linux', 'windows']) {
final FakePlatform platform = FakePlatform( final FakePlatform platform = FakePlatform(
......
...@@ -26,12 +26,14 @@ void main() { ...@@ -26,12 +26,14 @@ void main() {
}); });
test('waitForAbsent should time out waiting for text "present" to disappear', () async { test('waitForAbsent should time out waiting for text "present" to disappear', () async {
try { await expectLater(
await driver.waitForAbsent(presentText, timeout: const Duration(seconds: 1)); () => driver.waitForAbsent(presentText, timeout: const Duration(seconds: 1)),
fail('expected DriverError'); throwsA(isA<DriverError>().having(
} on DriverError catch (error) { (DriverError error) => error.message,
expect(error.message, contains('Timeout while executing waitForAbsent')); 'message',
} contains('Timeout while executing waitForAbsent'),
)),
);
}); });
test('waitForAbsent should resolve when text "present" disappears', () async { test('waitForAbsent should resolve when text "present" disappears', () async {
...@@ -51,12 +53,14 @@ void main() { ...@@ -51,12 +53,14 @@ void main() {
}); });
test('waitFor times out waiting for "present" to reappear', () async { test('waitFor times out waiting for "present" to reappear', () async {
try { await expectLater(
await driver.waitFor(presentText, timeout: const Duration(seconds: 1)); () => driver.waitFor(presentText, timeout: const Duration(seconds: 1)),
fail('expected DriverError'); throwsA(isA<DriverError>().having(
} on DriverError catch (error) { (DriverError error) => error.message,
expect(error.message, contains('Timeout while executing waitFor')); 'message',
} contains('Timeout while executing waitFor'),
)),
);
}); });
test('waitFor should resolve when text "present" reappears', () async { test('waitFor should resolve when text "present" reappears', () async {
......
...@@ -30,20 +30,21 @@ Future<void> pumpWidgetWithBoilerplate(WidgetTester tester, Widget widget) async ...@@ -30,20 +30,21 @@ Future<void> pumpWidgetWithBoilerplate(WidgetTester tester, Widget widget) async
Future<void> main() async { Future<void> main() async {
testWidgets('Need at least 2 tabs', (WidgetTester tester) async { testWidgets('Need at least 2 tabs', (WidgetTester tester) async {
try { await expectLater(
await pumpWidgetWithBoilerplate(tester, CupertinoTabBar( () => pumpWidgetWithBoilerplate(tester, CupertinoTabBar(
items: <BottomNavigationBarItem>[ items: <BottomNavigationBarItem>[
BottomNavigationBarItem( BottomNavigationBarItem(
icon: ImageIcon(MemoryImage(Uint8List.fromList(kTransparentImage))), icon: ImageIcon(MemoryImage(Uint8List.fromList(kTransparentImage))),
label: 'Tab 1', label: 'Tab 1',
), ),
], ],
)); )),
fail('Should not be possible to create a tab bar with just one item'); throwsA(isA<AssertionError>().having(
} on AssertionError catch (e) { (AssertionError error) => error.toString(),
expect(e.toString(), contains('items.length')); '.toString()',
// Exception expected. contains('items.length'),
} )),
);
}); });
testWidgets('Active and inactive colors', (WidgetTester tester) async { testWidgets('Active and inactive colors', (WidgetTester tester) async {
......
...@@ -85,35 +85,37 @@ void main() { ...@@ -85,35 +85,37 @@ void main() {
}); });
testWidgets('Need at least 2 children', (WidgetTester tester) async { testWidgets('Need at least 2 children', (WidgetTester tester) async {
final Map<int, Widget> children = <int, Widget>{}; await expectLater(
try { () => tester.pumpWidget(
await tester.pumpWidget(
boilerplate( boilerplate(
child: CupertinoSegmentedControl<int>( child: CupertinoSegmentedControl<int>(
children: children, children: const <int, Widget>{},
onValueChanged: (int newValue) { }, onValueChanged: (int newValue) { },
), ),
), ),
); ),
fail('Should not be possible to create a segmented control with no children'); throwsA(isA<AssertionError>().having(
} on AssertionError catch (e) { (AssertionError error) => error.toString(),
expect(e.toString(), contains('children.length')); '.toString()',
} contains('children.length'),
try { )),
children[0] = const Text('Child 1'); );
await tester.pumpWidget( await expectLater(
() => tester.pumpWidget(
boilerplate( boilerplate(
child: CupertinoSegmentedControl<int>( child: CupertinoSegmentedControl<int>(
children: children, children: const <int, Widget>{0: Text('Child 1')},
onValueChanged: (int newValue) { }, onValueChanged: (int newValue) { },
), ),
), ),
); ),
fail('Should not be possible to create a segmented control with just one child'); throwsA(isA<AssertionError>().having(
} on AssertionError catch (e) { (AssertionError error) => error.toString(),
expect(e.toString(), contains('children.length')); '.toString()',
} contains('children.length'),
)),
);
}); });
testWidgets('Padding works', (WidgetTester tester) async { testWidgets('Padding works', (WidgetTester tester) async {
...@@ -208,8 +210,8 @@ void main() { ...@@ -208,8 +210,8 @@ void main() {
children[0] = const Text('Child 1'); children[0] = const Text('Child 1');
children[1] = const Text('Child 2'); children[1] = const Text('Child 2');
try { await expectLater(
await tester.pumpWidget( () => tester.pumpWidget(
boilerplate( boilerplate(
child: CupertinoSegmentedControl<int>( child: CupertinoSegmentedControl<int>(
children: children, children: children,
...@@ -217,14 +219,13 @@ void main() { ...@@ -217,14 +219,13 @@ void main() {
groupValue: 2, groupValue: 2,
), ),
), ),
); ),
fail( throwsA(isA<AssertionError>().having(
'Should not be possible to create segmented control in which ' (AssertionError error) => error.toString(),
'value is not the key of one of the children widgets', '.toString()',
); contains('children'),
} on AssertionError catch (e) { )),
expect(e.toString(), contains('children')); );
}
}); });
testWidgets('Widgets have correct default text/icon styles, change correctly on selection', (WidgetTester tester) async { testWidgets('Widgets have correct default text/icon styles, change correctly on selection', (WidgetTester tester) async {
......
...@@ -73,50 +73,56 @@ void main() { ...@@ -73,50 +73,56 @@ void main() {
}); });
testWidgets('Need at least 2 children', (WidgetTester tester) async { testWidgets('Need at least 2 children', (WidgetTester tester) async {
final Map<int, Widget> children = <int, Widget>{};
groupValue = null; groupValue = null;
try { await expectLater(
await tester.pumpWidget( () => tester.pumpWidget(
CupertinoSlidingSegmentedControl<int>( CupertinoSlidingSegmentedControl<int>(
children: children, children: const <int, Widget>{},
groupValue: groupValue, groupValue: groupValue,
onValueChanged: defaultCallback, onValueChanged: defaultCallback,
), ),
); ),
fail('Should not be possible to create a segmented control with no children'); throwsA(isA<AssertionError>().having(
} on AssertionError catch (e) { (AssertionError error) => error.toString(),
expect(e.toString(), contains('children.length')); '.toString()',
} contains('children.length'),
try { )),
children[0] = const Text('Child 1'); );
await tester.pumpWidget( await expectLater(
() => tester.pumpWidget(
CupertinoSlidingSegmentedControl<int>( CupertinoSlidingSegmentedControl<int>(
children: children, children: const <int, Widget>{0: Text('Child 1')},
groupValue: groupValue, groupValue: groupValue,
onValueChanged: defaultCallback, onValueChanged: defaultCallback,
), ),
); ),
fail('Should not be possible to create a segmented control with just one child'); throwsA(isA<AssertionError>().having(
} on AssertionError catch (e) { (AssertionError error) => error.toString(),
expect(e.toString(), contains('children.length')); '.toString()',
} contains('children.length'),
)),
);
groupValue = -1; groupValue = -1;
try { await expectLater(
children[1] = const Text('Child 2'); () => tester.pumpWidget(
children[2] = const Text('Child 3');
await tester.pumpWidget(
CupertinoSlidingSegmentedControl<int>( CupertinoSlidingSegmentedControl<int>(
children: children, children: const <int, Widget>{
0: Text('Child 1'),
1: Text('Child 2'),
2: Text('Child 3'),
},
groupValue: groupValue, groupValue: groupValue,
onValueChanged: defaultCallback, onValueChanged: defaultCallback,
), ),
); ),
fail('Should not be possible to create a segmented control with a groupValue pointing to a non-existent child'); throwsA(isA<AssertionError>().having(
} on AssertionError catch (e) { (AssertionError error) => error.toString(),
expect(e.toString(), contains('groupValue must be either null or one of the keys in the children map')); '.toString()',
} contains('groupValue must be either null or one of the keys in the children map'),
)),
);
}); });
testWidgets('Padding works', (WidgetTester tester) async { testWidgets('Padding works', (WidgetTester tester) async {
......
...@@ -37,16 +37,14 @@ void main() { ...@@ -37,16 +37,14 @@ void main() {
}); });
test('returns failing future if action throws', () async { test('returns failing future if action throws', () async {
try { await expectLater(
await debugInstrumentAction<void>('throws', () async { () => debugInstrumentAction<void>('throws', () async {
await Future<void>.delayed(Duration.zero); await Future<void>.delayed(Duration.zero);
throw 'Error'; throw 'Error';
}); }),
fail('Error expected but not thrown'); throwsA('Error'),
} on String catch (error) { );
expect(error, 'Error'); expect(printBuffer.toString(), matches(r'^Action "throws" took .+'));
expect(printBuffer.toString(), matches(r'^Action "throws" took .+'));
}
}); });
}); });
} }
...@@ -576,8 +576,8 @@ void main() { ...@@ -576,8 +576,8 @@ void main() {
); );
}).toList(); }).toList();
try { await expectLater(
await tester.pumpWidget( () => tester.pumpWidget(
MaterialApp( MaterialApp(
home: Scaffold( home: Scaffold(
body: DropdownButtonFormField<String>( body: DropdownButtonFormField<String>(
...@@ -587,15 +587,13 @@ void main() { ...@@ -587,15 +587,13 @@ void main() {
), ),
), ),
), ),
); ),
throwsA(isA<AssertionError>().having(
fail('Should not be possible to have duplicate item value'); (AssertionError error) => error.toString(),
} on AssertionError catch (error) { '.toString()',
expect(
error.toString(),
contains("There should be exactly one item with [DropdownButton]'s value"), contains("There should be exactly one item with [DropdownButton]'s value"),
); )),
} );
}); });
testWidgets('DropdownButtonFormField value should only appear in one menu item', (WidgetTester tester) async { testWidgets('DropdownButtonFormField value should only appear in one menu item', (WidgetTester tester) async {
...@@ -607,8 +605,8 @@ void main() { ...@@ -607,8 +605,8 @@ void main() {
); );
}).toList(); }).toList();
try { await expectLater(
await tester.pumpWidget( () => tester.pumpWidget(
MaterialApp( MaterialApp(
home: Scaffold( home: Scaffold(
body: DropdownButton<String>( body: DropdownButton<String>(
...@@ -618,15 +616,13 @@ void main() { ...@@ -618,15 +616,13 @@ void main() {
), ),
), ),
), ),
); ),
throwsA(isA<AssertionError>().having(
fail('Should not be possible to have no items with passed in value'); (AssertionError error) => error.toString(),
} on AssertionError catch (error) { '.toString()',
expect(
error.toString(),
contains("There should be exactly one item with [DropdownButton]'s value"), contains("There should be exactly one item with [DropdownButton]'s value"),
); )),
} );
}); });
testWidgets('DropdownButtonFormField - selectedItemBuilder builds custom buttons', (WidgetTester tester) async { testWidgets('DropdownButtonFormField - selectedItemBuilder builds custom buttons', (WidgetTester tester) async {
......
...@@ -445,8 +445,8 @@ void main() { ...@@ -445,8 +445,8 @@ void main() {
); );
}).toList(); }).toList();
try { await expectLater(
await tester.pumpWidget( () => tester.pumpWidget(
MaterialApp( MaterialApp(
home: Scaffold( home: Scaffold(
body: DropdownButton<String>( body: DropdownButton<String>(
...@@ -456,15 +456,13 @@ void main() { ...@@ -456,15 +456,13 @@ void main() {
), ),
), ),
), ),
); ),
throwsA(isA<AssertionError>().having(
fail('Should not be possible to have duplicate item value'); (AssertionError error) => error.toString(),
} on AssertionError catch (error) { '.toString()',
expect(
error.toString(),
contains("There should be exactly one item with [DropdownButton]'s value"), contains("There should be exactly one item with [DropdownButton]'s value"),
); )),
} );
}); });
testWidgets('DropdownButton value should only appear in one menu item', (WidgetTester tester) async { testWidgets('DropdownButton value should only appear in one menu item', (WidgetTester tester) async {
...@@ -476,8 +474,8 @@ void main() { ...@@ -476,8 +474,8 @@ void main() {
); );
}).toList(); }).toList();
try { await expectLater(
await tester.pumpWidget( () => tester.pumpWidget(
MaterialApp( MaterialApp(
home: Scaffold( home: Scaffold(
body: DropdownButton<String>( body: DropdownButton<String>(
...@@ -487,15 +485,13 @@ void main() { ...@@ -487,15 +485,13 @@ void main() {
), ),
), ),
), ),
); ),
throwsA(isA<AssertionError>().having(
fail('Should not be possible to have no items with passed in value'); (AssertionError error) => error.toString(),
} on AssertionError catch (error) { '.toString()',
expect(
error.toString(),
contains("There should be exactly one item with [DropdownButton]'s value"), contains("There should be exactly one item with [DropdownButton]'s value"),
); )),
} );
}); });
testWidgets('Dropdown form field uses form field state', (WidgetTester tester) async { testWidgets('Dropdown form field uses form field state', (WidgetTester tester) async {
......
...@@ -171,8 +171,8 @@ void main() { ...@@ -171,8 +171,8 @@ void main() {
testWidgets( testWidgets(
'children and isSelected properties have to be the same length', 'children and isSelected properties have to be the same length',
(WidgetTester tester) async { (WidgetTester tester) async {
try { await expectLater(
await tester.pumpWidget( () => tester.pumpWidget(
Material( Material(
child: boilerplate( child: boilerplate(
child: ToggleButtons( child: ToggleButtons(
...@@ -184,15 +184,16 @@ void main() { ...@@ -184,15 +184,16 @@ void main() {
), ),
), ),
), ),
); ),
fail( throwsA(isA<AssertionError>().having(
'Should not be possible to create a toggle button with mismatching ' (AssertionError error) => error.toString(),
'children.length and isSelected.length.', '.toString()',
); allOf(
} on AssertionError catch (e) { contains('children.length'),
expect(e.toString(), contains('children.length')); contains('isSelected.length'),
expect(e.toString(), contains('isSelected.length')); ),
} )),
);
}, },
); );
......
...@@ -968,30 +968,41 @@ void main() { ...@@ -968,30 +968,41 @@ void main() {
); );
expect(isHit, isTrue); expect(isHit, isTrue);
expect(ran, isTrue); expect(ran, isTrue);
isHit = false;
ran = false; ran = false;
try { expect(
isHit = result.addWithOutOfBandPosition( () {
paintTransform: MatrixUtils.forceToPoint(Offset.zero), // cannot be inverted isHit = result.addWithOutOfBandPosition(
hitTest: (BoxHitTestResult result) { paintTransform: MatrixUtils.forceToPoint(Offset.zero), // cannot be inverted
fail('non-invertible transform should be caught'); hitTest: (BoxHitTestResult result) {
}, fail('non-invertible transform should be caught');
); },
fail('no exception thrown'); );
} on AssertionError catch (e) { },
expect(e.message, 'paintTransform must be invertible.'); throwsA(isA<AssertionError>().having(
} (AssertionError error) => error.message,
'message',
'paintTransform must be invertible.',
)),
);
expect(isHit, isFalse);
try { expect(
isHit = result.addWithOutOfBandPosition( () {
hitTest: (BoxHitTestResult result) { isHit = result.addWithOutOfBandPosition(
fail('addWithOutOfBandPosition should need some transformation of some sort'); hitTest: (BoxHitTestResult result) {
}, fail('addWithOutOfBandPosition should need some transformation of some sort');
); },
fail('no exception thrown'); );
} on AssertionError catch (e) { },
expect(e.message, 'Exactly one transform or offset argument must be provided.'); throwsA(isA<AssertionError>().having(
} (AssertionError error) => error.message,
'message',
'Exactly one transform or offset argument must be provided.',
)),
);
expect(isHit, isFalse);
}); });
test('error message', () { test('error message', () {
......
...@@ -181,19 +181,20 @@ void main() { ...@@ -181,19 +181,20 @@ void main() {
expect(child2.read<int>('foo'), isNull); // Value does not exist in this child. expect(child2.read<int>('foo'), isNull); // Value does not exist in this child.
// child1 is not given up before running finalizers. // child1 is not given up before running finalizers.
try { expect(
manager.doSerialization(); () => manager.doSerialization(),
fail('expected error'); throwsA(isA<FlutterError>().having(
} on FlutterError catch (e) { (FlutterError error) => error.message,
expect( 'message',
e.message, equals(
'Multiple owners claimed child RestorationBuckets with the same IDs.\n' 'Multiple owners claimed child RestorationBuckets with the same IDs.\n'
'The following IDs were claimed multiple times from the parent RestorationBucket(restorationId: root, owner: MockManager):\n' 'The following IDs were claimed multiple times from the parent RestorationBucket(restorationId: root, owner: MockManager):\n'
' * "child1" was claimed by:\n' ' * "child1" was claimed by:\n'
' * SecondClaim\n' ' * SecondClaim\n'
' * FirstClaim (current owner)', ' * FirstClaim (current owner)',
); ),
} )),
);
}); });
test('claim child that is already claimed does not throw if given up', () { test('claim child that is already claimed does not throw if given up', () {
......
...@@ -50,16 +50,18 @@ void main() { ...@@ -50,16 +50,18 @@ void main() {
group('construction check', () { group('construction check', () {
testWidgets('ListWheelScrollView needs positive diameter ratio', (WidgetTester tester) async { testWidgets('ListWheelScrollView needs positive diameter ratio', (WidgetTester tester) async {
try { expect(
ListWheelScrollView( () => ListWheelScrollView(
diameterRatio: nonconst(-2.0), diameterRatio: nonconst(-2.0),
itemExtent: 20.0, itemExtent: 20.0,
children: const <Widget>[], children: const <Widget>[],
); ),
fail('Expected failure with negative diameterRatio'); throwsA(isA<AssertionError>().having(
} on AssertionError catch (exception) { (AssertionError error) => error.message,
expect(exception.message, contains("You can't set a diameterRatio of 0")); 'message',
} contains("You can't set a diameterRatio of 0"),
)),
);
}); });
testWidgets('ListWheelScrollView can have zero child', (WidgetTester tester) async { testWidgets('ListWheelScrollView can have zero child', (WidgetTester tester) async {
......
...@@ -756,15 +756,14 @@ void main() { ...@@ -756,15 +756,14 @@ void main() {
testWidgets('PageView can restore page', (WidgetTester tester) async { testWidgets('PageView can restore page', (WidgetTester tester) async {
final PageController controller = PageController(); final PageController controller = PageController();
try { expect(
controller.page; () => controller.page,
fail('Accessing page before attaching should fail.'); throwsA(isA<AssertionError>().having(
} on AssertionError catch (e) { (AssertionError error) => error.message,
expect( 'message',
e.message, equals('PageController.page cannot be accessed before a PageView is built with it.'),
'PageController.page cannot be accessed before a PageView is built with it.', )),
); );
}
final PageStorageBucket bucket = PageStorageBucket(); final PageStorageBucket bucket = PageStorageBucket();
await tester.pumpWidget(Directionality( await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
...@@ -791,15 +790,14 @@ void main() { ...@@ -791,15 +790,14 @@ void main() {
child: Container(), child: Container(),
), ),
); );
try { expect(
controller.page; () => controller.page,
fail('Accessing page after detaching all PageViews should fail.'); throwsA(isA<AssertionError>().having(
} on AssertionError catch (e) { (AssertionError error) => error.message,
expect( 'message',
e.message, equals('PageController.page cannot be accessed before a PageView is built with it.'),
'PageController.page cannot be accessed before a PageView is built with it.', )),
); );
}
await tester.pumpWidget(Directionality( await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
child: PageStorage( child: PageStorage(
......
...@@ -531,13 +531,14 @@ void main() { ...@@ -531,13 +531,14 @@ void main() {
fakeClient.responses['waitFor'] = makeFakeResponse(<String, dynamic>{ fakeClient.responses['waitFor'] = makeFakeResponse(<String, dynamic>{
'message': 'This is a failure', 'message': 'This is a failure',
}, isError: true); }, isError: true);
try { await expectLater(
await driver.waitFor(find.byTooltip('foo')); () => driver.waitFor(find.byTooltip('foo')),
fail('expected an exception'); throwsA(isA<DriverError>().having(
} catch (error) { (DriverError error) => error.message,
expect(error, isA<DriverError>()); 'message',
expect((error as DriverError).message, 'Error in Flutter application: {message: This is a failure}'); 'Error in Flutter application: {message: This is a failure}',
} )),
);
}); });
test('uncaught remote error', () async { test('uncaught remote error', () async {
......
...@@ -819,12 +819,10 @@ class LoggerInterrupted implements Exception { ...@@ -819,12 +819,10 @@ class LoggerInterrupted implements Exception {
Future<void> expectLoggerInterruptEndsTask(Future<void> task, StreamLogger logger) async { Future<void> expectLoggerInterruptEndsTask(Future<void> task, StreamLogger logger) async {
logger.interrupt(); // an exception during the task should cause it to fail... logger.interrupt(); // an exception during the task should cause it to fail...
try { await expectLater(
await task; () => task,
expect(false, isTrue); // (shouldn't reach here) throwsA(isA<ToolExit>().having((ToolExit error) => error.exitCode, 'exitCode', 2)),
} on ToolExit catch (error) { );
expect(error.exitCode, 2); // ...with exit code 2.
}
} }
VMServiceConnector getFakeVmServiceFactory({ VMServiceConnector getFakeVmServiceFactory({
......
...@@ -23,12 +23,10 @@ void main() { ...@@ -23,12 +23,10 @@ void main() {
testUsingContext('fail with a bad device id', () async { testUsingContext('fail with a bad device id', () async {
final LogsCommand command = LogsCommand(); final LogsCommand command = LogsCommand();
try { await expectLater(
await createTestCommandRunner(command).run(<String>['-d', 'abc123', 'logs']); () => createTestCommandRunner(command).run(<String>['-d', 'abc123', 'logs']),
fail('Expect exception'); throwsA(isA<ToolExit>().having((ToolExit error) => error.exitCode, 'exitCode', anyOf(isNull, 1))),
} on ToolExit catch (e) { );
expect(e.exitCode ?? 1, 1);
}
}); });
}); });
} }
...@@ -51,12 +51,10 @@ void main() { ...@@ -51,12 +51,10 @@ void main() {
testUsingContext('fails when target not found', () async { testUsingContext('fails when target not found', () async {
final RunCommand command = RunCommand(); final RunCommand command = RunCommand();
try { expect(
await createTestCommandRunner(command).run(<String>['run', '-t', 'abc123', '--no-pub']); () => createTestCommandRunner(command).run(<String>['run', '-t', 'abc123', '--no-pub']),
fail('Expect exception'); throwsA(isA<ToolExit>().having((ToolExit error) => error.exitCode, 'exitCode', anyOf(isNull, 1))),
} on ToolExit catch (e) { );
expect(e.exitCode ?? 1, 1);
}
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
...@@ -69,18 +67,20 @@ void main() { ...@@ -69,18 +67,20 @@ void main() {
fileSystem.file('.packages').createSync(); fileSystem.file('.packages').createSync();
final RunCommand command = RunCommand(); final RunCommand command = RunCommand();
try { await expectLater(
await createTestCommandRunner(command).run(<String>[ () => createTestCommandRunner(command).run(<String>[
'run', 'run',
'--use-application-binary=app/bar/faz', '--use-application-binary=app/bar/faz',
'--fast-start', '--fast-start',
'--no-pub', '--no-pub',
'--show-test-device', '--show-test-device',
]); ]),
fail('Expect exception'); throwsA(isA<Exception>().having(
} on Exception catch (e) { (Exception exception) => exception.toString(),
expect(e.toString(), isNot(contains('--fast-start is not supported with --use-application-binary'))); 'toString',
} isNot(contains('--fast-start is not supported with --use-application-binary')),
)),
);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
...@@ -97,15 +97,13 @@ void main() { ...@@ -97,15 +97,13 @@ void main() {
..createSync(recursive: true); ..createSync(recursive: true);
final RunCommand command = RunCommand(); final RunCommand command = RunCommand();
try { await expectLater(
await createTestCommandRunner(command).run(<String>[ () => createTestCommandRunner(command).run(<String>[
'run', 'run',
'--no-pub', '--no-pub',
]); ]),
fail('Expect exception'); throwsA(isA<ToolExit>()),
} on Exception catch (e) { );
expect(e, isA<ToolExit>());
}
final BufferLogger bufferLogger = globals.logger as BufferLogger; final BufferLogger bufferLogger = globals.logger as BufferLogger;
expect( expect(
bufferLogger.statusText, bufferLogger.statusText,
...@@ -124,16 +122,17 @@ void main() { ...@@ -124,16 +122,17 @@ void main() {
.createSync(recursive: true); .createSync(recursive: true);
final RunCommand command = RunCommand(); final RunCommand command = RunCommand();
try { await expectLater(
await createTestCommandRunner(command).run(<String>[ () => createTestCommandRunner(command).run(<String>[
'run', 'run',
'--no-pub', '--no-pub',
]); ]),
fail('Expect exception'); throwsA(isA<ToolExit>().having(
} on Exception catch (e) { (ToolExit error) => error.toString(),
expect(e, isA<ToolExit>()); 'toString()',
expect(e.toString(), contains('No pubspec.yaml file found')); contains('No pubspec.yaml file found'),
} )),
);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
...@@ -180,16 +179,14 @@ void main() { ...@@ -180,16 +179,14 @@ void main() {
(Invocation invocation) => Future<List<Device>>.value(noDevices) (Invocation invocation) => Future<List<Device>>.value(noDevices)
); );
try { await expectLater(
await createTestCommandRunner(command).run(<String>[ () => createTestCommandRunner(command).run(<String>[
'run', 'run',
'--no-pub', '--no-pub',
'--no-hot', '--no-hot',
]); ]),
fail('Expect exception'); throwsA(isA<ToolExit>().having((ToolExit error) => error.message, 'message', isNull)),
} on ToolExit catch (e) { );
expect(e.message, null);
}
expect( expect(
testLogger.statusText, testLogger.statusText,
...@@ -256,16 +253,14 @@ void main() { ...@@ -256,16 +253,14 @@ void main() {
(Invocation invocation) => Future<List<Device>>.value(<Device>[]), (Invocation invocation) => Future<List<Device>>.value(<Device>[]),
); );
try { await expectLater(
await createTestCommandRunner(command).run(<String>[ () => createTestCommandRunner(command).run(<String>[
'run', 'run',
'--no-pub', '--no-pub',
'--no-hot', '--no-hot',
]); ]),
fail('Expect exception'); throwsA(isA<ToolExit>().having((ToolExit error) => error.message, 'message', isNull)),
} on ToolExit catch (e) { );
expect(e.message, null);
}
expect( expect(
testLogger.statusText, testLogger.statusText,
......
...@@ -61,15 +61,16 @@ void main() { ...@@ -61,15 +61,16 @@ void main() {
final ShellCompletionCommand command = ShellCompletionCommand(); final ShellCompletionCommand command = ShellCompletionCommand();
const String outputFile = 'bash-setup.sh'; const String outputFile = 'bash-setup.sh';
globals.fs.file(outputFile).createSync(); globals.fs.file(outputFile).createSync();
try { await expectLater(
await createTestCommandRunner(command).run( () => createTestCommandRunner(command).run(
<String>['bash-completion', outputFile], <String>['bash-completion', outputFile],
); ),
fail('Expect ToolExit exception'); throwsA(
} on ToolExit catch (error) { isA<ToolExit>()
expect(error.exitCode ?? 1, 1); .having((ToolExit error) => error.exitCode, 'exitCode', anyOf(isNull, 1))
expect(error.message, contains('Use --overwrite')); .having((ToolExit error) => error.message, 'message', contains('Use --overwrite')),
} ),
);
expect(globals.fs.isFileSync(outputFile), isTrue); expect(globals.fs.isFileSync(outputFile), isTrue);
expect(globals.fs.file(outputFile).readAsStringSync(), isEmpty); expect(globals.fs.file(outputFile).readAsStringSync(), isEmpty);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
......
...@@ -161,13 +161,18 @@ void main() { ...@@ -161,13 +161,18 @@ void main() {
double: () => context.get<int>()! * 1.0, double: () => context.get<int>()! * 1.0,
}, },
); );
try { expect(
await value; () => value,
fail('ContextDependencyCycleException expected but not thrown.'); throwsA(
} on ContextDependencyCycleException catch (e) { isA<ContextDependencyCycleException>()
expect(e.cycle, <Type>[String, double, int]); .having((ContextDependencyCycleException error) => error.cycle, 'cycle', <Type>[String, double, int])
expect(e.toString(), 'Dependency cycle detected: String -> double -> int'); .having(
} (ContextDependencyCycleException error) => error.toString(),
'toString()',
'Dependency cycle detected: String -> double -> int',
),
),
);
}); });
}); });
......
...@@ -211,13 +211,14 @@ void main() { ...@@ -211,13 +211,14 @@ void main() {
exitCode: 1, exitCode: 1,
stderr: stderr, stderr: stderr,
)); ));
try { expect(
processUtils.runSync(<String>['kaboom'], throwOnError: true); () => processUtils.runSync(<String>['kaboom'], throwOnError: true),
fail('ProcessException expected.'); throwsA(isA<ProcessException>().having(
} on ProcessException catch (e) { (ProcessException error) => error.message,
expect(e, isA<ProcessException>()); 'message',
expect(e.message.contains(stderr), false); isNot(contains(stderr)),
} )),
);
}); });
testWithoutContext('throws with stderr in exception on failure with verboseExceptions', () async { testWithoutContext('throws with stderr in exception on failure with verboseExceptions', () async {
......
...@@ -406,12 +406,10 @@ void main() { ...@@ -406,12 +406,10 @@ void main() {
botDetector: const BotDetectorAlwaysNo(), botDetector: const BotDetectorAlwaysNo(),
processManager: processManager, processManager: processManager,
); );
try { await expectLater(
await pub.get(context: PubContext.flutterTests); () => pub.get(context: PubContext.flutterTests),
throw AssertionError('pubGet did not fail'); throwsA(isA<ToolExit>().having((ToolExit error) => error.message, 'message', 'pub get failed (66; err3)')),
} on ToolExit catch (error) { );
expect(error.message, 'pub get failed (66; err3)');
}
expect(logger.statusText, expect(logger.statusText,
'Running "flutter pub get" in /...\n' 'Running "flutter pub get" in /...\n'
'out1\n' 'out1\n'
......
...@@ -174,13 +174,14 @@ void main() { ...@@ -174,13 +174,14 @@ void main() {
} }
Future<void> failToEvaluateExpression(FlutterTestDriver flutter) async { Future<void> failToEvaluateExpression(FlutterTestDriver flutter) async {
ObjRef res; await expectLater(
try { () => flutter.evaluateInFrame('"test"'),
res = await flutter.evaluateInFrame('"test"'); throwsA(isA<RPCError>().having(
} on RPCError catch (e) { (RPCError error) => error.message,
expect(e.message, contains('Expression evaluation is not supported for this configuration')); 'message',
} contains('Expression evaluation is not supported for this configuration'),
expect(res, null); )),
);
} }
Future<void> checkStaticScope(FlutterTestDriver flutter) async { Future<void> checkStaticScope(FlutterTestDriver flutter) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment