From a15b203d824aeeb5db2af85862cdb82f2047bbfe Mon Sep 17 00:00:00 2001 From: Chantawat Yangtrong Date: Wed, 6 Aug 2025 13:52:42 +0700 Subject: [PATCH 1/2] fix: catch all exceptions --- lib/src/scenario_generator.dart | 14 +++----- test/feature_generator_test.dart | 57 +++++++++++++++++-------------- test/feature_with_hooks_test.dart | 2 +- test/full_set_test.dart | 4 +-- 4 files changed, 39 insertions(+), 38 deletions(-) diff --git a/lib/src/scenario_generator.dart b/lib/src/scenario_generator.dart index e8ee957..c111b17 100644 --- a/lib/src/scenario_generator.dart +++ b/lib/src/scenario_generator.dart @@ -14,9 +14,7 @@ void parseScenario( List tags, String scenarioParams, ) { - sb.writeln( - " $testMethodName('''$scenarioTitle''', ($testerName) async {", - ); + sb.writeln(" $testMethodName('''$scenarioTitle''', ($testerName) async {"); if (hasHooks) { sb.writeln(' var $testSuccessVariableName = true;'); } @@ -38,7 +36,7 @@ void parseScenario( } if (hasHooks) { - sb.writeln(' } on TestFailure {'); + sb.writeln(' } catch (_) {'); sb.writeln(' $testSuccessVariableName = false;'); sb.writeln(' rethrow;'); } @@ -67,9 +65,7 @@ void parseScenario( for (final param in scenarioParams.split(', ')) { sb.writeln(' $param,'); } - sb.writeln( - ' );', - ); + sb.writeln(' );'); } } @@ -86,9 +82,7 @@ List> generateScenariosFromScenarioOutline( .toList(); } -List> _getExamples( - List scenario, -) { +List> _getExamples(List scenario) { final exampleLines = scenario .skipWhile((l) => l.type != LineType.exampleTitle) .where((l) => l.type == LineType.examples) diff --git a/test/feature_generator_test.dart b/test/feature_generator_test.dart index 6ea7c92..1d3eac1 100644 --- a/test/feature_generator_test.dart +++ b/test/feature_generator_test.dart @@ -21,7 +21,8 @@ void main() { }); test('no customization', () async { - const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = + '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -43,8 +44,10 @@ void main() { test('existing step should not regenerate', () async { const scenario = 'existing_step'; - final dummyStepPath = - p.join(getStepFolderName(scenario), 'the_app_is_running.dart'); + final dummyStepPath = p.join( + getStepFolderName(scenario), + 'the_app_is_running.dart', + ); const expectedFileContent = '// existing step'; fs.file(dummyStepPath) ..createSync(recursive: true) @@ -66,8 +69,11 @@ relativeToTestFolder: false ..writeAsStringSync(bddOptions); const scenario = 'existing_step_outside_test_folder'; - final dummyStepPath = - p.join(fs.currentDirectory.path, 'my_steps', 'the_app_is_running.dart'); + final dummyStepPath = p.join( + fs.currentDirectory.path, + 'my_steps', + 'the_app_is_running.dart', + ); fs.file(dummyStepPath) ..createSync(recursive: true) ..writeAsStringSync('dummy'); @@ -75,7 +81,8 @@ relativeToTestFolder: false // note: the import is so weird because p.relative() can not // find intersection between two paths (however, somehow it works) // not a problem in the real world - const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = + '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -107,7 +114,8 @@ hookFolderName: hooksFolder ..createSync() ..writeAsStringSync(bddOptions); - const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = + '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -139,7 +147,7 @@ hookFolderName: hooksFolder ' try {\n' " await beforeEach('''Testing scenario''');\n" ' await theAppIsRunning(tester);\n' - ' } on TestFailure {\n' + ' } catch (_) {\n' ' success = false;\n' ' rethrow;\n' ' } finally {\n' @@ -164,10 +172,7 @@ hookFolderName: hooksFolder ..writeAsStringSync(bddOptions); const scenario = 'options'; - expect( - () => generate(scenario), - throwsException, - ); + expect(() => generate(scenario), throwsException); }); test('merge options', () async { @@ -187,7 +192,8 @@ testMethodName: customName stepFolderName: ./scenarios '''); - const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = + '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -241,7 +247,8 @@ include: $externalYaml3 stepFolderName: ./scenarios '''); - const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = + '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -260,9 +267,7 @@ stepFolderName: ./scenarios const scenario = 'options'; final content = await generate( scenario, - const BuilderOptions({ - 'include': externalYaml3, - }), + const BuilderOptions({'include': externalYaml3}), ); expect(content, expected); }); @@ -276,7 +281,8 @@ dev_dependencies: sdk: flutter '''); - const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = + '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -307,7 +313,8 @@ dev_dependencies: dev_dependencies: '''); - const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = + '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -356,9 +363,9 @@ Future generate( } String getStepFolderName(String scenario) => p.joinAll([ - fs.currentDirectory.path, - 'test', - 'builder_scenarios', - scenario, - 'step', - ]); + fs.currentDirectory.path, + 'test', + 'builder_scenarios', + scenario, + 'step', +]); diff --git a/test/feature_with_hooks_test.dart b/test/feature_with_hooks_test.dart index bb8491e..2b76b5e 100644 --- a/test/feature_with_hooks_test.dart +++ b/test/feature_with_hooks_test.dart @@ -36,7 +36,7 @@ void main() { try { await beforeEach(\'\'\'Testing scenario\'\'\' ); await theAppIsRunning(tester); - } on TestFailure { + } catch (_) { success = false; rethrow; } finally { diff --git a/test/full_set_test.dart b/test/full_set_test.dart index a5d12ec..d052f5b 100644 --- a/test/full_set_test.dart +++ b/test/full_set_test.dart @@ -67,7 +67,7 @@ void main() { await theAppIsRunning(tester); await iRunCode(tester, 'func foo() {}; func bar() { print("hey!"); };'); await iSeeText(tester, '0'); - } on TestFailure { + } catch (_) { success = false; rethrow; } finally { @@ -96,7 +96,7 @@ void main() { await beforeEach(\'\'\'Initial counter value is 0\'\'\' ); await bddSetUp(tester); await theAppIsRunning(tester); - } on TestFailure { + } catch (_) { success = false; rethrow; } finally { From 77dc85f17d2c6eadc521ce437cda647ab0229ef2 Mon Sep 17 00:00:00 2001 From: Chantawat Yangtrong Date: Wed, 6 Aug 2025 14:20:54 +0700 Subject: [PATCH 2/2] fix: format --- test/feature_generator_test.dart | 33 +++++++++++++------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/test/feature_generator_test.dart b/test/feature_generator_test.dart index 1d3eac1..14b6d86 100644 --- a/test/feature_generator_test.dart +++ b/test/feature_generator_test.dart @@ -21,8 +21,7 @@ void main() { }); test('no customization', () async { - const expected = - '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -81,8 +80,7 @@ relativeToTestFolder: false // note: the import is so weird because p.relative() can not // find intersection between two paths (however, somehow it works) // not a problem in the real world - const expected = - '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -114,8 +112,7 @@ hookFolderName: hooksFolder ..createSync() ..writeAsStringSync(bddOptions); - const expected = - '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -192,8 +189,7 @@ testMethodName: customName stepFolderName: ./scenarios '''); - const expected = - '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -247,8 +243,7 @@ include: $externalYaml3 stepFolderName: ./scenarios '''); - const expected = - '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -281,8 +276,7 @@ dev_dependencies: sdk: flutter '''); - const expected = - '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -313,8 +307,7 @@ dev_dependencies: dev_dependencies: '''); - const expected = - '// GENERATED CODE - DO NOT MODIFY BY HAND\n' + const expected = '// GENERATED CODE - DO NOT MODIFY BY HAND\n' '// ignore_for_file: type=lint, type=warning\n' '\n' "import 'package:flutter/material.dart';\n" @@ -363,9 +356,9 @@ Future generate( } String getStepFolderName(String scenario) => p.joinAll([ - fs.currentDirectory.path, - 'test', - 'builder_scenarios', - scenario, - 'step', -]); + fs.currentDirectory.path, + 'test', + 'builder_scenarios', + scenario, + 'step', + ]);