Skip to content

Commit a15b203

Browse files
committed
fix: catch all exceptions
1 parent 339bc8c commit a15b203

4 files changed

Lines changed: 39 additions & 38 deletions

File tree

lib/src/scenario_generator.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ void parseScenario(
1414
List<String> tags,
1515
String scenarioParams,
1616
) {
17-
sb.writeln(
18-
" $testMethodName('''$scenarioTitle''', ($testerName) async {",
19-
);
17+
sb.writeln(" $testMethodName('''$scenarioTitle''', ($testerName) async {");
2018
if (hasHooks) {
2119
sb.writeln(' var $testSuccessVariableName = true;');
2220
}
@@ -38,7 +36,7 @@ void parseScenario(
3836
}
3937

4038
if (hasHooks) {
41-
sb.writeln(' } on TestFailure {');
39+
sb.writeln(' } catch (_) {');
4240
sb.writeln(' $testSuccessVariableName = false;');
4341
sb.writeln(' rethrow;');
4442
}
@@ -67,9 +65,7 @@ void parseScenario(
6765
for (final param in scenarioParams.split(', ')) {
6866
sb.writeln(' $param,');
6967
}
70-
sb.writeln(
71-
' );',
72-
);
68+
sb.writeln(' );');
7369
}
7470
}
7571

@@ -86,9 +82,7 @@ List<List<BddLine>> generateScenariosFromScenarioOutline(
8682
.toList();
8783
}
8884

89-
List<Map<String, String>> _getExamples(
90-
List<BddLine> scenario,
91-
) {
85+
List<Map<String, String>> _getExamples(List<BddLine> scenario) {
9286
final exampleLines = scenario
9387
.skipWhile((l) => l.type != LineType.exampleTitle)
9488
.where((l) => l.type == LineType.examples)

test/feature_generator_test.dart

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ void main() {
2121
});
2222

2323
test('no customization', () async {
24-
const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n'
24+
const expected =
25+
'// GENERATED CODE - DO NOT MODIFY BY HAND\n'
2526
'// ignore_for_file: type=lint, type=warning\n'
2627
'\n'
2728
"import 'package:flutter/material.dart';\n"
@@ -43,8 +44,10 @@ void main() {
4344

4445
test('existing step should not regenerate', () async {
4546
const scenario = 'existing_step';
46-
final dummyStepPath =
47-
p.join(getStepFolderName(scenario), 'the_app_is_running.dart');
47+
final dummyStepPath = p.join(
48+
getStepFolderName(scenario),
49+
'the_app_is_running.dart',
50+
);
4851
const expectedFileContent = '// existing step';
4952
fs.file(dummyStepPath)
5053
..createSync(recursive: true)
@@ -66,16 +69,20 @@ relativeToTestFolder: false
6669
..writeAsStringSync(bddOptions);
6770

6871
const scenario = 'existing_step_outside_test_folder';
69-
final dummyStepPath =
70-
p.join(fs.currentDirectory.path, 'my_steps', 'the_app_is_running.dart');
72+
final dummyStepPath = p.join(
73+
fs.currentDirectory.path,
74+
'my_steps',
75+
'the_app_is_running.dart',
76+
);
7177
fs.file(dummyStepPath)
7278
..createSync(recursive: true)
7379
..writeAsStringSync('dummy');
7480

7581
// note: the import is so weird because p.relative() can not
7682
// find intersection between two paths (however, somehow it works)
7783
// not a problem in the real world
78-
const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n'
84+
const expected =
85+
'// GENERATED CODE - DO NOT MODIFY BY HAND\n'
7986
'// ignore_for_file: type=lint, type=warning\n'
8087
'\n'
8188
"import 'package:flutter/material.dart';\n"
@@ -107,7 +114,8 @@ hookFolderName: hooksFolder
107114
..createSync()
108115
..writeAsStringSync(bddOptions);
109116

110-
const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n'
117+
const expected =
118+
'// GENERATED CODE - DO NOT MODIFY BY HAND\n'
111119
'// ignore_for_file: type=lint, type=warning\n'
112120
'\n'
113121
"import 'package:flutter/material.dart';\n"
@@ -139,7 +147,7 @@ hookFolderName: hooksFolder
139147
' try {\n'
140148
" await beforeEach('''Testing scenario''');\n"
141149
' await theAppIsRunning(tester);\n'
142-
' } on TestFailure {\n'
150+
' } catch (_) {\n'
143151
' success = false;\n'
144152
' rethrow;\n'
145153
' } finally {\n'
@@ -164,10 +172,7 @@ hookFolderName: hooksFolder
164172
..writeAsStringSync(bddOptions);
165173

166174
const scenario = 'options';
167-
expect(
168-
() => generate(scenario),
169-
throwsException,
170-
);
175+
expect(() => generate(scenario), throwsException);
171176
});
172177

173178
test('merge options', () async {
@@ -187,7 +192,8 @@ testMethodName: customName
187192
stepFolderName: ./scenarios
188193
''');
189194

190-
const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n'
195+
const expected =
196+
'// GENERATED CODE - DO NOT MODIFY BY HAND\n'
191197
'// ignore_for_file: type=lint, type=warning\n'
192198
'\n'
193199
"import 'package:flutter/material.dart';\n"
@@ -241,7 +247,8 @@ include: $externalYaml3
241247
stepFolderName: ./scenarios
242248
''');
243249

244-
const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n'
250+
const expected =
251+
'// GENERATED CODE - DO NOT MODIFY BY HAND\n'
245252
'// ignore_for_file: type=lint, type=warning\n'
246253
'\n'
247254
"import 'package:flutter/material.dart';\n"
@@ -260,9 +267,7 @@ stepFolderName: ./scenarios
260267
const scenario = 'options';
261268
final content = await generate(
262269
scenario,
263-
const BuilderOptions(<String, dynamic>{
264-
'include': externalYaml3,
265-
}),
270+
const BuilderOptions(<String, dynamic>{'include': externalYaml3}),
266271
);
267272
expect(content, expected);
268273
});
@@ -276,7 +281,8 @@ dev_dependencies:
276281
sdk: flutter
277282
''');
278283

279-
const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n'
284+
const expected =
285+
'// GENERATED CODE - DO NOT MODIFY BY HAND\n'
280286
'// ignore_for_file: type=lint, type=warning\n'
281287
'\n'
282288
"import 'package:flutter/material.dart';\n"
@@ -307,7 +313,8 @@ dev_dependencies:
307313
dev_dependencies:
308314
''');
309315

310-
const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n'
316+
const expected =
317+
'// GENERATED CODE - DO NOT MODIFY BY HAND\n'
311318
'// ignore_for_file: type=lint, type=warning\n'
312319
'\n'
313320
"import 'package:flutter/material.dart';\n"
@@ -356,9 +363,9 @@ Future<String> generate(
356363
}
357364

358365
String getStepFolderName(String scenario) => p.joinAll([
359-
fs.currentDirectory.path,
360-
'test',
361-
'builder_scenarios',
362-
scenario,
363-
'step',
364-
]);
366+
fs.currentDirectory.path,
367+
'test',
368+
'builder_scenarios',
369+
scenario,
370+
'step',
371+
]);

test/feature_with_hooks_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void main() {
3636
try {
3737
await beforeEach(\'\'\'Testing scenario\'\'\' );
3838
await theAppIsRunning(tester);
39-
} on TestFailure {
39+
} catch (_) {
4040
success = false;
4141
rethrow;
4242
} finally {

test/full_set_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void main() {
6767
await theAppIsRunning(tester);
6868
await iRunCode(tester, 'func foo() {}; func bar() { print("hey!"); };');
6969
await iSeeText(tester, '0');
70-
} on TestFailure {
70+
} catch (_) {
7171
success = false;
7272
rethrow;
7373
} finally {
@@ -96,7 +96,7 @@ void main() {
9696
await beforeEach(\'\'\'Initial counter value is 0\'\'\' );
9797
await bddSetUp(tester);
9898
await theAppIsRunning(tester);
99-
} on TestFailure {
99+
} catch (_) {
100100
success = false;
101101
rethrow;
102102
} finally {

0 commit comments

Comments
 (0)