From 2aa36b5aa1d8c5d3b34ed6d4be14842bdcc30775 Mon Sep 17 00:00:00 2001 From: Jon Samwell Date: Wed, 6 Feb 2019 13:25:19 +1100 Subject: [PATCH] chore(linting): update code to pass stricter linting rules --- CHANGELOG.md | 5 + analysis_options.yaml | 85 ++++++++ example/lib/main.dart | 16 +- example/test_driver/app.dart | 4 +- example/test_driver/hooks/hook_example.dart | 13 +- lib/src/expect/expect_mimic.dart | 4 +- lib/src/expect/expect_mimic_utils.dart | 10 +- lib/src/feature_file_runner.dart | 14 +- .../flutter/flutter_run_process_handler.dart | 4 +- .../flutter/flutter_test_configuration.dart | 4 +- lib/src/flutter/flutter_world.dart | 2 +- lib/src/flutter/hooks/app_runner_hook.dart | 7 +- .../steps/given_i_open_the_drawer_step.dart | 2 +- lib/src/flutter/steps/when_pause_step.dart | 3 +- .../parameter_count_mismatch_error.dart | 6 +- .../expressions/gherkin_expression.dart | 8 +- .../gherkin/expressions/tag_expression.dart | 10 +- lib/src/gherkin/parser.dart | 2 +- .../gherkin/runnables/debug_information.dart | 2 +- lib/src/gherkin/runnables/feature.dart | 10 +- lib/src/gherkin/runnables/feature_file.dart | 4 +- .../gherkin/runnables/multi_line_string.dart | 7 +- lib/src/gherkin/runnables/scenario.dart | 6 +- lib/src/gherkin/runnables/step.dart | 6 +- lib/src/gherkin/runnables/table.dart | 6 +- lib/src/gherkin/steps/step_definition.dart | 4 +- .../step_definition_implementations.dart | 6 + lib/src/gherkin/syntax/background_syntax.dart | 3 +- lib/src/gherkin/syntax/comment_syntax.dart | 1 + lib/src/gherkin/syntax/empty_line_syntax.dart | 1 + lib/src/gherkin/syntax/feature_syntax.dart | 3 +- lib/src/gherkin/syntax/language_syntax.dart | 3 +- .../syntax/multiline_string_syntax.dart | 11 +- lib/src/gherkin/syntax/scenario_syntax.dart | 3 +- lib/src/gherkin/syntax/step_syntax.dart | 3 +- lib/src/gherkin/syntax/table_line_syntax.dart | 3 +- lib/src/gherkin/syntax/tag_syntax.dart | 3 +- lib/src/gherkin/syntax/text_line_syntax.dart | 3 +- lib/src/hooks/aggregated_hook.dart | 7 +- lib/src/reporters/aggregated_reporter.dart | 4 +- lib/src/reporters/progress_reporter.dart | 1 + lib/src/reporters/stdout_reporter.dart | 1 + .../reporters/test_run_summary_reporter.dart | 16 +- lib/src/test_runner.dart | 42 ++-- lib/src/utils/perf.dart | 2 +- pubspec.lock | 7 + pubspec.yaml | 3 +- test/feature_file_runner_test.dart | 185 ++++++++---------- .../expressions/gherkin_expression.dart | 18 +- test/gherkin/expressions/tag_expression.dart | 8 +- test/gherkin/parser_test.dart | 8 +- test/gherkin/runnables/feature_file_test.dart | 4 +- test/gherkin/runnables/feature_test.dart | 12 +- .../runnables/multi_line_string_test.dart | 4 +- test/gherkin/runnables/scenario_test.dart | 6 +- test/gherkin/runnables/step_test.dart | 6 +- test/gherkin/runnables/table_test.dart | 12 +- test/gherkin/steps/step_definition_test.dart | 16 +- .../syntax/background_syntax_test.dart | 8 +- test/gherkin/syntax/comment_syntax_test.dart | 4 +- .../syntax/empty_line_syntax_test.dart | 4 +- test/gherkin/syntax/feature_syntax_test.dart | 8 +- test/gherkin/syntax/language_syntax_test.dart | 8 +- .../syntax/multiline_string_syntax_test.dart | 22 +-- test/gherkin/syntax/scenario_syntax_test.dart | 8 +- test/gherkin/syntax/step_syntax_test.dart | 30 +-- .../syntax/table_line_string_syntax_test.dart | 40 ++-- test/gherkin/syntax/tag_syntax_test.dart | 8 +- .../gherkin/syntax/text_line_syntax_test.dart | 8 +- test/hooks/aggregated_hook_test.dart | 2 +- test/mocks/gherkin_expression_mock.dart | 2 +- test/mocks/hook_mock.dart | 5 + test/mocks/reporter_mock.dart | 11 ++ test/mocks/step_definition_mock.dart | 1 + test/reporters/progress_reporter_test.dart | 5 +- .../test_run_summary_reporter_test.dart | 2 +- 76 files changed, 482 insertions(+), 343 deletions(-) create mode 100644 analysis_options.yaml diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a0f634..c4852e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [0.0.11] - 06/02/2019 + +* Fixes issue with table parameters not being given to step +* Added news hook that is called after the world for a scenario is created + ## [0.0.10] - 01/11/2018 * Ensured summary reporter reports failure reason diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..4aae589 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,85 @@ +# Defines a default set of lint rules enforced for +# projects at Google. For details and rationale, +# see https://github.com/dart-lang/pedantic#enabled-lints. +include: package:pedantic/analysis_options.yaml + +analyzer: + errors: + # treat missing required parameters as a warning (not a hint) + missing_required_param: warning + # treat missing returns as a warning (not a hint) + missing_return: warning + # allow having TODOs in the code + todo: ignore + exclude: + # - path/to/excluded/files/** + +# For lint rules and documentation, see http://dart-lang.github.io/linter/lints. +linter: + rules: + # these rules are documented on and in the same order as + # the Dart Lint rules page to make maintenance easier + # http://dart-lang.github.io/linter/lints/ + + # === error rules === + - avoid_empty_else + - avoid_slow_async_io + - cancel_subscriptions + - close_sinks + - control_flow_in_finally + - empty_statements + - hash_and_equals + - iterable_contains_unrelated_type + - list_remove_unrelated_type + - no_adjacent_strings_in_list + - no_duplicate_case_values + - test_types_in_equals + - throw_in_finally + - unrelated_type_equality_checks + - valid_regexps + + # === style rules === + - always_declare_return_types + - always_require_non_null_named_parameters + # - always_specify_types + - annotate_overrides + # - avoid_as + - avoid_init_to_null + - avoid_null_checks_in_equality_operators + - avoid_return_types_on_setters + - await_only_futures + - camel_case_types + # - directives_ordering + # - empty_catches + - empty_constructor_bodies + - implementation_imports + - library_names + - library_prefixes + - non_constant_identifier_names + - overridden_fields + - package_api_docs + - package_prefixed_library_names + - prefer_adjacent_string_concatenation + - prefer_collection_literals + - prefer_const_constructors + - prefer_contains + - prefer_equal_for_default_values + - prefer_final_locals + - prefer_initializing_formals + - prefer_is_empty + - prefer_is_not_empty + - prefer_void_to_null + - slash_for_doc_comments + # - sort_constructors_first + - sort_unnamed_constructors_first + - super_goes_last + - type_init_formals + - unnecessary_brace_in_string_interps + - unnecessary_const + - unnecessary_getters_setters + - unnecessary_new + - unnecessary_null_aware_assignments + - unnecessary_null_in_if_null_operators + - unnecessary_statements + - unnecessary_this + - use_rethrow_when_possible \ No newline at end of file diff --git a/example/lib/main.dart b/example/lib/main.dart index 8381ea6..ccf3055 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -37,18 +37,18 @@ class _MyHomePageState extends State { title: Text(widget.title), ), drawer: Drawer( - key: Key("drawer"), + key: const Key("drawer"), child: ListView( padding: EdgeInsets.zero, children: [ DrawerHeader( - child: Text('Drawer Header'), + child: const Text('Drawer Header'), decoration: BoxDecoration( color: Colors.blue, ), ), ListTile( - title: Text('Item 1'), + title: const Text('Item 1'), onTap: () { // Update the state of the app // ... @@ -57,7 +57,7 @@ class _MyHomePageState extends State { }, ), ListTile( - title: Text('Item 2'), + title: const Text('Item 2'), onTap: () { // Update the state of the app // ... @@ -72,7 +72,7 @@ class _MyHomePageState extends State { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text( + const Text( 'You have pushed the button this many times:', ), Text( @@ -80,7 +80,7 @@ class _MyHomePageState extends State { // Provide a Key to this specific Text Widget. This allows us // to identify this specific Widget from inside our test suite and // read the text. - key: Key('counter'), + key: const Key('counter'), style: Theme.of(context).textTheme.display1, ), ], @@ -89,10 +89,10 @@ class _MyHomePageState extends State { floatingActionButton: FloatingActionButton( // Provide a Key to this the button. This allows us to find this // specific button and tap it inside the test suite. - key: Key('increment'), + key: const Key('increment'), onPressed: _incrementCounter, tooltip: 'Increment', - child: Icon(Icons.add), + child: const Icon(Icons.add), ), ); } diff --git a/example/test_driver/app.dart b/example/test_driver/app.dart index a5366b9..7ccaae7 100644 --- a/example/test_driver/app.dart +++ b/example/test_driver/app.dart @@ -1,4 +1,4 @@ -import '../lib/main.dart'; +import 'package:example/main.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_driver/driver_extension.dart'; @@ -8,5 +8,5 @@ void main() { // Call the `main()` function of your app or call `runApp` with any widget you // are interested in testing. - runApp(new MyApp()); + runApp(MyApp()); } diff --git a/example/test_driver/hooks/hook_example.dart b/example/test_driver/hooks/hook_example.dart index bde51eb..b0b8995 100644 --- a/example/test_driver/hooks/hook_example.dart +++ b/example/test_driver/hooks/hook_example.dart @@ -3,33 +3,30 @@ import 'package:flutter_gherkin/flutter_gherkin.dart'; class HookExample extends Hook { /// The priority to assign to this hook. /// Higher priority gets run first so a priority of 10 is run before a priority of 2 + @override int get priority => 1; - @override - /// Run before any scenario in a test run have executed + @override Future onBeforeRun(TestConfiguration config) async { print("before run hook"); } - @override - /// Run after all scenarios in a test run have completed + @override Future onAfterRun(TestConfiguration config) async { print("after run hook"); } - @override - /// Run before a scenario and it steps are executed + @override Future onBeforeScenario( TestConfiguration config, String scenario) async { print("running hook before scenario '$scenario'"); } - @override - /// Run after a scenario has executed + @override Future onAfterScenario( TestConfiguration config, String scenario) async { print("running hook after scenario '$scenario'"); diff --git a/lib/src/expect/expect_mimic.dart b/lib/src/expect/expect_mimic.dart index a7f6a65..1783e8b 100644 --- a/lib/src/expect/expect_mimic.dart +++ b/lib/src/expect/expect_mimic.dart @@ -42,11 +42,11 @@ class ExpectMimic { /// you want to wait for the matcher to complete before continuing the test, you /// can call [expectLater] instead and `await` the result. void expect(actualValue, matcher, {String reason}) { - var matchState = {}; + final matchState = {}; matcher = wrapMatcher(matcher); final result = matcher.matches(actualValue, matchState); final formatter = (actual, matcher, reason, matchState, verbose) { - var mismatchDescription = new StringDescription(); + final mismatchDescription = StringDescription(); matcher.describeMismatch( actual, mismatchDescription, matchState, verbose); diff --git a/lib/src/expect/expect_mimic_utils.dart b/lib/src/expect/expect_mimic_utils.dart index 3736493..e900aa9 100644 --- a/lib/src/expect/expect_mimic_utils.dart +++ b/lib/src/expect/expect_mimic_utils.dart @@ -5,10 +5,10 @@ import 'package:matcher/matcher.dart'; /// The matcher package doesn't expose its pretty-print function directly, but /// we can use it through StringDescription. String prettyPrint(value) => - new StringDescription().addDescriptionOf(value).toString(); + StringDescription().addDescriptionOf(value).toString(); String formatFailure(Matcher expected, actual, String which, {String reason}) { - var buffer = new StringBuffer(); + final buffer = StringBuffer(); buffer.writeln(indent(prettyPrint(expected), first: 'Expected: ')); buffer.writeln(indent(prettyPrint(actual), first: ' Actual: ')); if (which.isNotEmpty) buffer.writeln(indent(which, first: ' Which: ')); @@ -37,13 +37,13 @@ String prefixLines(String text, String prefix, last ??= prefix; single ??= first ?? last ?? prefix; - var lines = text.split('\n'); + final lines = text.split('\n'); if (lines.length == 1) return "$single$text"; - var buffer = new StringBuffer("$first${lines.first}\n"); + final buffer = StringBuffer("$first${lines.first}\n"); // Write out all but the first and last lines with [prefix]. - for (var line in lines.skip(1).take(lines.length - 2)) { + for (final line in lines.skip(1).take(lines.length - 2)) { buffer.writeln("$prefix$line"); } buffer.write("$last${lines.last}"); diff --git a/lib/src/feature_file_runner.dart b/lib/src/feature_file_runner.dart index bec8f2d..6413e2a 100644 --- a/lib/src/feature_file_runner.dart +++ b/lib/src/feature_file_runner.dart @@ -85,7 +85,7 @@ class FeatureFileRunner { await _hook.onAfterScenarioWorldCreated(world, scenario.name); } - _reporter.onScenarioStarted( + await _reporter.onScenarioStarted( StartedMessage(Target.scenario, scenario.name, scenario.debug)); if (background != null) { await _log("Running background steps for scenerio '${scenario.name}'", @@ -95,7 +95,7 @@ class FeatureFileRunner { scenarioPassed = result.result == StepExecutionResult.pass; if (!_canContinueScenario(result)) { scenarioPassed = false; - _log( + await _log( "Background step '${step.name}' did not pass, all remaining steps will be skiped", step.debug, MessageLevel.warning); @@ -108,7 +108,7 @@ class FeatureFileRunner { scenarioPassed = result.result == StepExecutionResult.pass; if (!_canContinueScenario(result)) { scenarioPassed = false; - _log( + await _log( "Step '${step.name}' did not pass, all remaining steps will be skiped", step.debug, MessageLevel.warning); @@ -130,8 +130,8 @@ class FeatureFileRunner { Future _runStep( StepRunnable step, World world, bool skipExecution) async { StepResult result; - ExectuableStep code = _matchStepToExectuableStep(step); - Iterable parameters = _getStepParameters(step, code); + final ExectuableStep code = _matchStepToExectuableStep(step); + final Iterable parameters = _getStepParameters(step, code); await _log( "Attempting to run step '${step.name}'", step.debug, MessageLevel.info); @@ -206,7 +206,7 @@ class FeatureFileRunner { } """; _reporter.message(message, MessageLevel.error); - throw new GherkinStepNotDefinedException(message); + throw GherkinStepNotDefinedException(message); } return executable; @@ -215,7 +215,7 @@ class FeatureFileRunner { Iterable _getStepParameters(StepRunnable step, ExectuableStep code) { Iterable parameters = code.expression.getParameters(step.debug.lineText); - if (step.multilineStrings.length > 0) { + if (step.multilineStrings.isNotEmpty) { parameters = parameters.toList()..addAll(step.multilineStrings); } diff --git a/lib/src/flutter/flutter_run_process_handler.dart b/lib/src/flutter/flutter_run_process_handler.dart index ba8445e..7bbdc0f 100644 --- a/lib/src/flutter/flutter_run_process_handler.dart +++ b/lib/src/flutter/flutter_run_process_handler.dart @@ -16,7 +16,7 @@ class FlutterRunProcessHandler extends ProcessHandler { RegExp(r"no connected device", caseSensitive: false, multiLine: false); Process _runningProcess; Stream _processStdoutStream; - List _openSubscriptions = List(); + List _openSubscriptions = []; String _appTarget; String _workingDirectory; @@ -86,7 +86,7 @@ class FlutterRunProcessHandler extends ProcessHandler { void _ensureRunningProcess() { if (_runningProcess == null) { - throw new Exception( + throw Exception( "FlutterRunProcessHandler: flutter run process is not active"); } } diff --git a/lib/src/flutter/flutter_test_configuration.dart b/lib/src/flutter/flutter_test_configuration.dart index 2fb716d..0f68cc1 100644 --- a/lib/src/flutter/flutter_test_configuration.dart +++ b/lib/src/flutter/flutter_test_configuration.dart @@ -28,7 +28,7 @@ class FlutterTestConfiguration extends TestConfiguration { Platform.environment['VM_SERVICE_URL']; final driver = await FlutterDriver.connect( dartVmServiceUrl: dartVmServiceUrl, - isolateReadyTimeout: Duration(seconds: 30), + isolateReadyTimeout: const Duration(seconds: 30), logCommunicationToFile: false, printCommunication: false); return driver; @@ -36,7 +36,7 @@ class FlutterTestConfiguration extends TestConfiguration { Future createFlutterWorld( TestConfiguration config, FlutterWorld world) async { - world = world ?? new FlutterWorld(); + world = world ?? FlutterWorld(); final driver = await createFlutterDriver(); world.setFlutterDriver(driver); return world; diff --git a/lib/src/flutter/flutter_world.dart b/lib/src/flutter/flutter_world.dart index 7211dee..5173d2b 100644 --- a/lib/src/flutter/flutter_world.dart +++ b/lib/src/flutter/flutter_world.dart @@ -6,7 +6,7 @@ class FlutterWorld extends World { FlutterDriver get driver => _driver; - setFlutterDriver(FlutterDriver flutterDriver) { + void setFlutterDriver(FlutterDriver flutterDriver) { _driver = flutterDriver; } diff --git a/lib/src/flutter/hooks/app_runner_hook.dart b/lib/src/flutter/hooks/app_runner_hook.dart index f662f43..d1940a9 100644 --- a/lib/src/flutter/hooks/app_runner_hook.dart +++ b/lib/src/flutter/hooks/app_runner_hook.dart @@ -11,15 +11,19 @@ class FlutterAppRunnerHook extends Hook { FlutterRunProcessHandler _flutterAppProcess; bool haveRunFirstScenario = false; + @override int get priority => 999999; + @override Future onBeforeRun(TestConfiguration config) async { await _runApp(_castConfig(config)); } + @override Future onAfterRun(TestConfiguration config) async => await _terminateApp(); + @override Future onBeforeScenario( TestConfiguration config, String scenario) async { final flutterConfig = _castConfig(config); @@ -28,6 +32,7 @@ class FlutterAppRunnerHook extends Hook { } } + @override Future onAfterScenario( TestConfiguration config, String scenario) async { final flutterConfig = _castConfig(config); @@ -39,7 +44,7 @@ class FlutterAppRunnerHook extends Hook { } Future _runApp(FlutterTestConfiguration config) async { - _flutterAppProcess = new FlutterRunProcessHandler(); + _flutterAppProcess = FlutterRunProcessHandler(); _flutterAppProcess.setApplicationTargetFile(config.targetAppPath); stdout.writeln( "Starting Flutter app under test '${config.targetAppPath}', this might take a few moments"); diff --git a/lib/src/flutter/steps/given_i_open_the_drawer_step.dart b/lib/src/flutter/steps/given_i_open_the_drawer_step.dart index d94daed..118270b 100644 --- a/lib/src/flutter/steps/given_i_open_the_drawer_step.dart +++ b/lib/src/flutter/steps/given_i_open_the_drawer_step.dart @@ -21,7 +21,7 @@ class GivenOpenDrawer extends Given1WithWorld { if (isOpen && action == "close") { // Swipe to the left across the whole app to close the drawer await world.driver - .scroll(drawerFinder, -300.0, 0.0, Duration(milliseconds: 300)); + .scroll(drawerFinder, -300.0, 0.0, const Duration(milliseconds: 300)); } else if (!isOpen && action == "open") { await FlutterDriverUtils.tap( world.driver, find.byTooltip("Open navigation menu"), diff --git a/lib/src/flutter/steps/when_pause_step.dart b/lib/src/flutter/steps/when_pause_step.dart index 33e60aa..8a175d0 100644 --- a/lib/src/flutter/steps/when_pause_step.dart +++ b/lib/src/flutter/steps/when_pause_step.dart @@ -10,7 +10,8 @@ import 'package:flutter_gherkin/src/gherkin/steps/when.dart'; /// When I pause for 120 seconds class WhenPauseStep extends When1 { WhenPauseStep() - : super(StepDefinitionConfiguration()..timeout = Duration(minutes: 5)); + : super(StepDefinitionConfiguration() + ..timeout = const Duration(minutes: 5)); @override Future executeStep(int seconds) async { diff --git a/lib/src/gherkin/exceptions/parameter_count_mismatch_error.dart b/lib/src/gherkin/exceptions/parameter_count_mismatch_error.dart index 5ffb54e..859755b 100644 --- a/lib/src/gherkin/exceptions/parameter_count_mismatch_error.dart +++ b/lib/src/gherkin/exceptions/parameter_count_mismatch_error.dart @@ -6,9 +6,11 @@ class GherkinStepParameterMismatchException implements Exception { GherkinStepParameterMismatchException( this.step, this.expectParameterCount, this.actualParameterCount) - : message = "$step parameter count mismatch. Expect $expectParameterCount parameters but got $actualParameterCount. " + - "Ensure you are extending the correct step class which would be " + + : message = + "$step parameter count mismatch. Expect $expectParameterCount parameters but got $actualParameterCount. " + "Ensure you are extending the correct step class which would be " "Given${actualParameterCount > 0 ? '$actualParameterCount<${List.generate(actualParameterCount, (i) => "TInputType$i").join(", ")}>' : ''}"; + @override String toString() => message; } diff --git a/lib/src/gherkin/expressions/gherkin_expression.dart b/lib/src/gherkin/expressions/gherkin_expression.dart index a2a56b3..dbf041e 100644 --- a/lib/src/gherkin/expressions/gherkin_expression.dart +++ b/lib/src/gherkin/expressions/gherkin_expression.dart @@ -11,7 +11,7 @@ class _SortedParameterPosition { class GherkinExpression { final RegExp originalExpression; final List<_SortedParameterPosition> _sortedParameterPositions = - List<_SortedParameterPosition>(); + <_SortedParameterPosition>[]; RegExp _expression; GherkinExpression(this.originalExpression, @@ -41,7 +41,7 @@ class GherkinExpression { bool inCustomBracketSection = false; int indexOfOpeningBracket; for (var i = 0; i < originalExpression.pattern.length; i += 1) { - var char = originalExpression.pattern[i]; + final char = originalExpression.pattern[i]; if (char == "(") { // look ahead and make sure we don't see "s)" which would // indicate the plural parameter @@ -75,8 +75,8 @@ class GherkinExpression { } Iterable getParameters(String input) { - List stringValues = List(); - List values = List(); + final List stringValues = []; + final List values = []; _expression.allMatches(input).forEach((m) { // the first group is always the input string final indicies = diff --git a/lib/src/gherkin/expressions/tag_expression.dart b/lib/src/gherkin/expressions/tag_expression.dart index 74ea9c5..4a4d1b8 100644 --- a/lib/src/gherkin/expressions/tag_expression.dart +++ b/lib/src/gherkin/expressions/tag_expression.dart @@ -30,7 +30,7 @@ class TagExpressionEvaluator { } bool _evaluateRpn(Queue rpn, List tags) { - Queue stack = Queue(); + final Queue stack = Queue(); for (var token in rpn) { if (_isTag(token)) { stack.addFirst(tags.contains(token.replaceFirst(RegExp("@"), ""))); @@ -79,25 +79,25 @@ class TagExpressionEvaluator { operatorQueue.addLast(part); } else if (part == closingBracket) { while ( - operatorQueue.length > 0 && operatorQueue.last != openingBracket) { + operatorQueue.isNotEmpty && operatorQueue.last != openingBracket) { rpn.add(operatorQueue.removeLast()); } operatorQueue.removeLast(); } else if (_isOperator(part)) { final precendence = _operatorPrededence[part.toLowerCase()]; - while (operatorQueue.length > 0 && + while (operatorQueue.isNotEmpty && _operatorPrededence[operatorQueue.last] >= precendence) { rpn.add(operatorQueue.removeLast()); } operatorQueue.addLast(part); } else { - throw new GherkinSyntaxException( + throw GherkinSyntaxException( "Tag expression '$infixExpression' is not valid. Unknown token '$part'. Known tokens are '@tag', 'and', 'or', 'not' '(' and ')'"); } } - while (operatorQueue.length > 0) { + while (operatorQueue.isNotEmpty) { rpn.add(operatorQueue.removeLast()); } diff --git a/lib/src/gherkin/parser.dart b/lib/src/gherkin/parser.dart index 62740a4..a8e959c 100644 --- a/lib/src/gherkin/parser.dart +++ b/lib/src/gherkin/parser.dart @@ -74,7 +74,7 @@ class GherkinParser { parentBlock.addChild(runnable); } else { - throw new GherkinSyntaxException( + throw GherkinSyntaxException( "Unknown or un-implemented syntax: '$line', file: '${parentBlock.debug.filePath}"); } } diff --git a/lib/src/gherkin/runnables/debug_information.dart b/lib/src/gherkin/runnables/debug_information.dart index 0cf170a..444050e 100644 --- a/lib/src/gherkin/runnables/debug_information.dart +++ b/lib/src/gherkin/runnables/debug_information.dart @@ -6,6 +6,6 @@ class RunnableDebugInformation { RunnableDebugInformation(this.filePath, this.lineNumber, this.lineText); RunnableDebugInformation copyWith(int lineNumber, String line) { - return RunnableDebugInformation(this.filePath, lineNumber, line); + return RunnableDebugInformation(filePath, lineNumber, line); } } diff --git a/lib/src/gherkin/runnables/feature.dart b/lib/src/gherkin/runnables/feature.dart index 1bee6e9..1e77819 100644 --- a/lib/src/gherkin/runnables/feature.dart +++ b/lib/src/gherkin/runnables/feature.dart @@ -12,11 +12,11 @@ import 'package:flutter_gherkin/src/gherkin/runnables/text_line.dart'; class FeatureRunnable extends RunnableBlock { String _name; String description; - List tags = List(); + List tags = []; BackgroundRunnable background; - List scenarios = List(); + List scenarios = []; - Map> _tagMap = Map>(); + Map> _tagMap = >{}; FeatureRunnable(this._name, RunnableDebugInformation debug) : super(debug); @@ -46,7 +46,7 @@ class FeatureRunnable extends RunnableBlock { if (background == null) { background = child; } else { - throw new GherkinSyntaxException( + throw GherkinSyntaxException( "Feature file can only contain one backgroung block. File'${debug.filePath}' :: line '${child.debug.lineNumber}'"); } break; @@ -54,7 +54,7 @@ class FeatureRunnable extends RunnableBlock { case CommentLineRunnable: break; default: - throw new Exception( + throw Exception( "Unknown runnable child given to Feature '${child.runtimeType}'"); } } diff --git a/lib/src/gherkin/runnables/feature_file.dart b/lib/src/gherkin/runnables/feature_file.dart index f87f5ca..c46762f 100644 --- a/lib/src/gherkin/runnables/feature_file.dart +++ b/lib/src/gherkin/runnables/feature_file.dart @@ -8,7 +8,7 @@ import 'package:flutter_gherkin/src/gherkin/runnables/runnable_block.dart'; class FeatureFile extends RunnableBlock { String _language = "en"; - List features = new List(); + List features = []; FeatureFile(RunnableDebugInformation debug) : super(debug); @@ -26,7 +26,7 @@ class FeatureFile extends RunnableBlock { case EmptyLineRunnable: break; default: - throw new Exception( + throw Exception( "Unknown runnable child given to FeatureFile '${child.runtimeType}'"); } } diff --git a/lib/src/gherkin/runnables/multi_line_string.dart b/lib/src/gherkin/runnables/multi_line_string.dart index 7236164..fd20353 100644 --- a/lib/src/gherkin/runnables/multi_line_string.dart +++ b/lib/src/gherkin/runnables/multi_line_string.dart @@ -5,7 +5,7 @@ import 'package:flutter_gherkin/src/gherkin/runnables/runnable_block.dart'; import 'package:flutter_gherkin/src/gherkin/runnables/text_line.dart'; class MultilineStringRunnable extends RunnableBlock { - List lines = List(); + List lines = []; @override String get name => "Multiline String"; @@ -14,6 +14,8 @@ class MultilineStringRunnable extends RunnableBlock { @override void addChild(Runnable child) { + final exception = Exception( + "Unknown runnable child given to Multiline string '${child.runtimeType}'"); switch (child.runtimeType) { case TextLineRunnable: lines.add((child as TextLineRunnable).text); @@ -21,8 +23,7 @@ class MultilineStringRunnable extends RunnableBlock { case EmptyLineRunnable: break; default: - throw new Exception( - "Unknown runnable child given to Multiline string '${child.runtimeType}'"); + throw exception; } } } diff --git a/lib/src/gherkin/runnables/scenario.dart b/lib/src/gherkin/runnables/scenario.dart index 1eb9159..c705aa8 100644 --- a/lib/src/gherkin/runnables/scenario.dart +++ b/lib/src/gherkin/runnables/scenario.dart @@ -8,8 +8,8 @@ import 'package:flutter_gherkin/src/gherkin/runnables/tags.dart'; class ScenarioRunnable extends RunnableBlock { String _name; - List tags = List(); - List steps = new List(); + List tags = []; + List steps = []; ScenarioRunnable(this._name, RunnableDebugInformation debug) : super(debug); @@ -29,7 +29,7 @@ class ScenarioRunnable extends RunnableBlock { case EmptyLineRunnable: break; default: - throw new Exception( + throw Exception( "Unknown runnable child given to Scenario '${child.runtimeType}'"); } } diff --git a/lib/src/gherkin/runnables/step.dart b/lib/src/gherkin/runnables/step.dart index 8c00ecf..0328917 100644 --- a/lib/src/gherkin/runnables/step.dart +++ b/lib/src/gherkin/runnables/step.dart @@ -9,7 +9,7 @@ import 'package:flutter_gherkin/src/gherkin/runnables/table.dart'; class StepRunnable extends RunnableBlock { String _name; String description; - List multilineStrings = List(); + List multilineStrings = []; Table table; StepRunnable(this._name, RunnableDebugInformation debug) : super(debug); @@ -26,13 +26,13 @@ class StepRunnable extends RunnableBlock { break; case TableRunnable: if (table != null) - throw new GherkinSyntaxException( + throw GherkinSyntaxException( "Only a single table can be added to the step '$name'"); table = (child as TableRunnable).toTable(); break; default: - throw new Exception( + throw Exception( "Unknown runnable child given to Step '${child.runtimeType}'"); } } diff --git a/lib/src/gherkin/runnables/table.dart b/lib/src/gherkin/runnables/table.dart index e8e1fae..04fa131 100644 --- a/lib/src/gherkin/runnables/table.dart +++ b/lib/src/gherkin/runnables/table.dart @@ -6,7 +6,7 @@ import 'package:flutter_gherkin/src/gherkin/runnables/runnable.dart'; import 'package:flutter_gherkin/src/gherkin/runnables/runnable_block.dart'; class TableRunnable extends RunnableBlock { - final List rows = List(); + final List rows = []; @override String get name => "Table"; @@ -22,14 +22,14 @@ class TableRunnable extends RunnableBlock { case CommentLineRunnable: break; default: - throw new Exception( + throw Exception( "Unknown runnable child given to Table '${child.runtimeType}'"); } } Table toTable() { TableRow header; - List tableRows = List(); + final List tableRows = []; if (rows.length > 1) { header = _toRow(rows.first, 0, true); } diff --git a/lib/src/gherkin/steps/step_definition.dart b/lib/src/gherkin/steps/step_definition.dart index 307efdf..4f3fa59 100644 --- a/lib/src/gherkin/steps/step_definition.dart +++ b/lib/src/gherkin/steps/step_definition.dart @@ -16,7 +16,7 @@ abstract class StepDefinitionGeneric { RegExp get pattern; StepDefinitionGeneric(this.config, this._expectParameterCount) { - this._timeout = this.config?.timeout; + _timeout = config?.timeout; } TWorld get world => _world; @@ -54,6 +54,6 @@ abstract class StepDefinitionGeneric { void _ensureParameterCount(int actual, int expected) { if (actual != expected) throw GherkinStepParameterMismatchException( - this.runtimeType, expected, actual); + runtimeType, expected, actual); } } diff --git a/lib/src/gherkin/steps/step_definition_implementations.dart b/lib/src/gherkin/steps/step_definition_implementations.dart index 2a42d17..7c541e4 100644 --- a/lib/src/gherkin/steps/step_definition_implementations.dart +++ b/lib/src/gherkin/steps/step_definition_implementations.dart @@ -28,6 +28,7 @@ abstract class StepDefinition StepDefinition([StepDefinitionConfiguration configuration]) : super(configuration, 0); + @override Future onRun(Iterable parameters) async => await code(); } @@ -36,6 +37,7 @@ abstract class StepDefinition1 StepDefinition1([StepDefinitionConfiguration configuration]) : super(configuration, 1); + @override Future onRun(Iterable parameters) async => await code(parameters.elementAt(0)); } @@ -45,6 +47,7 @@ abstract class StepDefinition2 StepDefinition2([StepDefinitionConfiguration configuration]) : super(configuration, 2); + @override Future onRun(Iterable parameters) async => await code(parameters.elementAt(0), parameters.elementAt(1)); } @@ -55,6 +58,7 @@ abstract class StepDefinition3 StepDefinition3([StepDefinitionConfiguration configuration]) : super(configuration, 3); + @override Future onRun(Iterable parameters) async => await code( parameters.elementAt(0), parameters.elementAt(1), @@ -68,6 +72,7 @@ abstract class StepDefinition4 onRun(Iterable parameters) async => await code( parameters.elementAt(0), parameters.elementAt(1), @@ -82,6 +87,7 @@ abstract class StepDefinition5 onRun(Iterable parameters) async => await code( parameters.elementAt(0), parameters.elementAt(1), diff --git a/lib/src/gherkin/syntax/background_syntax.dart b/lib/src/gherkin/syntax/background_syntax.dart index 2a44ea9..d78d508 100644 --- a/lib/src/gherkin/syntax/background_syntax.dart +++ b/lib/src/gherkin/syntax/background_syntax.dart @@ -8,6 +8,7 @@ import 'package:flutter_gherkin/src/gherkin/syntax/syntax_matcher.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/tag_syntax.dart'; class BackgroundSyntax extends RegExMatchedGherkinSyntax { + @override final RegExp pattern = RegExp(r"^\s*Background:\s*(.+)\s*$", multiLine: false, caseSensitive: false); @@ -23,7 +24,7 @@ class BackgroundSyntax extends RegExMatchedGherkinSyntax { @override Runnable toRunnable(String line, RunnableDebugInformation debug) { final name = pattern.firstMatch(line).group(1); - final runnable = new BackgroundRunnable(name, debug); + final runnable = BackgroundRunnable(name, debug); return runnable; } } diff --git a/lib/src/gherkin/syntax/comment_syntax.dart b/lib/src/gherkin/syntax/comment_syntax.dart index 172f30c..05d0472 100644 --- a/lib/src/gherkin/syntax/comment_syntax.dart +++ b/lib/src/gherkin/syntax/comment_syntax.dart @@ -4,6 +4,7 @@ import 'package:flutter_gherkin/src/gherkin/runnables/runnable.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/regex_matched_syntax.dart'; class CommentSyntax extends RegExMatchedGherkinSyntax { + @override final RegExp pattern = RegExp("^#", multiLine: false, caseSensitive: false); @override diff --git a/lib/src/gherkin/syntax/empty_line_syntax.dart b/lib/src/gherkin/syntax/empty_line_syntax.dart index 5bcca72..cc3ac85 100644 --- a/lib/src/gherkin/syntax/empty_line_syntax.dart +++ b/lib/src/gherkin/syntax/empty_line_syntax.dart @@ -4,6 +4,7 @@ import 'package:flutter_gherkin/src/gherkin/runnables/runnable.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/regex_matched_syntax.dart'; class EmptyLineSyntax extends RegExMatchedGherkinSyntax { + @override final RegExp pattern = RegExp(r"^\s*$", multiLine: false, caseSensitive: false); diff --git a/lib/src/gherkin/syntax/feature_syntax.dart b/lib/src/gherkin/syntax/feature_syntax.dart index 160b685..f3cd88e 100644 --- a/lib/src/gherkin/syntax/feature_syntax.dart +++ b/lib/src/gherkin/syntax/feature_syntax.dart @@ -5,6 +5,7 @@ import './syntax_matcher.dart'; import './regex_matched_syntax.dart'; class FeatureSyntax extends RegExMatchedGherkinSyntax { + @override final RegExp pattern = RegExp(r"^Feature:\s*(.+)\s*", multiLine: false, caseSensitive: false); @@ -17,7 +18,7 @@ class FeatureSyntax extends RegExMatchedGherkinSyntax { @override Runnable toRunnable(String line, RunnableDebugInformation debug) { final name = pattern.firstMatch(line).group(1); - final runnable = new FeatureRunnable(name, debug); + final runnable = FeatureRunnable(name, debug); return runnable; } } diff --git a/lib/src/gherkin/syntax/language_syntax.dart b/lib/src/gherkin/syntax/language_syntax.dart index b04fc53..22c05f7 100644 --- a/lib/src/gherkin/syntax/language_syntax.dart +++ b/lib/src/gherkin/syntax/language_syntax.dart @@ -5,12 +5,13 @@ import './regex_matched_syntax.dart'; /// see https://docs.cucumber.io/gherkin/reference/#gherkin-dialects class LanguageSyntax extends RegExMatchedGherkinSyntax { + @override final RegExp pattern = RegExp(r"^\s*#\s*language:\s*([a-z]{2,7})\s*$", multiLine: false, caseSensitive: false); @override Runnable toRunnable(String line, RunnableDebugInformation debug) { - final runnable = new LanguageRunnable(debug); + final runnable = LanguageRunnable(debug); runnable.language = pattern.firstMatch(line).group(1); return runnable; } diff --git a/lib/src/gherkin/syntax/multiline_string_syntax.dart b/lib/src/gherkin/syntax/multiline_string_syntax.dart index 246a8ab..fc29d0f 100644 --- a/lib/src/gherkin/syntax/multiline_string_syntax.dart +++ b/lib/src/gherkin/syntax/multiline_string_syntax.dart @@ -8,8 +8,13 @@ import 'package:flutter_gherkin/src/gherkin/syntax/syntax_matcher.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/text_line_syntax.dart'; class MultilineStringSyntax extends RegExMatchedGherkinSyntax { - final RegExp pattern = RegExp(r"^\s*(" + '"""' + r"|'''|```)\s*$", - multiLine: false, caseSensitive: false); + @override + final RegExp pattern = RegExp( + r"^\s*(" + '"""' + r"|'''|```)\s*$", + multiLine: false, + caseSensitive: false); @override bool get isBlockSyntax => true; @@ -27,7 +32,7 @@ class MultilineStringSyntax extends RegExMatchedGherkinSyntax { @override Runnable toRunnable(String line, RunnableDebugInformation debug) { - final runnable = new MultilineStringRunnable(debug); + final runnable = MultilineStringRunnable(debug); return runnable; } diff --git a/lib/src/gherkin/syntax/scenario_syntax.dart b/lib/src/gherkin/syntax/scenario_syntax.dart index 949e167..adf1fc2 100644 --- a/lib/src/gherkin/syntax/scenario_syntax.dart +++ b/lib/src/gherkin/syntax/scenario_syntax.dart @@ -6,6 +6,7 @@ import 'package:flutter_gherkin/src/gherkin/syntax/syntax_matcher.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/tag_syntax.dart'; class ScenarioSyntax extends RegExMatchedGherkinSyntax { + @override final RegExp pattern = RegExp(r"^\s*Scenario:\s*(.+)\s*$", multiLine: false, caseSensitive: false); @@ -19,7 +20,7 @@ class ScenarioSyntax extends RegExMatchedGherkinSyntax { @override Runnable toRunnable(String line, RunnableDebugInformation debug) { final name = pattern.firstMatch(line).group(1); - final runnable = new ScenarioRunnable(name, debug); + final runnable = ScenarioRunnable(name, debug); return runnable; } } diff --git a/lib/src/gherkin/syntax/step_syntax.dart b/lib/src/gherkin/syntax/step_syntax.dart index e93d4ad..244c94a 100644 --- a/lib/src/gherkin/syntax/step_syntax.dart +++ b/lib/src/gherkin/syntax/step_syntax.dart @@ -7,6 +7,7 @@ import 'package:flutter_gherkin/src/gherkin/syntax/syntax_matcher.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/table_line_syntax.dart'; class StepSyntax extends RegExMatchedGherkinSyntax { + @override final RegExp pattern = RegExp(r"^(given|then|when|and|but)\s.*", multiLine: false, caseSensitive: false); @@ -19,7 +20,7 @@ class StepSyntax extends RegExMatchedGherkinSyntax { @override Runnable toRunnable(String line, RunnableDebugInformation debug) { - final runnable = new StepRunnable(line, debug); + final runnable = StepRunnable(line, debug); return runnable; } } diff --git a/lib/src/gherkin/syntax/table_line_syntax.dart b/lib/src/gherkin/syntax/table_line_syntax.dart index cb0e3ed..3368627 100644 --- a/lib/src/gherkin/syntax/table_line_syntax.dart +++ b/lib/src/gherkin/syntax/table_line_syntax.dart @@ -6,6 +6,7 @@ import 'package:flutter_gherkin/src/gherkin/syntax/regex_matched_syntax.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/syntax_matcher.dart'; class TableLineSyntax extends RegExMatchedGherkinSyntax { + @override final RegExp pattern = RegExp(r"^\s*\|.*\|\s*$", multiLine: false, caseSensitive: false); @@ -22,7 +23,7 @@ class TableLineSyntax extends RegExMatchedGherkinSyntax { @override Runnable toRunnable(String line, RunnableDebugInformation debug) { - final runnable = new TableRunnable(debug); + final runnable = TableRunnable(debug); runnable.rows.add(line.trim()); return runnable; } diff --git a/lib/src/gherkin/syntax/tag_syntax.dart b/lib/src/gherkin/syntax/tag_syntax.dart index 1307225..a7b8179 100644 --- a/lib/src/gherkin/syntax/tag_syntax.dart +++ b/lib/src/gherkin/syntax/tag_syntax.dart @@ -4,11 +4,12 @@ import 'package:flutter_gherkin/src/gherkin/runnables/tags.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/regex_matched_syntax.dart'; class TagSyntax extends RegExMatchedGherkinSyntax { + @override final RegExp pattern = RegExp("^@", multiLine: false, caseSensitive: false); @override Runnable toRunnable(String line, RunnableDebugInformation debug) { - final runnable = new TagsRunnable(debug); + final runnable = TagsRunnable(debug); runnable.tags = line .trim() .split(RegExp("@")) diff --git a/lib/src/gherkin/syntax/text_line_syntax.dart b/lib/src/gherkin/syntax/text_line_syntax.dart index fd90d75..9af7b75 100644 --- a/lib/src/gherkin/syntax/text_line_syntax.dart +++ b/lib/src/gherkin/syntax/text_line_syntax.dart @@ -4,12 +4,13 @@ import 'package:flutter_gherkin/src/gherkin/runnables/text_line.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/regex_matched_syntax.dart'; class TextLineSyntax extends RegExMatchedGherkinSyntax { + @override final RegExp pattern = RegExp(r"^\s*(?!#)\w+.*]*$", multiLine: false, caseSensitive: false); @override Runnable toRunnable(String line, RunnableDebugInformation debug) { - final runnable = new TextLineRunnable(debug); + final runnable = TextLineRunnable(debug); runnable.text = line.trim(); return runnable; } diff --git a/lib/src/hooks/aggregated_hook.dart b/lib/src/hooks/aggregated_hook.dart index 27a2d2b..7209227 100644 --- a/lib/src/hooks/aggregated_hook.dart +++ b/lib/src/hooks/aggregated_hook.dart @@ -9,29 +9,34 @@ class AggregatedHook extends Hook { _orderedHooks = hooks.toList()..sort((a, b) => b.priority - a.priority); } + @override Future onBeforeRun(TestConfiguration config) async => await _invokeHooks((h) => h.onBeforeRun(config)); /// Run after all scenerios in a test run have completed + @override Future onAfterRun(TestConfiguration config) async => await _invokeHooks((h) => h.onAfterRun(config)); + @override Future onAfterScenarioWorldCreated( World world, String scenario) async => await _invokeHooks((h) => h.onAfterScenarioWorldCreated(world, scenario)); /// Run before a scenario and it steps are executed + @override Future onBeforeScenario( TestConfiguration config, String scenario) async => await _invokeHooks((h) => h.onBeforeScenario(config, scenario)); /// Run after a scenario has executed + @override Future onAfterScenario( TestConfiguration config, String scenario) async => await _invokeHooks((h) => h.onAfterScenario(config, scenario)); Future _invokeHooks(Future invoke(Hook h)) async { - if (_orderedHooks != null && _orderedHooks.length > 0) { + if (_orderedHooks != null && _orderedHooks.isNotEmpty) { for (var hook in _orderedHooks) { await invoke(hook); } diff --git a/lib/src/reporters/aggregated_reporter.dart b/lib/src/reporters/aggregated_reporter.dart index 6e5b215..76b1d05 100644 --- a/lib/src/reporters/aggregated_reporter.dart +++ b/lib/src/reporters/aggregated_reporter.dart @@ -3,7 +3,7 @@ import 'package:flutter_gherkin/src/reporters/message_level.dart'; import 'package:flutter_gherkin/src/reporters/reporter.dart'; class AggregatedReporter extends Reporter { - final List _reporters = new List(); + final List _reporters = []; void addReporter(Reporter reporter) => _reporters.add(reporter); @@ -64,7 +64,7 @@ class AggregatedReporter extends Reporter { } Future _invokeReporters(Future invoke(Reporter r)) async { - if (_reporters != null && _reporters.length > 0) { + if (_reporters != null && _reporters.isNotEmpty) { for (var reporter in _reporters) { try { await invoke(reporter); diff --git a/lib/src/reporters/progress_reporter.dart b/lib/src/reporters/progress_reporter.dart index d1ff108..ff0b871 100644 --- a/lib/src/reporters/progress_reporter.dart +++ b/lib/src/reporters/progress_reporter.dart @@ -33,6 +33,7 @@ class ProgressReporter extends StdoutReporter { _getMessageColour(message.result.result)); } + @override Future message(String message, MessageLevel level) async { // ignore messages } diff --git a/lib/src/reporters/stdout_reporter.dart b/lib/src/reporters/stdout_reporter.dart index ffa7aa3..4f2a2c8 100644 --- a/lib/src/reporters/stdout_reporter.dart +++ b/lib/src/reporters/stdout_reporter.dart @@ -13,6 +13,7 @@ class StdoutReporter extends Reporter { StdoutReporter([this._logLevel = MessageLevel.verbose]); + @override Future message(String message, MessageLevel level) async { if (level.index >= _logLevel.index) { printMessageLine(message, getColour(level)); diff --git a/lib/src/reporters/test_run_summary_reporter.dart b/lib/src/reporters/test_run_summary_reporter.dart index 57a92d4..fa4ced4 100644 --- a/lib/src/reporters/test_run_summary_reporter.dart +++ b/lib/src/reporters/test_run_summary_reporter.dart @@ -4,10 +4,10 @@ import 'package:flutter_gherkin/src/reporters/message_level.dart'; import 'package:flutter_gherkin/src/reporters/messages.dart'; class TestRunSummaryReporter extends StdoutReporter { - final _timer = new Stopwatch(); - final List _ranSteps = List(); + final _timer = Stopwatch(); + final List _ranSteps = []; final List _ranScenarios = - List(); + []; @override Future onScenarioFinished(ScenarioFinishedMessage message) async { @@ -47,7 +47,7 @@ class TestRunSummaryReporter extends StdoutReporter { } String _collectScenarioSummary(Iterable scenarios) { - List summaries = List(); + final List summaries = []; if (scenarios.any((s) => s.passed)) { summaries.add( "${StdoutReporter.PASS_COLOR}${scenarios.where((s) => s.passed).length} passed${StdoutReporter.RESET_COLOR}"); @@ -62,7 +62,7 @@ class TestRunSummaryReporter extends StdoutReporter { } String _collectStepSummary(Iterable steps) { - List summaries = List(); + final List summaries = []; final passed = steps.where((s) => s.result.result == StepExecutionResult.pass); final skipped = @@ -71,17 +71,17 @@ class TestRunSummaryReporter extends StdoutReporter { s.result.result == StepExecutionResult.error || s.result.result == StepExecutionResult.fail || s.result.result == StepExecutionResult.timeout); - if (passed.length > 0) { + if (passed.isNotEmpty) { summaries.add( "${StdoutReporter.PASS_COLOR}${passed.length} passed${StdoutReporter.RESET_COLOR}"); } - if (skipped.length > 0) { + if (skipped.isNotEmpty) { summaries.add( "${StdoutReporter.WARN_COLOR}${skipped.length} skipped${StdoutReporter.RESET_COLOR}"); } - if (failed.length > 0) { + if (failed.isNotEmpty) { summaries.add( "${StdoutReporter.FAIL_COLOR}${failed.length} failed${StdoutReporter.RESET_COLOR}"); } diff --git a/lib/src/test_runner.dart b/lib/src/test_runner.dart index 8824654..33c5914 100644 --- a/lib/src/test_runner.dart +++ b/lib/src/test_runner.dart @@ -20,12 +20,12 @@ import 'package:flutter_gherkin/src/reporters/message_level.dart'; import 'package:flutter_gherkin/src/reporters/reporter.dart'; class GherkinRunner { - final _reporter = new AggregatedReporter(); - final _hook = new AggregatedHook(); - final _parser = new GherkinParser(); - final _tagExpressionEvaluator = new TagExpressionEvaluator(); - final List _executableSteps = new List(); - final List _customParameters = new List(); + final _reporter = AggregatedReporter(); + final _hook = AggregatedHook(); + final _parser = GherkinParser(); + final _tagExpressionEvaluator = TagExpressionEvaluator(); + final List _executableSteps = []; + final List _customParameters = []; Future execute(TestConfiguration config) async { config.prepare(); @@ -34,7 +34,7 @@ class GherkinRunner { _registerCustomParameters(config.customStepParameterDefinitions); _registerStepDefinitions(config.stepDefinitions); - List featureFiles = List(); + List featureFiles = []; for (var glob in config.features) { for (var entity in glob.listSync()) { await _reporter.message( @@ -48,7 +48,7 @@ class GherkinRunner { bool allFeaturesPassed = true; - if (featureFiles.length == 0) { + if (featureFiles.isEmpty) { await _reporter.message( "No feature files found to run, exitting without running any scenarios", MessageLevel.warning); @@ -68,9 +68,9 @@ class GherkinRunner { try { await _reporter.onTestRunStarted(); for (var featureFile in featureFiles) { - final runner = new FeatureFileRunner(config, _tagExpressionEvaluator, + final runner = FeatureFileRunner(config, _tagExpressionEvaluator, _executableSteps, _reporter, _hook); - await runner.run(featureFile); + allFeaturesPassed &= await runner.run(featureFile); } } finally { await _reporter.onTestRunFinished(); @@ -94,17 +94,17 @@ class GherkinRunner { } void _registerCustomParameters(Iterable customParameters) { - _customParameters.add(new FloatParameterLower()); - _customParameters.add(new FloatParameterCamel()); - _customParameters.add(new NumParameterLower()); - _customParameters.add(new NumParameterCamel()); - _customParameters.add(new IntParameterLower()); - _customParameters.add(new IntParameterCamel()); - _customParameters.add(new StringParameterLower()); - _customParameters.add(new StringParameterCamel()); - _customParameters.add(new WordParameterLower()); - _customParameters.add(new WordParameterCamel()); - _customParameters.add(new PluralParameter()); + _customParameters.add(FloatParameterLower()); + _customParameters.add(FloatParameterCamel()); + _customParameters.add(NumParameterLower()); + _customParameters.add(NumParameterCamel()); + _customParameters.add(IntParameterLower()); + _customParameters.add(IntParameterCamel()); + _customParameters.add(StringParameterLower()); + _customParameters.add(StringParameterCamel()); + _customParameters.add(WordParameterLower()); + _customParameters.add(WordParameterCamel()); + _customParameters.add(PluralParameter()); if (customParameters != null) _customParameters.addAll(customParameters); } diff --git a/lib/src/utils/perf.dart b/lib/src/utils/perf.dart index 92efdd1..6c813f4 100644 --- a/lib/src/utils/perf.dart +++ b/lib/src/utils/perf.dart @@ -3,7 +3,7 @@ import 'dart:async'; class Perf { static Future measure( Future action(), void logFn(int elapsedMilliseconds)) async { - final timer = new Stopwatch(); + final timer = Stopwatch(); timer.start(); try { return await action(); diff --git a/pubspec.lock b/pubspec.lock index 3b877d4..2434520 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -231,6 +231,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.6.2" + pedantic: + dependency: "direct main" + description: + name: pedantic + url: "https://pub.dartlang.org" + source: hosted + version: "1.4.0" platform: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 647eeb3..ef0acb7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_gherkin description: A Gherkin / Cucumber parser and test runner for Dart and Flutter -version: 0.0.10 +version: 0.0.11 author: Jon Samwell homepage: https://github.com/jonsamwell/flutter_gherkin @@ -18,6 +18,7 @@ dependencies: sdk: flutter flutter_driver: sdk: flutter + pedantic: ^1.4.0 dev_dependencies: diff --git a/test/feature_file_runner_test.dart b/test/feature_file_runner_test.dart index e520944..7e79d71 100644 --- a/test/feature_file_runner_test.dart +++ b/test/feature_file_runner_test.dart @@ -23,22 +23,21 @@ void main() { test("run simple feature file scenario", () async { final stepDefiniton = MockStepDefinition(); final executableStep = - new ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton); - final runner = new FeatureFileRunner( + ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton); + final runner = FeatureFileRunner( TestConfiguration(), MockTagExpressionEvaluator(), [executableStep], ReporterMock(), HookMock()); - final step = new StepRunnable( + final step = StepRunnable( "Step 1", RunnableDebugInformation("", 0, "Given I do a")); - final scenario = new ScenarioRunnable("Scenario: 1", emptyDebuggable) + final scenario = ScenarioRunnable("Scenario: 1", emptyDebuggable) ..steps.add(step); - final feature = new FeatureRunnable("1", emptyDebuggable) + final feature = FeatureRunnable("1", emptyDebuggable) ..scenarios.add(scenario); - final featureFile = new FeatureFile(emptyDebuggable) - ..features.add(feature); + final featureFile = FeatureFile(emptyDebuggable)..features.add(feature); await runner.run(featureFile); expect(stepDefiniton.hasRun, true); expect(stepDefiniton.runCount, 1); @@ -49,8 +48,8 @@ void main() { bool worldCreationFnInoked = false; final stepDefiniton = MockStepDefinition(); final executableStep = - new ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton); - final runner = new FeatureFileRunner( + ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton); + final runner = FeatureFileRunner( TestConfiguration() ..createWorld = (_) async { worldCreationFnInoked = true; @@ -61,14 +60,13 @@ void main() { ReporterMock(), HookMock()); - final step = new StepRunnable( + final step = StepRunnable( "Step 1", RunnableDebugInformation("", 0, "Given I do a")); - final scenario = new ScenarioRunnable("Scenario: 1", emptyDebuggable) + final scenario = ScenarioRunnable("Scenario: 1", emptyDebuggable) ..steps.add(step); - final feature = new FeatureRunnable("1", emptyDebuggable) + final feature = FeatureRunnable("1", emptyDebuggable) ..scenarios.add(scenario); - final featureFile = new FeatureFile(emptyDebuggable) - ..features.add(feature); + final featureFile = FeatureFile(emptyDebuggable)..features.add(feature); await runner.run(featureFile); expect(worldCreationFnInoked, true); expect(worldMock.disposeFnInvoked, true); @@ -77,30 +75,29 @@ void main() { test("steps are skipped if previous step failed", () async { final stepTextOne = "Given I do a"; final stepTextTwo = "Given I do b"; - final stepDefiniton = MockStepDefinition((_) => throw new Exception()); + final stepDefiniton = MockStepDefinition((_) => throw Exception()); final stepDefinitonTwo = MockStepDefinition(); - final executableStep = new ExectuableStep( + final executableStep = ExectuableStep( MockGherkinExpression((s) => s == stepTextOne), stepDefiniton); - final executableStepTwo = new ExectuableStep( + final executableStepTwo = ExectuableStep( MockGherkinExpression((s) => s == stepTextTwo), stepDefinitonTwo); - final runner = new FeatureFileRunner( + final runner = FeatureFileRunner( TestConfiguration(), MockTagExpressionEvaluator(), [executableStep, executableStepTwo], ReporterMock(), HookMock()); - final step = new StepRunnable( - "Step 1", RunnableDebugInformation("", 0, stepTextOne)); - final stepTwo = new StepRunnable( - "Step 2", RunnableDebugInformation("", 0, stepTextTwo)); - final scenario = new ScenarioRunnable("Scenario: 1", emptyDebuggable) + final step = + StepRunnable("Step 1", RunnableDebugInformation("", 0, stepTextOne)); + final stepTwo = + StepRunnable("Step 2", RunnableDebugInformation("", 0, stepTextTwo)); + final scenario = ScenarioRunnable("Scenario: 1", emptyDebuggable) ..steps.add(step) ..steps.add(stepTwo); - final feature = new FeatureRunnable("1", emptyDebuggable) + final feature = FeatureRunnable("1", emptyDebuggable) ..scenarios.add(scenario); - final featureFile = new FeatureFile(emptyDebuggable) - ..features.add(feature); + final featureFile = FeatureFile(emptyDebuggable)..features.add(feature); await runner.run(featureFile); expect(stepDefiniton.hasRun, true); expect(stepDefiniton.runCount, 1); @@ -110,23 +107,22 @@ void main() { group("step matching", () { test("exception throw when matching step definition not found", () async { final stepDefiniton = MockStepDefinition(); - final executableStep = new ExectuableStep( - MockGherkinExpression((_) => false), stepDefiniton); - final runner = new FeatureFileRunner( + final executableStep = + ExectuableStep(MockGherkinExpression((_) => false), stepDefiniton); + final runner = FeatureFileRunner( TestConfiguration(), MockTagExpressionEvaluator(), [executableStep], ReporterMock(), HookMock()); - final step = new StepRunnable("Step 1", + final step = StepRunnable("Step 1", RunnableDebugInformation("File Path", 2, "Given I do 'a'")); - final scenario = new ScenarioRunnable("Scenario: 1", emptyDebuggable) + final scenario = ScenarioRunnable("Scenario: 1", emptyDebuggable) ..steps.add(step); - final feature = new FeatureRunnable("1", emptyDebuggable) + final feature = FeatureRunnable("1", emptyDebuggable) ..scenarios.add(scenario); - final featureFile = new FeatureFile(emptyDebuggable) - ..features.add(feature); + final featureFile = FeatureFile(emptyDebuggable)..features.add(feature); expect( () async => await runner.run(featureFile), throwsA(allOf( @@ -172,24 +168,23 @@ void main() { MockStepDefinition((Iterable parameters) async { tableParameterProvided = parameters.first is Table; }, 1); - final executableStep = new ExectuableStep( - MockGherkinExpression((_) => true), stepDefiniton); - final runner = new FeatureFileRunner( + final executableStep = + ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton); + final runner = FeatureFileRunner( TestConfiguration(), MockTagExpressionEvaluator(), [executableStep], ReporterMock(), HookMock()); - final step = new StepRunnable( + final step = StepRunnable( "Step 1", RunnableDebugInformation("", 0, "Given I do a")); - step.table = new Table(null, null); - final scenario = new ScenarioRunnable("Scenario: 1", emptyDebuggable) + step.table = Table(null, null); + final scenario = ScenarioRunnable("Scenario: 1", emptyDebuggable) ..steps.add(step); - final feature = new FeatureRunnable("1", emptyDebuggable) + final feature = FeatureRunnable("1", emptyDebuggable) ..scenarios.add(scenario); - final featureFile = new FeatureFile(emptyDebuggable) - ..features.add(feature); + final featureFile = FeatureFile(emptyDebuggable)..features.add(feature); await runner.run(featureFile); expect(stepDefiniton.hasRun, true); expect(stepDefiniton.runCount, 1); @@ -201,26 +196,25 @@ void main() { test("hook is called when starting and finishing scenarios", () async { final hookMock = HookMock(); final stepDefiniton = MockStepDefinition(); - final executableStep = new ExectuableStep( - MockGherkinExpression((_) => true), stepDefiniton); - final runner = new FeatureFileRunner( + final executableStep = + ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton); + final runner = FeatureFileRunner( TestConfiguration(), MockTagExpressionEvaluator(), [executableStep], ReporterMock(), hookMock); - final step = new StepRunnable( + final step = StepRunnable( "Step 1", RunnableDebugInformation("", 0, "Given I do a")); - final scenario1 = new ScenarioRunnable("Scenario: 1", emptyDebuggable) + final scenario1 = ScenarioRunnable("Scenario: 1", emptyDebuggable) ..steps.add(step); - final scenario2 = new ScenarioRunnable("Scenario: 2", emptyDebuggable) + final scenario2 = ScenarioRunnable("Scenario: 2", emptyDebuggable) ..steps.add(step); - final feature = new FeatureRunnable("1", emptyDebuggable) + final feature = FeatureRunnable("1", emptyDebuggable) ..scenarios.add(scenario1) ..scenarios.add(scenario2); - final featureFile = new FeatureFile(emptyDebuggable) - ..features.add(feature); + final featureFile = FeatureFile(emptyDebuggable)..features.add(feature); await runner.run(featureFile); expect(hookMock.onBeforeScenarioInvocationCount, 2); expect(hookMock.onAfterScenarioInvocationCount, 2); @@ -232,27 +226,26 @@ void main() { () async { final reporterMock = ReporterMock(); final stepDefiniton = MockStepDefinition(); - final executableStep = new ExectuableStep( - MockGherkinExpression((_) => true), stepDefiniton); - final runner = new FeatureFileRunner( + final executableStep = + ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton); + final runner = FeatureFileRunner( TestConfiguration(), MockTagExpressionEvaluator(), [executableStep], reporterMock, HookMock()); - final step = new StepRunnable( + final step = StepRunnable( "Step 1", RunnableDebugInformation("", 0, "Given I do a")); - final scenario1 = new ScenarioRunnable("Scenario: 1", emptyDebuggable) + final scenario1 = ScenarioRunnable("Scenario: 1", emptyDebuggable) ..steps.add(step); - final scenario2 = new ScenarioRunnable("Scenario: 2", emptyDebuggable) + final scenario2 = ScenarioRunnable("Scenario: 2", emptyDebuggable) ..steps.add(step) ..steps.add(step); - final feature = new FeatureRunnable("1", emptyDebuggable) + final feature = FeatureRunnable("1", emptyDebuggable) ..scenarios.add(scenario1) ..scenarios.add(scenario2); - final featureFile = new FeatureFile(emptyDebuggable) - ..features.add(feature); + final featureFile = FeatureFile(emptyDebuggable)..features.add(feature); await runner.run(featureFile); expect(reporterMock.onFeatureStartedInvocationCount, 1); expect(reporterMock.onFeatureFinishedInvocationCount, 1); @@ -269,23 +262,22 @@ void main() { final reporterMock = ReporterMock(); reporterMock.onStepFinishedFn = (message) => finishedMessage = message; final stepDefiniton = MockStepDefinition(); - final executableStep = new ExectuableStep( - MockGherkinExpression((_) => true), stepDefiniton); - final runner = new FeatureFileRunner( + final executableStep = + ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton); + final runner = FeatureFileRunner( TestConfiguration(), MockTagExpressionEvaluator(), [executableStep], reporterMock, HookMock()); - final step = new StepRunnable( + final step = StepRunnable( "Step 1", RunnableDebugInformation("", 0, "Given I do a")); - final scenario1 = new ScenarioRunnable("Scenario: 1", emptyDebuggable) + final scenario1 = ScenarioRunnable("Scenario: 1", emptyDebuggable) ..steps.add(step); - final feature = new FeatureRunnable("1", emptyDebuggable) + final feature = FeatureRunnable("1", emptyDebuggable) ..scenarios.add(scenario1); - final featureFile = new FeatureFile(emptyDebuggable) - ..features.add(feature); + final featureFile = FeatureFile(emptyDebuggable)..features.add(feature); await runner.run(featureFile); expect(stepDefiniton.hasRun, true); expect(finishedMessage, (m) => m.name == "Step 1"); @@ -300,23 +292,22 @@ void main() { reporterMock.onStepFinishedFn = (message) => finishedMessage = message; final stepDefiniton = MockStepDefinition((_) => throw testFailureException); - final executableStep = new ExectuableStep( - MockGherkinExpression((_) => true), stepDefiniton); - final runner = new FeatureFileRunner( + final executableStep = + ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton); + final runner = FeatureFileRunner( TestConfiguration(), MockTagExpressionEvaluator(), [executableStep], reporterMock, HookMock()); - final step = new StepRunnable( + final step = StepRunnable( "Step 1", RunnableDebugInformation("", 0, "Given I do a")); - final scenario1 = new ScenarioRunnable("Scenario: 1", emptyDebuggable) + final scenario1 = ScenarioRunnable("Scenario: 1", emptyDebuggable) ..steps.add(step); - final feature = new FeatureRunnable("1", emptyDebuggable) + final feature = FeatureRunnable("1", emptyDebuggable) ..scenarios.add(scenario1); - final featureFile = new FeatureFile(emptyDebuggable) - ..features.add(feature); + final featureFile = FeatureFile(emptyDebuggable)..features.add(feature); await runner.run(featureFile); expect(stepDefiniton.hasRun, true); expect(finishedMessage, (m) => m.name == "Step 1"); @@ -332,23 +323,22 @@ void main() { reporterMock.onStepFinishedFn = (message) => finishedMessage = message; final stepDefiniton = MockStepDefinition( (_) async => await Future.delayed(Duration(seconds: 2))); - final executableStep = new ExectuableStep( - MockGherkinExpression((_) => true), stepDefiniton); - final runner = new FeatureFileRunner( + final executableStep = + ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton); + final runner = FeatureFileRunner( TestConfiguration()..defaultTimeout = Duration(milliseconds: 1), MockTagExpressionEvaluator(), [executableStep], reporterMock, HookMock()); - final step = new StepRunnable( + final step = StepRunnable( "Step 1", RunnableDebugInformation("", 0, "Given I do a")); - final scenario1 = new ScenarioRunnable("Scenario: 1", emptyDebuggable) + final scenario1 = ScenarioRunnable("Scenario: 1", emptyDebuggable) ..steps.add(step); - final feature = new FeatureRunnable("1", emptyDebuggable) + final feature = FeatureRunnable("1", emptyDebuggable) ..scenarios.add(scenario1); - final featureFile = new FeatureFile(emptyDebuggable) - ..features.add(feature); + final featureFile = FeatureFile(emptyDebuggable)..features.add(feature); await runner.run(featureFile); expect(stepDefiniton.hasRun, true); expect(finishedMessage, (m) => m.name == "Step 1"); @@ -357,7 +347,7 @@ void main() { }); test("skipped step reported correctly", () async { - final finishedMessages = List(); + final finishedMessages = []; final reporterMock = ReporterMock(); reporterMock.onStepFinishedFn = (message) => finishedMessages.add(message); @@ -365,37 +355,36 @@ void main() { final stepTextOne = "Given I do a"; final stepTextTwo = "Given I do b"; final stepTextThree = "Given I do c"; - final stepDefiniton = MockStepDefinition((_) => throw new Exception()); + final stepDefiniton = MockStepDefinition((_) => throw Exception()); final stepDefinitonTwo = MockStepDefinition(); final stepDefinitonThree = MockStepDefinition(); - final executableStep = new ExectuableStep( + final executableStep = ExectuableStep( MockGherkinExpression((s) => s == stepTextOne), stepDefiniton); - final executableStepTwo = new ExectuableStep( + final executableStepTwo = ExectuableStep( MockGherkinExpression((s) => s == stepTextTwo), stepDefinitonTwo); - final executableStepThree = new ExectuableStep( + final executableStepThree = ExectuableStep( MockGherkinExpression((s) => s == stepTextThree), stepDefinitonThree); - final runner = new FeatureFileRunner( + final runner = FeatureFileRunner( TestConfiguration()..defaultTimeout = Duration(milliseconds: 1), MockTagExpressionEvaluator(), [executableStep, executableStepTwo, executableStepThree], reporterMock, HookMock()); - final step = new StepRunnable( + final step = StepRunnable( "Step 1", RunnableDebugInformation("", 0, stepTextOne)); - final stepTwo = new StepRunnable( + final stepTwo = StepRunnable( "Step 2", RunnableDebugInformation("", 0, stepTextTwo)); - final stepThree = new StepRunnable( + final stepThree = StepRunnable( "Step 3", RunnableDebugInformation("", 0, stepTextThree)); - final scenario1 = new ScenarioRunnable("Scenario: 1", emptyDebuggable) + final scenario1 = ScenarioRunnable("Scenario: 1", emptyDebuggable) ..steps.add(step) ..steps.add(stepTwo) ..steps.add(stepThree); - final feature = new FeatureRunnable("1", emptyDebuggable) + final feature = FeatureRunnable("1", emptyDebuggable) ..scenarios.add(scenario1); - final featureFile = new FeatureFile(emptyDebuggable) - ..features.add(feature); + final featureFile = FeatureFile(emptyDebuggable)..features.add(feature); await runner.run(featureFile); expect(stepDefiniton.hasRun, true); expect(finishedMessages.length, 3); diff --git a/test/gherkin/expressions/gherkin_expression.dart b/test/gherkin/expressions/gherkin_expression.dart index b32dc90..b8e48fb 100644 --- a/test/gherkin/expressions/gherkin_expression.dart +++ b/test/gherkin/expressions/gherkin_expression.dart @@ -9,7 +9,7 @@ import 'package:test/test.dart'; void main() { group("GherkinExpression", () { test('parse simple regex expression correctly', () async { - final parser = new GherkinExpression(RegExp('I (open|close) the drawer'), + final parser = GherkinExpression(RegExp('I (open|close) the drawer'), [WordParameterLower(), WordParameterCamel()]); expect(parser.isMatch("I open the drawer"), equals(true)); @@ -20,7 +20,7 @@ void main() { test('parse complex regex with custom parameters expression correctly', () async { - final parser = new GherkinExpression( + final parser = GherkinExpression( RegExp( 'I (open|close) the drawer {int} time(s) and find {word} which is (good|bad)'), [WordParameterLower(), IntParameterLower(), PluralParameter()]); @@ -44,7 +44,7 @@ void main() { }); test('parse simple {word} expression correctly', () async { - final parser = new GherkinExpression(RegExp('I am {word} as {Word}'), + final parser = GherkinExpression(RegExp('I am {word} as {Word}'), [WordParameterLower(), WordParameterCamel()]); expect(parser.isMatch("I am 'happy'"), equals(false)); @@ -54,8 +54,8 @@ void main() { }); test('parse simple {string} expression correctly', () async { - final parser = new GherkinExpression( - RegExp('I am {string}'), [StringParameterLower()]); + final parser = + GherkinExpression(RegExp('I am {string}'), [StringParameterLower()]); expect(parser.isMatch("I am 'happy as Larry'"), equals(true)); expect(parser.getParameters("I am 'happy as Larry'"), @@ -63,7 +63,7 @@ void main() { }); test('parse simple {int} expression correctly', () async { - final parser = new GherkinExpression( + final parser = GherkinExpression( RegExp('I am {int} years and {Int} days old'), [IntParameterLower(), IntParameterCamel()]); @@ -73,7 +73,7 @@ void main() { }); test('parse simple {float} expression correctly', () async { - final parser = new GherkinExpression( + final parser = GherkinExpression( RegExp('I am {float} years and {Float} days old'), [FloatParameterLower(), FloatParameterCamel()]); @@ -84,7 +84,7 @@ void main() { }); test('parse simple plural (s) expression correctly', () async { - final parser = new GherkinExpression( + final parser = GherkinExpression( RegExp('I have {int} cucumber(s) in my belly'), [IntParameterLower(), PluralParameter()]); @@ -97,7 +97,7 @@ void main() { }); test('parse complex expression correctly', () async { - final parser = new GherkinExpression( + final parser = GherkinExpression( RegExp( '{word} {int} {string} {int} (jon|laurie) {float} {word} {float} cucumber(s)'), [ diff --git a/test/gherkin/expressions/tag_expression.dart b/test/gherkin/expressions/tag_expression.dart index b6a580b..a80f503 100644 --- a/test/gherkin/expressions/tag_expression.dart +++ b/test/gherkin/expressions/tag_expression.dart @@ -4,7 +4,7 @@ import "package:test/test.dart"; void main() { group("TagExpression", () { test("evaluate simple single tag expression correctly", () async { - final evaluator = new TagExpressionEvaluator(); + final evaluator = TagExpressionEvaluator(); final tags = ["a", "b", "c"]; expect(evaluator.evaluate("@a", tags), true); @@ -13,7 +13,7 @@ void main() { }); test("evaluate complex and tag expression correctly", () async { - final evaluator = new TagExpressionEvaluator(); + final evaluator = TagExpressionEvaluator(); final tags = ["a", "b", "c"]; expect(evaluator.evaluate("@a and @d", tags), false); @@ -22,7 +22,7 @@ void main() { }); test("evaluate complex or tag expression correctly", () async { - final evaluator = new TagExpressionEvaluator(); + final evaluator = TagExpressionEvaluator(); final tags = ["a", "b", "c"]; expect(evaluator.evaluate("(@a or @b)", tags), true); @@ -31,7 +31,7 @@ void main() { }); test("evaluate complex bracket tag expression correctly", () async { - final evaluator = new TagExpressionEvaluator(); + final evaluator = TagExpressionEvaluator(); final tags = ["a", "b", "c"]; expect(evaluator.evaluate("@a or (@b and @c)", tags), true); diff --git a/test/gherkin/parser_test.dart b/test/gherkin/parser_test.dart index a7c947a..31bfef2 100644 --- a/test/gherkin/parser_test.dart +++ b/test/gherkin/parser_test.dart @@ -6,7 +6,7 @@ import '../mocks/reporter_mock.dart'; void main() { group("parse", () { test('parses simple, single scenario correctly', () async { - final parser = new GherkinParser(); + final parser = GherkinParser(); final featureContents = """ # language: en Feature: The name of the feature @@ -30,7 +30,7 @@ void main() { When I do step c Then I expect to see d """; - FeatureFile featureFile = + final FeatureFile featureFile = await parser.parseFeatureFile(featureContents, "", ReporterMock()); expect(featureFile, isNot(null)); expect(featureFile.langauge, equals("en")); @@ -66,7 +66,7 @@ void main() { }); test('parses complex multi-scenario correctly', () async { - final parser = new GherkinParser(); + final parser = GherkinParser(); final featureContents = """ # language: en Feature: The name of the feature @@ -97,7 +97,7 @@ void main() { # When I do step c.1 Then I expect to see d """; - FeatureFile featureFile = + final FeatureFile featureFile = await parser.parseFeatureFile(featureContents, "", ReporterMock()); expect(featureFile, isNot(null)); expect(featureFile.langauge, equals("en")); diff --git a/test/gherkin/runnables/feature_file_test.dart b/test/gherkin/runnables/feature_file_test.dart index 575c92c..d240b0c 100644 --- a/test/gherkin/runnables/feature_file_test.dart +++ b/test/gherkin/runnables/feature_file_test.dart @@ -8,12 +8,12 @@ void main() { final debugInfo = RunnableDebugInformation(null, 0, null); group("addChild", () { test('can add LangaugeRunnable', () { - final runnable = new FeatureFile(debugInfo); + final runnable = FeatureFile(debugInfo); runnable.addChild(LanguageRunnable(debugInfo)..language = "en"); expect(runnable.langauge, "en"); }); test('can add TagsRunnable', () { - final runnable = new FeatureFile(debugInfo); + final runnable = FeatureFile(debugInfo); runnable.addChild(FeatureRunnable("1", debugInfo)); runnable.addChild(FeatureRunnable("2", debugInfo)); runnable.addChild(FeatureRunnable("3", debugInfo)); diff --git a/test/gherkin/runnables/feature_test.dart b/test/gherkin/runnables/feature_test.dart index bff54e5..2235fdc 100644 --- a/test/gherkin/runnables/feature_test.dart +++ b/test/gherkin/runnables/feature_test.dart @@ -12,27 +12,27 @@ void main() { final debugInfo = RunnableDebugInformation(null, 0, null); group("addChild", () { test('can add TextLineRunnable', () { - final runnable = new FeatureRunnable("", debugInfo); + final runnable = FeatureRunnable("", debugInfo); runnable.addChild(TextLineRunnable(debugInfo)..text = "text"); runnable.addChild(TextLineRunnable(debugInfo)..text = "text line two"); expect(runnable.description, "text\ntext line two"); }); test('can add TagsRunnable', () { - final runnable = new FeatureRunnable("", debugInfo); + final runnable = FeatureRunnable("", debugInfo); runnable.addChild(TagsRunnable(debugInfo)..tags = ["one", "two"]); runnable.addChild(TagsRunnable(debugInfo)..tags = ["three"]); expect(runnable.tags, ["one", "two", "three"]); }); test('can add EmptyLineRunnable', () { - final runnable = new FeatureRunnable("", debugInfo); + final runnable = FeatureRunnable("", debugInfo); runnable.addChild(EmptyLineRunnable(debugInfo)); }); test('can add CommentLineRunnable', () { - final runnable = new FeatureRunnable("", debugInfo); + final runnable = FeatureRunnable("", debugInfo); runnable.addChild(CommentLineRunnable("", debugInfo)); }); test('can add ScenarioRunnable', () { - final runnable = new FeatureRunnable("", debugInfo); + final runnable = FeatureRunnable("", debugInfo); runnable.addChild(ScenarioRunnable("1", debugInfo)); runnable.addChild(ScenarioRunnable("2", debugInfo)); runnable.addChild(ScenarioRunnable("3", debugInfo)); @@ -42,7 +42,7 @@ void main() { expect(runnable.scenarios.elementAt(2).name, "3"); }); test('can add BackgroundRunnable', () { - final runnable = new FeatureRunnable("", debugInfo); + final runnable = FeatureRunnable("", debugInfo); runnable.addChild(BackgroundRunnable("1", debugInfo)); expect(runnable.background, isNotNull); expect(runnable.background.name, "1"); diff --git a/test/gherkin/runnables/multi_line_string_test.dart b/test/gherkin/runnables/multi_line_string_test.dart index 21eb7bd..73e1bf6 100644 --- a/test/gherkin/runnables/multi_line_string_test.dart +++ b/test/gherkin/runnables/multi_line_string_test.dart @@ -8,11 +8,11 @@ void main() { final debugInfo = RunnableDebugInformation(null, 0, null); group("addChild", () { test('can add EmptyLineRunnable', () { - final runnable = new MultilineStringRunnable(debugInfo); + final runnable = MultilineStringRunnable(debugInfo); runnable.addChild(EmptyLineRunnable(debugInfo)); }); test('can add TextLineRunnable', () { - final runnable = new MultilineStringRunnable(debugInfo); + final runnable = MultilineStringRunnable(debugInfo); runnable.addChild(TextLineRunnable(debugInfo)..text = "1"); runnable.addChild(TextLineRunnable(debugInfo)..text = "2"); runnable.addChild(TextLineRunnable(debugInfo)..text = "3"); diff --git a/test/gherkin/runnables/scenario_test.dart b/test/gherkin/runnables/scenario_test.dart index a3ba89f..a581e33 100644 --- a/test/gherkin/runnables/scenario_test.dart +++ b/test/gherkin/runnables/scenario_test.dart @@ -9,11 +9,11 @@ void main() { final debugInfo = RunnableDebugInformation(null, 0, null); group("addChild", () { test('can add EmptyLineRunnable', () { - final runnable = new ScenarioRunnable("", debugInfo); + final runnable = ScenarioRunnable("", debugInfo); runnable.addChild(EmptyLineRunnable(debugInfo)); }); test('can add StepRunnable', () { - final runnable = new ScenarioRunnable("", debugInfo); + final runnable = ScenarioRunnable("", debugInfo); runnable.addChild(StepRunnable("1", debugInfo)); runnable.addChild(StepRunnable("2", debugInfo)); runnable.addChild(StepRunnable("3", debugInfo)); @@ -23,7 +23,7 @@ void main() { expect(runnable.steps.elementAt(2).name, "3"); }); test('can add TagsRunnable', () { - final runnable = new ScenarioRunnable("", debugInfo); + final runnable = ScenarioRunnable("", debugInfo); runnable.addChild(TagsRunnable(debugInfo)..tags = ["one", "two"]); runnable.addChild(TagsRunnable(debugInfo)..tags = ["three"]); expect(runnable.tags, ["one", "two", "three"]); diff --git a/test/gherkin/runnables/step_test.dart b/test/gherkin/runnables/step_test.dart index f53198f..c33ecbc 100644 --- a/test/gherkin/runnables/step_test.dart +++ b/test/gherkin/runnables/step_test.dart @@ -9,7 +9,7 @@ void main() { final debugInfo = RunnableDebugInformation(null, 0, null); group("addChild", () { test('can add MultilineStringRunnable', () { - final runnable = new StepRunnable("", debugInfo); + final runnable = StepRunnable("", debugInfo); runnable.addChild( MultilineStringRunnable(debugInfo)..lines = ["1", "2", "3"].toList()); runnable.addChild( @@ -20,7 +20,7 @@ void main() { }); test('can add TableRunnable', () { - final runnable = new StepRunnable("", debugInfo); + final runnable = StepRunnable("", debugInfo); runnable.addChild(TableRunnable(debugInfo) ..addChild(TableRunnable(debugInfo)..rows.add("|Col A|Col B|")) ..addChild(TableRunnable(debugInfo)..rows.add("|1|2|")) @@ -33,7 +33,7 @@ void main() { }); test('can only add single TableRunnable', () { - final runnable = new StepRunnable("Step A", debugInfo); + final runnable = StepRunnable("Step A", debugInfo); runnable.addChild(TableRunnable(debugInfo) ..addChild(TableRunnable(debugInfo)..rows.add("|Col A|Col B|")) ..addChild(TableRunnable(debugInfo)..rows.add("|1|2|")) diff --git a/test/gherkin/runnables/table_test.dart b/test/gherkin/runnables/table_test.dart index f682f4b..b7b7b45 100644 --- a/test/gherkin/runnables/table_test.dart +++ b/test/gherkin/runnables/table_test.dart @@ -7,11 +7,11 @@ void main() { final debugInfo = RunnableDebugInformation(null, 0, null); group("addChild", () { test('can add CommentLineRunnable', () { - final runnable = new TableRunnable(debugInfo); + final runnable = TableRunnable(debugInfo); runnable.addChild(CommentLineRunnable("", debugInfo)); }); test('can add TableRunnable', () { - final runnable = new TableRunnable(debugInfo); + final runnable = TableRunnable(debugInfo); runnable.addChild( TableRunnable(debugInfo)..rows.add("| Header 1 | Header 2 |")); runnable.addChild(TableRunnable(debugInfo)..rows.add("| 1 | 2 |")); @@ -24,7 +24,7 @@ void main() { group("to table", () { test("single row table has no header row", () async { - final runnable = new TableRunnable(debugInfo); + final runnable = TableRunnable(debugInfo); runnable.addChild( TableRunnable(debugInfo)..rows.add("| one | two | three |")); final table = runnable.toTable(); @@ -34,7 +34,7 @@ void main() { }); test("two row table has header row", () async { - final runnable = new TableRunnable(debugInfo); + final runnable = TableRunnable(debugInfo); runnable.addChild(TableRunnable(debugInfo) ..rows.add("| header one | header two | header three |")); runnable.addChild( @@ -48,7 +48,7 @@ void main() { }); test("three row table has header row and correct rows", () async { - final runnable = new TableRunnable(debugInfo); + final runnable = TableRunnable(debugInfo); runnable.addChild(TableRunnable(debugInfo) ..rows.add("| header one | header two | header three |")); runnable.addChild( @@ -65,7 +65,7 @@ void main() { }); test("table removes columns leading and trailing spaces", () async { - final runnable = new TableRunnable(debugInfo); + final runnable = TableRunnable(debugInfo); runnable.addChild(TableRunnable(debugInfo) ..rows.add("| header one | header two | header three |")); runnable.addChild(TableRunnable(debugInfo) diff --git a/test/gherkin/steps/step_definition_test.dart b/test/gherkin/steps/step_definition_test.dart index 1ce6381..1aaee7c 100644 --- a/test/gherkin/steps/step_definition_test.dart +++ b/test/gherkin/steps/step_definition_test.dart @@ -34,12 +34,12 @@ void main() { final step = StepDefinitionMock(StepDefinitionConfiguration(), 2); expect( () async => await step.run( - null, null, Duration(seconds: 1), Iterable.empty()), + null, null, Duration(seconds: 1), const Iterable.empty()), throwsA((e) => e is GherkinStepParameterMismatchException && e.message == - "StepDefinitionMock parameter count mismatch. Expect 2 parameters but got 0. " + - "Ensure you are extending the correct step class which would be Given")); + "StepDefinitionMock parameter count mismatch. Expect 2 parameters but got 0. " + "Ensure you are extending the correct step class which would be Given")); expect(step.invocationCount, 0); }); @@ -52,8 +52,8 @@ void main() { throwsA((e) => e is GherkinStepParameterMismatchException && e.message == - "StepDefinitionMock parameter count mismatch. Expect 2 parameters but got 1. " + - "Ensure you are extending the correct step class which would be Given1")); + "StepDefinitionMock parameter count mismatch. Expect 2 parameters but got 1. " + "Ensure you are extending the correct step class which would be Given1")); expect(step.invocationCount, 0); }); @@ -71,7 +71,8 @@ void main() { StepDefinitionConfiguration(), 0, () async => throw Exception("1")); expect( await step.run( - null, null, Duration(milliseconds: 1), Iterable.empty()), (r) { + null, null, Duration(milliseconds: 1), const Iterable.empty()), + (r) { return r is ErroredStepResult && r.result == StepExecutionResult.error && r.exception is Exception && @@ -86,7 +87,8 @@ void main() { () async => throw TestFailure("1")); expect( await step.run( - null, null, Duration(milliseconds: 1), Iterable.empty()), (r) { + null, null, Duration(milliseconds: 1), const Iterable.empty()), + (r) { return r is StepResult && r.result == StepExecutionResult.fail && r.resultReason == "1"; diff --git a/test/gherkin/syntax/background_syntax_test.dart b/test/gherkin/syntax/background_syntax_test.dart index 5d87699..6231741 100644 --- a/test/gherkin/syntax/background_syntax_test.dart +++ b/test/gherkin/syntax/background_syntax_test.dart @@ -7,13 +7,13 @@ import 'package:test/test.dart'; void main() { group("isMatch", () { test('matches correctly', () { - final syntax = new BackgroundSyntax(); + final syntax = BackgroundSyntax(); expect(syntax.isMatch("Background: something"), true); expect(syntax.isMatch(" Background: something"), true); }); test('does not match', () { - final syntax = new BackgroundSyntax(); + final syntax = BackgroundSyntax(); expect(syntax.isMatch("Background something"), false); expect(syntax.isMatch("#Background: something"), false); }); @@ -21,8 +21,8 @@ void main() { group("toRunnable", () { test('creates BackgroundRunnable', () { - final syntax = new BackgroundSyntax(); - Runnable runnable = syntax.toRunnable("Background: A backgroun 123", + final syntax = BackgroundSyntax(); + final Runnable runnable = syntax.toRunnable("Background: A backgroun 123", RunnableDebugInformation(null, 0, null)); expect(runnable, isNotNull); expect(runnable, predicate((x) => x is BackgroundRunnable)); diff --git a/test/gherkin/syntax/comment_syntax_test.dart b/test/gherkin/syntax/comment_syntax_test.dart index 76d8215..ee7a7ca 100644 --- a/test/gherkin/syntax/comment_syntax_test.dart +++ b/test/gherkin/syntax/comment_syntax_test.dart @@ -4,7 +4,7 @@ import 'package:test/test.dart'; void main() { group("isMatch", () { test('matches correctly', () { - final keyword = new CommentSyntax(); + final keyword = CommentSyntax(); expect(keyword.isMatch("# I am a comment"), true); expect(keyword.isMatch("#I am also a comment"), true); expect(keyword.isMatch("## I am also a comment"), true); @@ -12,7 +12,7 @@ void main() { }); test('does not match', () { - final keyword = new CommentSyntax(); + final keyword = CommentSyntax(); // expect(keyword.isMatch("# language: en"), false); expect(keyword.isMatch("I am not a comment"), false); }); diff --git a/test/gherkin/syntax/empty_line_syntax_test.dart b/test/gherkin/syntax/empty_line_syntax_test.dart index 0eb096e..51a1420 100644 --- a/test/gherkin/syntax/empty_line_syntax_test.dart +++ b/test/gherkin/syntax/empty_line_syntax_test.dart @@ -4,7 +4,7 @@ import 'package:test/test.dart'; void main() { group("isMatch", () { test('matches correctly', () { - final keyword = new EmptyLineSyntax(); + final keyword = EmptyLineSyntax(); expect(keyword.isMatch(""), true); expect(keyword.isMatch(" "), true); expect(keyword.isMatch(" "), true); @@ -12,7 +12,7 @@ void main() { }); test('does not match', () { - final keyword = new EmptyLineSyntax(); + final keyword = EmptyLineSyntax(); expect(keyword.isMatch("a"), false); expect(keyword.isMatch(" b"), false); expect(keyword.isMatch(" c"), false); diff --git a/test/gherkin/syntax/feature_syntax_test.dart b/test/gherkin/syntax/feature_syntax_test.dart index 6a5d997..24bfcb4 100644 --- a/test/gherkin/syntax/feature_syntax_test.dart +++ b/test/gherkin/syntax/feature_syntax_test.dart @@ -7,13 +7,13 @@ import 'package:test/test.dart'; void main() { group("isMatch", () { test('matches correctly', () { - final keyword = new FeatureSyntax(); + final keyword = FeatureSyntax(); expect(keyword.isMatch("Feature: one"), true); expect(keyword.isMatch("Feature:one"), true); }); test('does not match', () { - final keyword = new FeatureSyntax(); + final keyword = FeatureSyntax(); expect(keyword.isMatch("#Feature: no"), false); expect(keyword.isMatch("# Feature no"), false); }); @@ -21,8 +21,8 @@ void main() { group("toRunnable", () { test('creates FeatureRunnable', () { - final keyword = new FeatureSyntax(); - Runnable runnable = keyword.toRunnable( + final keyword = FeatureSyntax(); + final Runnable runnable = keyword.toRunnable( "Feature: A feature 123", RunnableDebugInformation(null, 0, null)); expect(runnable, isNotNull); expect(runnable, predicate((x) => x is FeatureRunnable)); diff --git a/test/gherkin/syntax/language_syntax_test.dart b/test/gherkin/syntax/language_syntax_test.dart index 6aed3e6..af91674 100644 --- a/test/gherkin/syntax/language_syntax_test.dart +++ b/test/gherkin/syntax/language_syntax_test.dart @@ -6,14 +6,14 @@ import 'package:test/test.dart'; void main() { group("isMatch", () { test('matches correctly', () { - final keyword = new LanguageSyntax(); + final keyword = LanguageSyntax(); expect(keyword.isMatch("# language: en"), true); expect(keyword.isMatch("#language: fr"), true); expect(keyword.isMatch("#language:de"), true); }); test('does not match', () { - final keyword = new LanguageSyntax(); + final keyword = LanguageSyntax(); expect(keyword.isMatch("#language no"), false); expect(keyword.isMatch("# language comment"), false); }); @@ -21,8 +21,8 @@ void main() { group("toRunnable", () { test('creates LanguageRunnable', () { - final keyword = new LanguageSyntax(); - LanguageRunnable runnable = keyword.toRunnable( + final keyword = LanguageSyntax(); + final LanguageRunnable runnable = keyword.toRunnable( "# language: de", RunnableDebugInformation(null, 0, null)); expect(runnable, isNotNull); expect(runnable, predicate((x) => x is LanguageRunnable)); diff --git a/test/gherkin/syntax/multiline_string_syntax_test.dart b/test/gherkin/syntax/multiline_string_syntax_test.dart index 9b2b4d8..f72a3bc 100644 --- a/test/gherkin/syntax/multiline_string_syntax_test.dart +++ b/test/gherkin/syntax/multiline_string_syntax_test.dart @@ -8,14 +8,14 @@ import 'package:test/test.dart'; void main() { group("isMatch", () { test('matches correctly', () { - final syntax = new MultilineStringSyntax(); + final syntax = MultilineStringSyntax(); expect(syntax.isMatch('"""'), true); expect(syntax.isMatch('```'), true); expect(syntax.isMatch("'''"), true); }); test('does not match', () { - final syntax = new MultilineStringSyntax(); + final syntax = MultilineStringSyntax(); expect(syntax.isMatch('#"""'), false); expect(syntax.isMatch('#```'), false); expect(syntax.isMatch("#'''"), false); @@ -26,30 +26,30 @@ void main() { }); group("block", () { test("is block", () { - final syntax = new MultilineStringSyntax(); + final syntax = MultilineStringSyntax(); expect(syntax.isBlockSyntax, true); }); test("continue block if text line string", () { - final syntax = new MultilineStringSyntax(); - expect(syntax.hasBlockEnded(new TextLineSyntax()), false); + final syntax = MultilineStringSyntax(); + expect(syntax.hasBlockEnded(TextLineSyntax()), false); }); test("continue block if comment string", () { - final syntax = new MultilineStringSyntax(); - expect(syntax.hasBlockEnded(new CommentSyntax()), false); + final syntax = MultilineStringSyntax(); + expect(syntax.hasBlockEnded(CommentSyntax()), false); }); test("end block if multiline string", () { - final syntax = new MultilineStringSyntax(); - expect(syntax.hasBlockEnded(new MultilineStringSyntax()), true); + final syntax = MultilineStringSyntax(); + expect(syntax.hasBlockEnded(MultilineStringSyntax()), true); }); }); group("toRunnable", () { test('creates TextLineRunnable', () { - final syntax = new MultilineStringSyntax(); - MultilineStringRunnable runnable = + final syntax = MultilineStringSyntax(); + final MultilineStringRunnable runnable = syntax.toRunnable("'''", RunnableDebugInformation(null, 0, null)); expect(runnable, isNotNull); expect(runnable, predicate((x) => x is MultilineStringRunnable)); diff --git a/test/gherkin/syntax/scenario_syntax_test.dart b/test/gherkin/syntax/scenario_syntax_test.dart index 6521b2f..82f4aba 100644 --- a/test/gherkin/syntax/scenario_syntax_test.dart +++ b/test/gherkin/syntax/scenario_syntax_test.dart @@ -7,13 +7,13 @@ import 'package:test/test.dart'; void main() { group("isMatch", () { test('matches correctly', () { - final syntax = new ScenarioSyntax(); + final syntax = ScenarioSyntax(); expect(syntax.isMatch("Scenario: something"), true); expect(syntax.isMatch(" Scenario: something"), true); }); test('does not match', () { - final syntax = new ScenarioSyntax(); + final syntax = ScenarioSyntax(); expect(syntax.isMatch("Scenario something"), false); expect(syntax.isMatch("#Scenario: something"), false); }); @@ -21,8 +21,8 @@ void main() { group("toRunnable", () { test('creates FeatureRunnable', () { - final keyword = new ScenarioSyntax(); - Runnable runnable = keyword.toRunnable( + final keyword = ScenarioSyntax(); + final Runnable runnable = keyword.toRunnable( "Scenario: A scenario 123", RunnableDebugInformation(null, 0, null)); expect(runnable, isNotNull); expect(runnable, predicate((x) => x is ScenarioRunnable)); diff --git a/test/gherkin/syntax/step_syntax_test.dart b/test/gherkin/syntax/step_syntax_test.dart index d45049c..8bbad89 100644 --- a/test/gherkin/syntax/step_syntax_test.dart +++ b/test/gherkin/syntax/step_syntax_test.dart @@ -8,67 +8,67 @@ import 'package:test/test.dart'; void main() { group("isMatch", () { test('matches given correctly', () { - final syntax = new StepSyntax(); + final syntax = StepSyntax(); expect(syntax.isMatch("Given a step"), true); expect(syntax.isMatch("given a step"), true); }); test('matches then correctly', () { - final syntax = new StepSyntax(); + final syntax = StepSyntax(); expect(syntax.isMatch("Then a step"), true); expect(syntax.isMatch("then a step"), true); }); test('matches when correctly', () { - final syntax = new StepSyntax(); + final syntax = StepSyntax(); expect(syntax.isMatch("When I do something"), true); expect(syntax.isMatch("when I do something"), true); }); test('matches and correctly', () { - final syntax = new StepSyntax(); + final syntax = StepSyntax(); expect(syntax.isMatch("And something"), true); expect(syntax.isMatch("and something"), true); }); test('matches but correctly', () { - final syntax = new StepSyntax(); + final syntax = StepSyntax(); expect(syntax.isMatch("but something"), true); expect(syntax.isMatch("but something"), true); }); test('does not match', () { - final syntax = new StepSyntax(); + final syntax = StepSyntax(); expect(syntax.isMatch("#given something"), false); }); }); group("block", () { test("is block", () { - final syntax = new StepSyntax(); + final syntax = StepSyntax(); expect(syntax.isBlockSyntax, true); }); test("continue block if multiline string", () { - final syntax = new StepSyntax(); - expect(syntax.hasBlockEnded(new MultilineStringSyntax()), false); + final syntax = StepSyntax(); + expect(syntax.hasBlockEnded(MultilineStringSyntax()), false); }); test("continue block if table", () { - final syntax = new StepSyntax(); - expect(syntax.hasBlockEnded(new TableLineSyntax()), false); + final syntax = StepSyntax(); + expect(syntax.hasBlockEnded(TableLineSyntax()), false); }); test("end block if not multiline string or table", () { - final syntax = new StepSyntax(); - expect(syntax.hasBlockEnded(new StepSyntax()), true); + final syntax = StepSyntax(); + expect(syntax.hasBlockEnded(StepSyntax()), true); }); }); group("toRunnable", () { test('creates StepRunnable', () { - final syntax = new StepSyntax(); - StepRunnable runnable = syntax.toRunnable( + final syntax = StepSyntax(); + final StepRunnable runnable = syntax.toRunnable( "Given I do something", RunnableDebugInformation(null, 0, null)); expect(runnable, isNotNull); expect(runnable, predicate((x) => x is StepRunnable)); diff --git a/test/gherkin/syntax/table_line_string_syntax_test.dart b/test/gherkin/syntax/table_line_string_syntax_test.dart index 22edb53..6167c8a 100644 --- a/test/gherkin/syntax/table_line_string_syntax_test.dart +++ b/test/gherkin/syntax/table_line_string_syntax_test.dart @@ -9,14 +9,14 @@ import 'package:test/test.dart'; void main() { group("isMatch", () { test('matches correctly', () { - final syntax = new TableLineSyntax(); + final syntax = TableLineSyntax(); expect(syntax.isMatch('||'), true); expect(syntax.isMatch(' | | '), true); expect(syntax.isMatch(" |a|b|c| "), true); }); test('does not match', () { - final syntax = new TableLineSyntax(); + final syntax = TableLineSyntax(); expect(syntax.isMatch('#||'), false); expect(syntax.isMatch(' | '), false); expect(syntax.isMatch(" |a|b|c "), false); @@ -25,57 +25,57 @@ void main() { group("block", () { test("is block", () { - final syntax = new TableLineSyntax(); + final syntax = TableLineSyntax(); expect(syntax.isBlockSyntax, true); }); test("continue block if table line string", () { - final syntax = new TableLineSyntax(); - expect(syntax.hasBlockEnded(new TableLineSyntax()), false); + final syntax = TableLineSyntax(); + expect(syntax.hasBlockEnded(TableLineSyntax()), false); }); test("continue block if comment string", () { - final syntax = new TableLineSyntax(); - expect(syntax.hasBlockEnded(new CommentSyntax()), false); + final syntax = TableLineSyntax(); + expect(syntax.hasBlockEnded(CommentSyntax()), false); }); test("end block if not table line string", () { - final syntax = new TableLineSyntax(); - expect(syntax.hasBlockEnded(new MultilineStringSyntax()), true); + final syntax = TableLineSyntax(); + expect(syntax.hasBlockEnded(MultilineStringSyntax()), true); }); }); group("block", () { test("is block", () { - final syntax = new TableLineSyntax(); + final syntax = TableLineSyntax(); expect(syntax.isBlockSyntax, true); }); test("continue block if table line", () { - final syntax = new TableLineSyntax(); - expect(syntax.hasBlockEnded(new TableLineSyntax()), false); + final syntax = TableLineSyntax(); + expect(syntax.hasBlockEnded(TableLineSyntax()), false); }); test("continue block if comment string", () { - final syntax = new TableLineSyntax(); - expect(syntax.hasBlockEnded(new CommentSyntax()), false); + final syntax = TableLineSyntax(); + expect(syntax.hasBlockEnded(CommentSyntax()), false); }); test("end block if step", () { - final syntax = new TableLineSyntax(); - expect(syntax.hasBlockEnded(new StepSyntax()), true); + final syntax = TableLineSyntax(); + expect(syntax.hasBlockEnded(StepSyntax()), true); }); test("end block if multiline string", () { - final syntax = new TableLineSyntax(); - expect(syntax.hasBlockEnded(new MultilineStringSyntax()), true); + final syntax = TableLineSyntax(); + expect(syntax.hasBlockEnded(MultilineStringSyntax()), true); }); }); group("toRunnable", () { test('creates TableRunnable', () { - final syntax = new TableLineSyntax(); - TableRunnable runnable = syntax.toRunnable( + final syntax = TableLineSyntax(); + final TableRunnable runnable = syntax.toRunnable( " | Row One | Row Two | ", RunnableDebugInformation(null, 0, null)); expect(runnable, isNotNull); expect(runnable, predicate((x) => x is TableRunnable)); diff --git a/test/gherkin/syntax/tag_syntax_test.dart b/test/gherkin/syntax/tag_syntax_test.dart index a407d73..5e88974 100644 --- a/test/gherkin/syntax/tag_syntax_test.dart +++ b/test/gherkin/syntax/tag_syntax_test.dart @@ -6,13 +6,13 @@ import 'package:test/test.dart'; void main() { group("isMatch", () { test('matches correctly', () { - final syntax = new TagSyntax(); + final syntax = TagSyntax(); expect(syntax.isMatch("@tagone @tagtow @tag_three"), true); expect(syntax.isMatch("@tag"), true); }); test('does not match', () { - final syntax = new TagSyntax(); + final syntax = TagSyntax(); expect(syntax.isMatch("not a tag"), false); expect(syntax.isMatch("#@tag @tag2"), false); }); @@ -20,8 +20,8 @@ void main() { group("toRunnable", () { test('creates TextLineRunnable', () { - final syntax = new TagSyntax(); - TagsRunnable runnable = syntax.toRunnable( + final syntax = TagSyntax(); + final TagsRunnable runnable = syntax.toRunnable( "@tag1 @tag2 @tag3@tag_4", RunnableDebugInformation(null, 0, null)); expect(runnable, isNotNull); expect(runnable, predicate((x) => x is TagsRunnable)); diff --git a/test/gherkin/syntax/text_line_syntax_test.dart b/test/gherkin/syntax/text_line_syntax_test.dart index 28625e8..88a514c 100644 --- a/test/gherkin/syntax/text_line_syntax_test.dart +++ b/test/gherkin/syntax/text_line_syntax_test.dart @@ -6,7 +6,7 @@ import 'package:test/test.dart'; void main() { group("isMatch", () { test('matches correctly', () { - final syntax = new TextLineSyntax(); + final syntax = TextLineSyntax(); expect(syntax.isMatch("Hello Jon"), true); expect(syntax.isMatch("Hello 'Jon'!"), true); expect(syntax.isMatch(" Hello Jon"), true); @@ -15,7 +15,7 @@ void main() { }); test('does not match', () { - final syntax = new TextLineSyntax(); + final syntax = TextLineSyntax(); expect(syntax.isMatch("#Hello Jon"), false); expect(syntax.isMatch("# Hello Jon"), false); expect(syntax.isMatch("# Hello Jon"), false); @@ -26,8 +26,8 @@ void main() { group("toRunnable", () { test('creates TextLineRunnable', () { - final syntax = new TextLineSyntax(); - TextLineRunnable runnable = syntax.toRunnable( + final syntax = TextLineSyntax(); + final TextLineRunnable runnable = syntax.toRunnable( " Some text ", RunnableDebugInformation(null, 0, null)); expect(runnable, isNotNull); expect(runnable, predicate((x) => x is TextLineRunnable)); diff --git a/test/hooks/aggregated_hook_test.dart b/test/hooks/aggregated_hook_test.dart index fdd6c93..984200f 100644 --- a/test/hooks/aggregated_hook_test.dart +++ b/test/hooks/aggregated_hook_test.dart @@ -5,7 +5,7 @@ import '../mocks/hook_mock.dart'; void main() { group("orders hooks", () { test("executes hooks in correct order", () async { - final executionOrder = List(); + final executionOrder = []; final hookOne = HookMock( providedPriority: 0, onBeforeRunCode: () => executionOrder.add(3)); final hookTwo = HookMock( diff --git a/test/mocks/gherkin_expression_mock.dart b/test/mocks/gherkin_expression_mock.dart index fd7b022..c727f9c 100644 --- a/test/mocks/gherkin_expression_mock.dart +++ b/test/mocks/gherkin_expression_mock.dart @@ -8,7 +8,7 @@ class MockGherkinExpression implements GherkinExpression { MockGherkinExpression(this.isMatchFn); @override - Iterable getParameters(String input) => Iterable.empty(); + Iterable getParameters(String input) => const Iterable.empty(); @override bool isMatch(String input) => isMatchFn(input); diff --git a/test/mocks/hook_mock.dart b/test/mocks/hook_mock.dart index ed3a2f5..52299ea 100644 --- a/test/mocks/hook_mock.dart +++ b/test/mocks/hook_mock.dart @@ -17,6 +17,7 @@ class HookMock extends Hook { HookMock({this.onBeforeRunCode, this.providedPriority = 0}); + @override Future onBeforeRun(TestConfiguration config) async { onBeforeRunInvocationCount += 1; if (onBeforeRunCode != null) { @@ -24,17 +25,21 @@ class HookMock extends Hook { } } + @override Future onAfterRun(TestConfiguration config) async => onAfterRunInvocationCount += 1; + @override Future onBeforeScenario( TestConfiguration config, String scenario) async => onBeforeScenarioInvocationCount += 1; + @override Future onAfterScenario( TestConfiguration config, String scenario) async => onAfterScenarioInvocationCount += 1; + @override Future onAfterScenarioWorldCreated( World world, String scenario) async => onAfterScenarioWorldCreatedInvocationCount += 1; diff --git a/test/mocks/reporter_mock.dart b/test/mocks/reporter_mock.dart index 6432b8f..1f7f914 100644 --- a/test/mocks/reporter_mock.dart +++ b/test/mocks/reporter_mock.dart @@ -17,27 +17,38 @@ class ReporterMock extends Reporter { OnStepFinished onStepFinishedFn; + @override Future onTestRunStarted() async => onTestRunStartedInvocationCount += 1; + @override Future onTestRunFinished() async => onTestRunfinishedInvocationCount += 1; + @override Future onFeatureStarted(StartedMessage message) async => onFeatureStartedInvocationCount += 1; + @override Future onFeatureFinished(FinishedMessage message) async => onFeatureFinishedInvocationCount += 1; + @override Future onScenarioStarted(StartedMessage message) async => onScenarioStartedInvocationCount += 1; + @override Future onScenarioFinished(FinishedMessage message) async => onScenarioFinishedInvocationCount += 1; + @override Future onStepStarted(StartedMessage message) async => onStepStartedInvocationCount += 1; + @override Future onStepFinished(StepFinishedMessage message) async { if (onStepFinishedFn != null) onStepFinishedFn(message); onStepFinishedInvocationCount += 1; } + @override Future onException(Exception exception, StackTrace stackTrace) async => onExceptionInvocationCount += 1; + @override Future message(String message, MessageLevel level) async => messageInvocationCount += 1; + @override Future dispose() async => disposeInvocationCount += 1; } diff --git a/test/mocks/step_definition_mock.dart b/test/mocks/step_definition_mock.dart index defac0f..e6fb51e 100644 --- a/test/mocks/step_definition_mock.dart +++ b/test/mocks/step_definition_mock.dart @@ -6,6 +6,7 @@ typedef Future OnRunCode(Iterable parameters); class MockStepDefinition extends StepDefinitionBase { bool hasRun = false; int runCount = 0; + @override final OnRunCode code; MockStepDefinition([this.code, int expectedParameterCount = 0]) diff --git a/test/reporters/progress_reporter_test.dart b/test/reporters/progress_reporter_test.dart index fc52d85..dc01066 100644 --- a/test/reporters/progress_reporter_test.dart +++ b/test/reporters/progress_reporter_test.dart @@ -4,7 +4,7 @@ import "package:flutter_gherkin/src/gherkin/steps/step_run_result.dart"; import "package:test/test.dart"; class TestableProgressReporter extends ProgressReporter { - final output = List(); + final output = []; @override void printMessageLine(String message, [String colour]) { output.add(message); @@ -39,8 +39,7 @@ void main() { expect(reporter.output, [ " √ Step 1 # filePath:1 took 0ms", - " × Step 2 # filePath:2 took 0ms \n" - " Failed Reason", + " × Step 2 # filePath:2 took 0ms \n Failed Reason", " - Step 3 # filePath:3 took 0ms", " × Step 4 # filePath:4 took 0ms", " × Step 5 # filePath:5 took 1ms" diff --git a/test/reporters/test_run_summary_reporter_test.dart b/test/reporters/test_run_summary_reporter_test.dart index 3b5d827..95d1072 100644 --- a/test/reporters/test_run_summary_reporter_test.dart +++ b/test/reporters/test_run_summary_reporter_test.dart @@ -3,7 +3,7 @@ import 'package:flutter_gherkin/src/gherkin/steps/step_run_result.dart'; import 'package:test/test.dart'; class TestableTestRunSummaryReporter extends TestRunSummaryReporter { - final output = List(); + final output = []; @override void printMessageLine(String message, [String colour]) { output.add(message);