Skip to content

Commit fa8c943

Browse files
authored
Merge pull request #2 from softnetics/fix/test-failure
fix: catch all exceptions
2 parents 339bc8c + 77dc85f commit fa8c943

4 files changed

Lines changed: 19 additions & 25 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: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ void main() {
4343

4444
test('existing step should not regenerate', () async {
4545
const scenario = 'existing_step';
46-
final dummyStepPath =
47-
p.join(getStepFolderName(scenario), 'the_app_is_running.dart');
46+
final dummyStepPath = p.join(
47+
getStepFolderName(scenario),
48+
'the_app_is_running.dart',
49+
);
4850
const expectedFileContent = '// existing step';
4951
fs.file(dummyStepPath)
5052
..createSync(recursive: true)
@@ -66,8 +68,11 @@ relativeToTestFolder: false
6668
..writeAsStringSync(bddOptions);
6769

6870
const scenario = 'existing_step_outside_test_folder';
69-
final dummyStepPath =
70-
p.join(fs.currentDirectory.path, 'my_steps', 'the_app_is_running.dart');
71+
final dummyStepPath = p.join(
72+
fs.currentDirectory.path,
73+
'my_steps',
74+
'the_app_is_running.dart',
75+
);
7176
fs.file(dummyStepPath)
7277
..createSync(recursive: true)
7378
..writeAsStringSync('dummy');
@@ -139,7 +144,7 @@ hookFolderName: hooksFolder
139144
' try {\n'
140145
" await beforeEach('''Testing scenario''');\n"
141146
' await theAppIsRunning(tester);\n'
142-
' } on TestFailure {\n'
147+
' } catch (_) {\n'
143148
' success = false;\n'
144149
' rethrow;\n'
145150
' } finally {\n'
@@ -164,10 +169,7 @@ hookFolderName: hooksFolder
164169
..writeAsStringSync(bddOptions);
165170

166171
const scenario = 'options';
167-
expect(
168-
() => generate(scenario),
169-
throwsException,
170-
);
172+
expect(() => generate(scenario), throwsException);
171173
});
172174

173175
test('merge options', () async {
@@ -260,9 +262,7 @@ stepFolderName: ./scenarios
260262
const scenario = 'options';
261263
final content = await generate(
262264
scenario,
263-
const BuilderOptions(<String, dynamic>{
264-
'include': externalYaml3,
265-
}),
265+
const BuilderOptions(<String, dynamic>{'include': externalYaml3}),
266266
);
267267
expect(content, expected);
268268
});

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)