chore(linting): update code to pass stricter linting rules

This commit is contained in:
Jon Samwell 2019-02-06 13:25:19 +11:00
parent 2ccdb80a29
commit 2aa36b5aa1
76 changed files with 482 additions and 343 deletions

View File

@ -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 ## [0.0.10] - 01/11/2018
* Ensured summary reporter reports failure reason * Ensured summary reporter reports failure reason

85
analysis_options.yaml Normal file
View File

@ -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

View File

@ -37,18 +37,18 @@ class _MyHomePageState extends State<MyHomePage> {
title: Text(widget.title), title: Text(widget.title),
), ),
drawer: Drawer( drawer: Drawer(
key: Key("drawer"), key: const Key("drawer"),
child: ListView( child: ListView(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
children: <Widget>[ children: <Widget>[
DrawerHeader( DrawerHeader(
child: Text('Drawer Header'), child: const Text('Drawer Header'),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.blue, color: Colors.blue,
), ),
), ),
ListTile( ListTile(
title: Text('Item 1'), title: const Text('Item 1'),
onTap: () { onTap: () {
// Update the state of the app // Update the state of the app
// ... // ...
@ -57,7 +57,7 @@ class _MyHomePageState extends State<MyHomePage> {
}, },
), ),
ListTile( ListTile(
title: Text('Item 2'), title: const Text('Item 2'),
onTap: () { onTap: () {
// Update the state of the app // Update the state of the app
// ... // ...
@ -72,7 +72,7 @@ class _MyHomePageState extends State<MyHomePage> {
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text( const Text(
'You have pushed the button this many times:', 'You have pushed the button this many times:',
), ),
Text( Text(
@ -80,7 +80,7 @@ class _MyHomePageState extends State<MyHomePage> {
// Provide a Key to this specific Text Widget. This allows us // Provide a Key to this specific Text Widget. This allows us
// to identify this specific Widget from inside our test suite and // to identify this specific Widget from inside our test suite and
// read the text. // read the text.
key: Key('counter'), key: const Key('counter'),
style: Theme.of(context).textTheme.display1, style: Theme.of(context).textTheme.display1,
), ),
], ],
@ -89,10 +89,10 @@ class _MyHomePageState extends State<MyHomePage> {
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
// Provide a Key to this the button. This allows us to find this // Provide a Key to this the button. This allows us to find this
// specific button and tap it inside the test suite. // specific button and tap it inside the test suite.
key: Key('increment'), key: const Key('increment'),
onPressed: _incrementCounter, onPressed: _incrementCounter,
tooltip: 'Increment', tooltip: 'Increment',
child: Icon(Icons.add), child: const Icon(Icons.add),
), ),
); );
} }

View File

@ -1,4 +1,4 @@
import '../lib/main.dart'; import 'package:example/main.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_driver/driver_extension.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 // Call the `main()` function of your app or call `runApp` with any widget you
// are interested in testing. // are interested in testing.
runApp(new MyApp()); runApp(MyApp());
} }

View File

@ -3,33 +3,30 @@ import 'package:flutter_gherkin/flutter_gherkin.dart';
class HookExample extends Hook { class HookExample extends Hook {
/// The priority to assign to this 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 /// Higher priority gets run first so a priority of 10 is run before a priority of 2
@override
int get priority => 1; int get priority => 1;
@override
/// Run before any scenario in a test run have executed /// Run before any scenario in a test run have executed
@override
Future<void> onBeforeRun(TestConfiguration config) async { Future<void> onBeforeRun(TestConfiguration config) async {
print("before run hook"); print("before run hook");
} }
@override
/// Run after all scenarios in a test run have completed /// Run after all scenarios in a test run have completed
@override
Future<void> onAfterRun(TestConfiguration config) async { Future<void> onAfterRun(TestConfiguration config) async {
print("after run hook"); print("after run hook");
} }
@override
/// Run before a scenario and it steps are executed /// Run before a scenario and it steps are executed
@override
Future<void> onBeforeScenario( Future<void> onBeforeScenario(
TestConfiguration config, String scenario) async { TestConfiguration config, String scenario) async {
print("running hook before scenario '$scenario'"); print("running hook before scenario '$scenario'");
} }
@override
/// Run after a scenario has executed /// Run after a scenario has executed
@override
Future<void> onAfterScenario( Future<void> onAfterScenario(
TestConfiguration config, String scenario) async { TestConfiguration config, String scenario) async {
print("running hook after scenario '$scenario'"); print("running hook after scenario '$scenario'");

View File

@ -42,11 +42,11 @@ class ExpectMimic {
/// you want to wait for the matcher to complete before continuing the test, you /// you want to wait for the matcher to complete before continuing the test, you
/// can call [expectLater] instead and `await` the result. /// can call [expectLater] instead and `await` the result.
void expect(actualValue, matcher, {String reason}) { void expect(actualValue, matcher, {String reason}) {
var matchState = {}; final matchState = {};
matcher = wrapMatcher(matcher); matcher = wrapMatcher(matcher);
final result = matcher.matches(actualValue, matchState); final result = matcher.matches(actualValue, matchState);
final formatter = (actual, matcher, reason, matchState, verbose) { final formatter = (actual, matcher, reason, matchState, verbose) {
var mismatchDescription = new StringDescription(); final mismatchDescription = StringDescription();
matcher.describeMismatch( matcher.describeMismatch(
actual, mismatchDescription, matchState, verbose); actual, mismatchDescription, matchState, verbose);

View File

@ -5,10 +5,10 @@ import 'package:matcher/matcher.dart';
/// The matcher package doesn't expose its pretty-print function directly, but /// The matcher package doesn't expose its pretty-print function directly, but
/// we can use it through StringDescription. /// we can use it through StringDescription.
String prettyPrint(value) => String prettyPrint(value) =>
new StringDescription().addDescriptionOf(value).toString(); StringDescription().addDescriptionOf(value).toString();
String formatFailure(Matcher expected, actual, String which, {String reason}) { 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(expected), first: 'Expected: '));
buffer.writeln(indent(prettyPrint(actual), first: ' Actual: ')); buffer.writeln(indent(prettyPrint(actual), first: ' Actual: '));
if (which.isNotEmpty) buffer.writeln(indent(which, first: ' Which: ')); if (which.isNotEmpty) buffer.writeln(indent(which, first: ' Which: '));
@ -37,13 +37,13 @@ String prefixLines(String text, String prefix,
last ??= prefix; last ??= prefix;
single ??= first ?? last ?? prefix; single ??= first ?? last ?? prefix;
var lines = text.split('\n'); final lines = text.split('\n');
if (lines.length == 1) return "$single$text"; 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]. // 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.writeln("$prefix$line");
} }
buffer.write("$last${lines.last}"); buffer.write("$last${lines.last}");

View File

@ -85,7 +85,7 @@ class FeatureFileRunner {
await _hook.onAfterScenarioWorldCreated(world, scenario.name); await _hook.onAfterScenarioWorldCreated(world, scenario.name);
} }
_reporter.onScenarioStarted( await _reporter.onScenarioStarted(
StartedMessage(Target.scenario, scenario.name, scenario.debug)); StartedMessage(Target.scenario, scenario.name, scenario.debug));
if (background != null) { if (background != null) {
await _log("Running background steps for scenerio '${scenario.name}'", await _log("Running background steps for scenerio '${scenario.name}'",
@ -95,7 +95,7 @@ class FeatureFileRunner {
scenarioPassed = result.result == StepExecutionResult.pass; scenarioPassed = result.result == StepExecutionResult.pass;
if (!_canContinueScenario(result)) { if (!_canContinueScenario(result)) {
scenarioPassed = false; scenarioPassed = false;
_log( await _log(
"Background step '${step.name}' did not pass, all remaining steps will be skiped", "Background step '${step.name}' did not pass, all remaining steps will be skiped",
step.debug, step.debug,
MessageLevel.warning); MessageLevel.warning);
@ -108,7 +108,7 @@ class FeatureFileRunner {
scenarioPassed = result.result == StepExecutionResult.pass; scenarioPassed = result.result == StepExecutionResult.pass;
if (!_canContinueScenario(result)) { if (!_canContinueScenario(result)) {
scenarioPassed = false; scenarioPassed = false;
_log( await _log(
"Step '${step.name}' did not pass, all remaining steps will be skiped", "Step '${step.name}' did not pass, all remaining steps will be skiped",
step.debug, step.debug,
MessageLevel.warning); MessageLevel.warning);
@ -130,8 +130,8 @@ class FeatureFileRunner {
Future<StepResult> _runStep( Future<StepResult> _runStep(
StepRunnable step, World world, bool skipExecution) async { StepRunnable step, World world, bool skipExecution) async {
StepResult result; StepResult result;
ExectuableStep code = _matchStepToExectuableStep(step); final ExectuableStep code = _matchStepToExectuableStep(step);
Iterable<dynamic> parameters = _getStepParameters(step, code); final Iterable<dynamic> parameters = _getStepParameters(step, code);
await _log( await _log(
"Attempting to run step '${step.name}'", step.debug, MessageLevel.info); "Attempting to run step '${step.name}'", step.debug, MessageLevel.info);
@ -206,7 +206,7 @@ class FeatureFileRunner {
} }
"""; """;
_reporter.message(message, MessageLevel.error); _reporter.message(message, MessageLevel.error);
throw new GherkinStepNotDefinedException(message); throw GherkinStepNotDefinedException(message);
} }
return executable; return executable;
@ -215,7 +215,7 @@ class FeatureFileRunner {
Iterable<dynamic> _getStepParameters(StepRunnable step, ExectuableStep code) { Iterable<dynamic> _getStepParameters(StepRunnable step, ExectuableStep code) {
Iterable<dynamic> parameters = Iterable<dynamic> parameters =
code.expression.getParameters(step.debug.lineText); code.expression.getParameters(step.debug.lineText);
if (step.multilineStrings.length > 0) { if (step.multilineStrings.isNotEmpty) {
parameters = parameters.toList()..addAll(step.multilineStrings); parameters = parameters.toList()..addAll(step.multilineStrings);
} }

View File

@ -16,7 +16,7 @@ class FlutterRunProcessHandler extends ProcessHandler {
RegExp(r"no connected device", caseSensitive: false, multiLine: false); RegExp(r"no connected device", caseSensitive: false, multiLine: false);
Process _runningProcess; Process _runningProcess;
Stream<String> _processStdoutStream; Stream<String> _processStdoutStream;
List<StreamSubscription> _openSubscriptions = List<StreamSubscription>(); List<StreamSubscription> _openSubscriptions = <StreamSubscription>[];
String _appTarget; String _appTarget;
String _workingDirectory; String _workingDirectory;
@ -86,7 +86,7 @@ class FlutterRunProcessHandler extends ProcessHandler {
void _ensureRunningProcess() { void _ensureRunningProcess() {
if (_runningProcess == null) { if (_runningProcess == null) {
throw new Exception( throw Exception(
"FlutterRunProcessHandler: flutter run process is not active"); "FlutterRunProcessHandler: flutter run process is not active");
} }
} }

View File

@ -28,7 +28,7 @@ class FlutterTestConfiguration extends TestConfiguration {
Platform.environment['VM_SERVICE_URL']; Platform.environment['VM_SERVICE_URL'];
final driver = await FlutterDriver.connect( final driver = await FlutterDriver.connect(
dartVmServiceUrl: dartVmServiceUrl, dartVmServiceUrl: dartVmServiceUrl,
isolateReadyTimeout: Duration(seconds: 30), isolateReadyTimeout: const Duration(seconds: 30),
logCommunicationToFile: false, logCommunicationToFile: false,
printCommunication: false); printCommunication: false);
return driver; return driver;
@ -36,7 +36,7 @@ class FlutterTestConfiguration extends TestConfiguration {
Future<FlutterWorld> createFlutterWorld( Future<FlutterWorld> createFlutterWorld(
TestConfiguration config, FlutterWorld world) async { TestConfiguration config, FlutterWorld world) async {
world = world ?? new FlutterWorld(); world = world ?? FlutterWorld();
final driver = await createFlutterDriver(); final driver = await createFlutterDriver();
world.setFlutterDriver(driver); world.setFlutterDriver(driver);
return world; return world;

View File

@ -6,7 +6,7 @@ class FlutterWorld extends World {
FlutterDriver get driver => _driver; FlutterDriver get driver => _driver;
setFlutterDriver(FlutterDriver flutterDriver) { void setFlutterDriver(FlutterDriver flutterDriver) {
_driver = flutterDriver; _driver = flutterDriver;
} }

View File

@ -11,15 +11,19 @@ class FlutterAppRunnerHook extends Hook {
FlutterRunProcessHandler _flutterAppProcess; FlutterRunProcessHandler _flutterAppProcess;
bool haveRunFirstScenario = false; bool haveRunFirstScenario = false;
@override
int get priority => 999999; int get priority => 999999;
@override
Future<void> onBeforeRun(TestConfiguration config) async { Future<void> onBeforeRun(TestConfiguration config) async {
await _runApp(_castConfig(config)); await _runApp(_castConfig(config));
} }
@override
Future<void> onAfterRun(TestConfiguration config) async => Future<void> onAfterRun(TestConfiguration config) async =>
await _terminateApp(); await _terminateApp();
@override
Future<void> onBeforeScenario( Future<void> onBeforeScenario(
TestConfiguration config, String scenario) async { TestConfiguration config, String scenario) async {
final flutterConfig = _castConfig(config); final flutterConfig = _castConfig(config);
@ -28,6 +32,7 @@ class FlutterAppRunnerHook extends Hook {
} }
} }
@override
Future<void> onAfterScenario( Future<void> onAfterScenario(
TestConfiguration config, String scenario) async { TestConfiguration config, String scenario) async {
final flutterConfig = _castConfig(config); final flutterConfig = _castConfig(config);
@ -39,7 +44,7 @@ class FlutterAppRunnerHook extends Hook {
} }
Future<void> _runApp(FlutterTestConfiguration config) async { Future<void> _runApp(FlutterTestConfiguration config) async {
_flutterAppProcess = new FlutterRunProcessHandler(); _flutterAppProcess = FlutterRunProcessHandler();
_flutterAppProcess.setApplicationTargetFile(config.targetAppPath); _flutterAppProcess.setApplicationTargetFile(config.targetAppPath);
stdout.writeln( stdout.writeln(
"Starting Flutter app under test '${config.targetAppPath}', this might take a few moments"); "Starting Flutter app under test '${config.targetAppPath}', this might take a few moments");

View File

@ -21,7 +21,7 @@ class GivenOpenDrawer extends Given1WithWorld<String, FlutterWorld> {
if (isOpen && action == "close") { if (isOpen && action == "close") {
// Swipe to the left across the whole app to close the drawer // Swipe to the left across the whole app to close the drawer
await world.driver 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") { } else if (!isOpen && action == "open") {
await FlutterDriverUtils.tap( await FlutterDriverUtils.tap(
world.driver, find.byTooltip("Open navigation menu"), world.driver, find.byTooltip("Open navigation menu"),

View File

@ -10,7 +10,8 @@ import 'package:flutter_gherkin/src/gherkin/steps/when.dart';
/// When I pause for 120 seconds /// When I pause for 120 seconds
class WhenPauseStep extends When1<int> { class WhenPauseStep extends When1<int> {
WhenPauseStep() WhenPauseStep()
: super(StepDefinitionConfiguration()..timeout = Duration(minutes: 5)); : super(StepDefinitionConfiguration()
..timeout = const Duration(minutes: 5));
@override @override
Future<void> executeStep(int seconds) async { Future<void> executeStep(int seconds) async {

View File

@ -6,9 +6,11 @@ class GherkinStepParameterMismatchException implements Exception {
GherkinStepParameterMismatchException( GherkinStepParameterMismatchException(
this.step, this.expectParameterCount, this.actualParameterCount) this.step, this.expectParameterCount, this.actualParameterCount)
: message = "$step parameter count mismatch. Expect $expectParameterCount parameters but got $actualParameterCount. " + : message =
"Ensure you are extending the correct step class which would be " + "$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(", ")}>' : ''}"; "Given${actualParameterCount > 0 ? '$actualParameterCount<${List.generate(actualParameterCount, (i) => "TInputType$i").join(", ")}>' : ''}";
@override
String toString() => message; String toString() => message;
} }

View File

@ -11,7 +11,7 @@ class _SortedParameterPosition {
class GherkinExpression { class GherkinExpression {
final RegExp originalExpression; final RegExp originalExpression;
final List<_SortedParameterPosition> _sortedParameterPositions = final List<_SortedParameterPosition> _sortedParameterPositions =
List<_SortedParameterPosition>(); <_SortedParameterPosition>[];
RegExp _expression; RegExp _expression;
GherkinExpression(this.originalExpression, GherkinExpression(this.originalExpression,
@ -41,7 +41,7 @@ class GherkinExpression {
bool inCustomBracketSection = false; bool inCustomBracketSection = false;
int indexOfOpeningBracket; int indexOfOpeningBracket;
for (var i = 0; i < originalExpression.pattern.length; i += 1) { for (var i = 0; i < originalExpression.pattern.length; i += 1) {
var char = originalExpression.pattern[i]; final char = originalExpression.pattern[i];
if (char == "(") { if (char == "(") {
// look ahead and make sure we don't see "s)" which would // look ahead and make sure we don't see "s)" which would
// indicate the plural parameter // indicate the plural parameter
@ -75,8 +75,8 @@ class GherkinExpression {
} }
Iterable<dynamic> getParameters(String input) { Iterable<dynamic> getParameters(String input) {
List<String> stringValues = List<String>(); final List<String> stringValues = <String>[];
List<dynamic> values = List<dynamic>(); final List<dynamic> values = <dynamic>[];
_expression.allMatches(input).forEach((m) { _expression.allMatches(input).forEach((m) {
// the first group is always the input string // the first group is always the input string
final indicies = final indicies =

View File

@ -30,7 +30,7 @@ class TagExpressionEvaluator {
} }
bool _evaluateRpn(Queue<String> rpn, List<String> tags) { bool _evaluateRpn(Queue<String> rpn, List<String> tags) {
Queue<bool> stack = Queue<bool>(); final Queue<bool> stack = Queue<bool>();
for (var token in rpn) { for (var token in rpn) {
if (_isTag(token)) { if (_isTag(token)) {
stack.addFirst(tags.contains(token.replaceFirst(RegExp("@"), ""))); stack.addFirst(tags.contains(token.replaceFirst(RegExp("@"), "")));
@ -79,25 +79,25 @@ class TagExpressionEvaluator {
operatorQueue.addLast(part); operatorQueue.addLast(part);
} else if (part == closingBracket) { } else if (part == closingBracket) {
while ( while (
operatorQueue.length > 0 && operatorQueue.last != openingBracket) { operatorQueue.isNotEmpty && operatorQueue.last != openingBracket) {
rpn.add(operatorQueue.removeLast()); rpn.add(operatorQueue.removeLast());
} }
operatorQueue.removeLast(); operatorQueue.removeLast();
} else if (_isOperator(part)) { } else if (_isOperator(part)) {
final precendence = _operatorPrededence[part.toLowerCase()]; final precendence = _operatorPrededence[part.toLowerCase()];
while (operatorQueue.length > 0 && while (operatorQueue.isNotEmpty &&
_operatorPrededence[operatorQueue.last] >= precendence) { _operatorPrededence[operatorQueue.last] >= precendence) {
rpn.add(operatorQueue.removeLast()); rpn.add(operatorQueue.removeLast());
} }
operatorQueue.addLast(part); operatorQueue.addLast(part);
} else { } else {
throw new GherkinSyntaxException( throw GherkinSyntaxException(
"Tag expression '$infixExpression' is not valid. Unknown token '$part'. Known tokens are '@tag', 'and', 'or', 'not' '(' and ')'"); "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()); rpn.add(operatorQueue.removeLast());
} }

View File

@ -74,7 +74,7 @@ class GherkinParser {
parentBlock.addChild(runnable); parentBlock.addChild(runnable);
} else { } else {
throw new GherkinSyntaxException( throw GherkinSyntaxException(
"Unknown or un-implemented syntax: '$line', file: '${parentBlock.debug.filePath}"); "Unknown or un-implemented syntax: '$line', file: '${parentBlock.debug.filePath}");
} }
} }

View File

@ -6,6 +6,6 @@ class RunnableDebugInformation {
RunnableDebugInformation(this.filePath, this.lineNumber, this.lineText); RunnableDebugInformation(this.filePath, this.lineNumber, this.lineText);
RunnableDebugInformation copyWith(int lineNumber, String line) { RunnableDebugInformation copyWith(int lineNumber, String line) {
return RunnableDebugInformation(this.filePath, lineNumber, line); return RunnableDebugInformation(filePath, lineNumber, line);
} }
} }

View File

@ -12,11 +12,11 @@ import 'package:flutter_gherkin/src/gherkin/runnables/text_line.dart';
class FeatureRunnable extends RunnableBlock { class FeatureRunnable extends RunnableBlock {
String _name; String _name;
String description; String description;
List<String> tags = List<String>(); List<String> tags = <String>[];
BackgroundRunnable background; BackgroundRunnable background;
List<ScenarioRunnable> scenarios = List<ScenarioRunnable>(); List<ScenarioRunnable> scenarios = <ScenarioRunnable>[];
Map<int, Iterable<String>> _tagMap = Map<int, Iterable<String>>(); Map<int, Iterable<String>> _tagMap = <int, Iterable<String>>{};
FeatureRunnable(this._name, RunnableDebugInformation debug) : super(debug); FeatureRunnable(this._name, RunnableDebugInformation debug) : super(debug);
@ -46,7 +46,7 @@ class FeatureRunnable extends RunnableBlock {
if (background == null) { if (background == null) {
background = child; background = child;
} else { } else {
throw new GherkinSyntaxException( throw GherkinSyntaxException(
"Feature file can only contain one backgroung block. File'${debug.filePath}' :: line '${child.debug.lineNumber}'"); "Feature file can only contain one backgroung block. File'${debug.filePath}' :: line '${child.debug.lineNumber}'");
} }
break; break;
@ -54,7 +54,7 @@ class FeatureRunnable extends RunnableBlock {
case CommentLineRunnable: case CommentLineRunnable:
break; break;
default: default:
throw new Exception( throw Exception(
"Unknown runnable child given to Feature '${child.runtimeType}'"); "Unknown runnable child given to Feature '${child.runtimeType}'");
} }
} }

View File

@ -8,7 +8,7 @@ import 'package:flutter_gherkin/src/gherkin/runnables/runnable_block.dart';
class FeatureFile extends RunnableBlock { class FeatureFile extends RunnableBlock {
String _language = "en"; String _language = "en";
List<FeatureRunnable> features = new List<FeatureRunnable>(); List<FeatureRunnable> features = <FeatureRunnable>[];
FeatureFile(RunnableDebugInformation debug) : super(debug); FeatureFile(RunnableDebugInformation debug) : super(debug);
@ -26,7 +26,7 @@ class FeatureFile extends RunnableBlock {
case EmptyLineRunnable: case EmptyLineRunnable:
break; break;
default: default:
throw new Exception( throw Exception(
"Unknown runnable child given to FeatureFile '${child.runtimeType}'"); "Unknown runnable child given to FeatureFile '${child.runtimeType}'");
} }
} }

View File

@ -5,7 +5,7 @@ import 'package:flutter_gherkin/src/gherkin/runnables/runnable_block.dart';
import 'package:flutter_gherkin/src/gherkin/runnables/text_line.dart'; import 'package:flutter_gherkin/src/gherkin/runnables/text_line.dart';
class MultilineStringRunnable extends RunnableBlock { class MultilineStringRunnable extends RunnableBlock {
List<String> lines = List<String>(); List<String> lines = <String>[];
@override @override
String get name => "Multiline String"; String get name => "Multiline String";
@ -14,6 +14,8 @@ class MultilineStringRunnable extends RunnableBlock {
@override @override
void addChild(Runnable child) { void addChild(Runnable child) {
final exception = Exception(
"Unknown runnable child given to Multiline string '${child.runtimeType}'");
switch (child.runtimeType) { switch (child.runtimeType) {
case TextLineRunnable: case TextLineRunnable:
lines.add((child as TextLineRunnable).text); lines.add((child as TextLineRunnable).text);
@ -21,8 +23,7 @@ class MultilineStringRunnable extends RunnableBlock {
case EmptyLineRunnable: case EmptyLineRunnable:
break; break;
default: default:
throw new Exception( throw exception;
"Unknown runnable child given to Multiline string '${child.runtimeType}'");
} }
} }
} }

View File

@ -8,8 +8,8 @@ import 'package:flutter_gherkin/src/gherkin/runnables/tags.dart';
class ScenarioRunnable extends RunnableBlock { class ScenarioRunnable extends RunnableBlock {
String _name; String _name;
List<String> tags = List<String>(); List<String> tags = <String>[];
List<StepRunnable> steps = new List<StepRunnable>(); List<StepRunnable> steps = <StepRunnable>[];
ScenarioRunnable(this._name, RunnableDebugInformation debug) : super(debug); ScenarioRunnable(this._name, RunnableDebugInformation debug) : super(debug);
@ -29,7 +29,7 @@ class ScenarioRunnable extends RunnableBlock {
case EmptyLineRunnable: case EmptyLineRunnable:
break; break;
default: default:
throw new Exception( throw Exception(
"Unknown runnable child given to Scenario '${child.runtimeType}'"); "Unknown runnable child given to Scenario '${child.runtimeType}'");
} }
} }

View File

@ -9,7 +9,7 @@ import 'package:flutter_gherkin/src/gherkin/runnables/table.dart';
class StepRunnable extends RunnableBlock { class StepRunnable extends RunnableBlock {
String _name; String _name;
String description; String description;
List<String> multilineStrings = List<String>(); List<String> multilineStrings = <String>[];
Table table; Table table;
StepRunnable(this._name, RunnableDebugInformation debug) : super(debug); StepRunnable(this._name, RunnableDebugInformation debug) : super(debug);
@ -26,13 +26,13 @@ class StepRunnable extends RunnableBlock {
break; break;
case TableRunnable: case TableRunnable:
if (table != null) if (table != null)
throw new GherkinSyntaxException( throw GherkinSyntaxException(
"Only a single table can be added to the step '$name'"); "Only a single table can be added to the step '$name'");
table = (child as TableRunnable).toTable(); table = (child as TableRunnable).toTable();
break; break;
default: default:
throw new Exception( throw Exception(
"Unknown runnable child given to Step '${child.runtimeType}'"); "Unknown runnable child given to Step '${child.runtimeType}'");
} }
} }

View File

@ -6,7 +6,7 @@ import 'package:flutter_gherkin/src/gherkin/runnables/runnable.dart';
import 'package:flutter_gherkin/src/gherkin/runnables/runnable_block.dart'; import 'package:flutter_gherkin/src/gherkin/runnables/runnable_block.dart';
class TableRunnable extends RunnableBlock { class TableRunnable extends RunnableBlock {
final List<String> rows = List<String>(); final List<String> rows = <String>[];
@override @override
String get name => "Table"; String get name => "Table";
@ -22,14 +22,14 @@ class TableRunnable extends RunnableBlock {
case CommentLineRunnable: case CommentLineRunnable:
break; break;
default: default:
throw new Exception( throw Exception(
"Unknown runnable child given to Table '${child.runtimeType}'"); "Unknown runnable child given to Table '${child.runtimeType}'");
} }
} }
Table toTable() { Table toTable() {
TableRow header; TableRow header;
List<TableRow> tableRows = List<TableRow>(); final List<TableRow> tableRows = <TableRow>[];
if (rows.length > 1) { if (rows.length > 1) {
header = _toRow(rows.first, 0, true); header = _toRow(rows.first, 0, true);
} }

View File

@ -16,7 +16,7 @@ abstract class StepDefinitionGeneric<TWorld extends World> {
RegExp get pattern; RegExp get pattern;
StepDefinitionGeneric(this.config, this._expectParameterCount) { StepDefinitionGeneric(this.config, this._expectParameterCount) {
this._timeout = this.config?.timeout; _timeout = config?.timeout;
} }
TWorld get world => _world; TWorld get world => _world;
@ -54,6 +54,6 @@ abstract class StepDefinitionGeneric<TWorld extends World> {
void _ensureParameterCount(int actual, int expected) { void _ensureParameterCount(int actual, int expected) {
if (actual != expected) if (actual != expected)
throw GherkinStepParameterMismatchException( throw GherkinStepParameterMismatchException(
this.runtimeType, expected, actual); runtimeType, expected, actual);
} }
} }

View File

@ -28,6 +28,7 @@ abstract class StepDefinition<TWorld extends World>
StepDefinition([StepDefinitionConfiguration configuration]) StepDefinition([StepDefinitionConfiguration configuration])
: super(configuration, 0); : super(configuration, 0);
@override
Future<void> onRun(Iterable<dynamic> parameters) async => await code(); Future<void> onRun(Iterable<dynamic> parameters) async => await code();
} }
@ -36,6 +37,7 @@ abstract class StepDefinition1<TWorld extends World, TInput1>
StepDefinition1([StepDefinitionConfiguration configuration]) StepDefinition1([StepDefinitionConfiguration configuration])
: super(configuration, 1); : super(configuration, 1);
@override
Future<void> onRun(Iterable<dynamic> parameters) async => Future<void> onRun(Iterable<dynamic> parameters) async =>
await code(parameters.elementAt(0)); await code(parameters.elementAt(0));
} }
@ -45,6 +47,7 @@ abstract class StepDefinition2<TWorld extends World, TInput1, TInput2>
StepDefinition2([StepDefinitionConfiguration configuration]) StepDefinition2([StepDefinitionConfiguration configuration])
: super(configuration, 2); : super(configuration, 2);
@override
Future<void> onRun(Iterable<dynamic> parameters) async => Future<void> onRun(Iterable<dynamic> parameters) async =>
await code(parameters.elementAt(0), parameters.elementAt(1)); await code(parameters.elementAt(0), parameters.elementAt(1));
} }
@ -55,6 +58,7 @@ abstract class StepDefinition3<TWorld extends World, TInput1, TInput2, TInput3>
StepDefinition3([StepDefinitionConfiguration configuration]) StepDefinition3([StepDefinitionConfiguration configuration])
: super(configuration, 3); : super(configuration, 3);
@override
Future<void> onRun(Iterable<dynamic> parameters) async => await code( Future<void> onRun(Iterable<dynamic> parameters) async => await code(
parameters.elementAt(0), parameters.elementAt(0),
parameters.elementAt(1), parameters.elementAt(1),
@ -68,6 +72,7 @@ abstract class StepDefinition4<TWorld extends World, TInput1, TInput2, TInput3,
StepDefinition4([StepDefinitionConfiguration configuration]) StepDefinition4([StepDefinitionConfiguration configuration])
: super(configuration, 4); : super(configuration, 4);
@override
Future<void> onRun(Iterable<dynamic> parameters) async => await code( Future<void> onRun(Iterable<dynamic> parameters) async => await code(
parameters.elementAt(0), parameters.elementAt(0),
parameters.elementAt(1), parameters.elementAt(1),
@ -82,6 +87,7 @@ abstract class StepDefinition5<TWorld extends World, TInput1, TInput2, TInput3,
StepDefinition5([StepDefinitionConfiguration configuration]) StepDefinition5([StepDefinitionConfiguration configuration])
: super(configuration, 5); : super(configuration, 5);
@override
Future<void> onRun(Iterable<dynamic> parameters) async => await code( Future<void> onRun(Iterable<dynamic> parameters) async => await code(
parameters.elementAt(0), parameters.elementAt(0),
parameters.elementAt(1), parameters.elementAt(1),

View File

@ -8,6 +8,7 @@ import 'package:flutter_gherkin/src/gherkin/syntax/syntax_matcher.dart';
import 'package:flutter_gherkin/src/gherkin/syntax/tag_syntax.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/tag_syntax.dart';
class BackgroundSyntax extends RegExMatchedGherkinSyntax { class BackgroundSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = RegExp(r"^\s*Background:\s*(.+)\s*$", final RegExp pattern = RegExp(r"^\s*Background:\s*(.+)\s*$",
multiLine: false, caseSensitive: false); multiLine: false, caseSensitive: false);
@ -23,7 +24,7 @@ class BackgroundSyntax extends RegExMatchedGherkinSyntax {
@override @override
Runnable toRunnable(String line, RunnableDebugInformation debug) { Runnable toRunnable(String line, RunnableDebugInformation debug) {
final name = pattern.firstMatch(line).group(1); final name = pattern.firstMatch(line).group(1);
final runnable = new BackgroundRunnable(name, debug); final runnable = BackgroundRunnable(name, debug);
return runnable; return runnable;
} }
} }

View File

@ -4,6 +4,7 @@ import 'package:flutter_gherkin/src/gherkin/runnables/runnable.dart';
import 'package:flutter_gherkin/src/gherkin/syntax/regex_matched_syntax.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/regex_matched_syntax.dart';
class CommentSyntax extends RegExMatchedGherkinSyntax { class CommentSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = RegExp("^#", multiLine: false, caseSensitive: false); final RegExp pattern = RegExp("^#", multiLine: false, caseSensitive: false);
@override @override

View File

@ -4,6 +4,7 @@ import 'package:flutter_gherkin/src/gherkin/runnables/runnable.dart';
import 'package:flutter_gherkin/src/gherkin/syntax/regex_matched_syntax.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/regex_matched_syntax.dart';
class EmptyLineSyntax extends RegExMatchedGherkinSyntax { class EmptyLineSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = final RegExp pattern =
RegExp(r"^\s*$", multiLine: false, caseSensitive: false); RegExp(r"^\s*$", multiLine: false, caseSensitive: false);

View File

@ -5,6 +5,7 @@ import './syntax_matcher.dart';
import './regex_matched_syntax.dart'; import './regex_matched_syntax.dart';
class FeatureSyntax extends RegExMatchedGherkinSyntax { class FeatureSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = final RegExp pattern =
RegExp(r"^Feature:\s*(.+)\s*", multiLine: false, caseSensitive: false); RegExp(r"^Feature:\s*(.+)\s*", multiLine: false, caseSensitive: false);
@ -17,7 +18,7 @@ class FeatureSyntax extends RegExMatchedGherkinSyntax {
@override @override
Runnable toRunnable(String line, RunnableDebugInformation debug) { Runnable toRunnable(String line, RunnableDebugInformation debug) {
final name = pattern.firstMatch(line).group(1); final name = pattern.firstMatch(line).group(1);
final runnable = new FeatureRunnable(name, debug); final runnable = FeatureRunnable(name, debug);
return runnable; return runnable;
} }
} }

View File

@ -5,12 +5,13 @@ import './regex_matched_syntax.dart';
/// see https://docs.cucumber.io/gherkin/reference/#gherkin-dialects /// see https://docs.cucumber.io/gherkin/reference/#gherkin-dialects
class LanguageSyntax extends RegExMatchedGherkinSyntax { class LanguageSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = RegExp(r"^\s*#\s*language:\s*([a-z]{2,7})\s*$", final RegExp pattern = RegExp(r"^\s*#\s*language:\s*([a-z]{2,7})\s*$",
multiLine: false, caseSensitive: false); multiLine: false, caseSensitive: false);
@override @override
Runnable toRunnable(String line, RunnableDebugInformation debug) { Runnable toRunnable(String line, RunnableDebugInformation debug) {
final runnable = new LanguageRunnable(debug); final runnable = LanguageRunnable(debug);
runnable.language = pattern.firstMatch(line).group(1); runnable.language = pattern.firstMatch(line).group(1);
return runnable; return runnable;
} }

View File

@ -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'; import 'package:flutter_gherkin/src/gherkin/syntax/text_line_syntax.dart';
class MultilineStringSyntax extends RegExMatchedGherkinSyntax { class MultilineStringSyntax extends RegExMatchedGherkinSyntax {
final RegExp pattern = RegExp(r"^\s*(" + '"""' + r"|'''|```)\s*$", @override
multiLine: false, caseSensitive: false); final RegExp pattern = RegExp(
r"^\s*("
'"""'
r"|'''|```)\s*$",
multiLine: false,
caseSensitive: false);
@override @override
bool get isBlockSyntax => true; bool get isBlockSyntax => true;
@ -27,7 +32,7 @@ class MultilineStringSyntax extends RegExMatchedGherkinSyntax {
@override @override
Runnable toRunnable(String line, RunnableDebugInformation debug) { Runnable toRunnable(String line, RunnableDebugInformation debug) {
final runnable = new MultilineStringRunnable(debug); final runnable = MultilineStringRunnable(debug);
return runnable; return runnable;
} }

View File

@ -6,6 +6,7 @@ import 'package:flutter_gherkin/src/gherkin/syntax/syntax_matcher.dart';
import 'package:flutter_gherkin/src/gherkin/syntax/tag_syntax.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/tag_syntax.dart';
class ScenarioSyntax extends RegExMatchedGherkinSyntax { class ScenarioSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = RegExp(r"^\s*Scenario:\s*(.+)\s*$", final RegExp pattern = RegExp(r"^\s*Scenario:\s*(.+)\s*$",
multiLine: false, caseSensitive: false); multiLine: false, caseSensitive: false);
@ -19,7 +20,7 @@ class ScenarioSyntax extends RegExMatchedGherkinSyntax {
@override @override
Runnable toRunnable(String line, RunnableDebugInformation debug) { Runnable toRunnable(String line, RunnableDebugInformation debug) {
final name = pattern.firstMatch(line).group(1); final name = pattern.firstMatch(line).group(1);
final runnable = new ScenarioRunnable(name, debug); final runnable = ScenarioRunnable(name, debug);
return runnable; return runnable;
} }
} }

View File

@ -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'; import 'package:flutter_gherkin/src/gherkin/syntax/table_line_syntax.dart';
class StepSyntax extends RegExMatchedGherkinSyntax { class StepSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = RegExp(r"^(given|then|when|and|but)\s.*", final RegExp pattern = RegExp(r"^(given|then|when|and|but)\s.*",
multiLine: false, caseSensitive: false); multiLine: false, caseSensitive: false);
@ -19,7 +20,7 @@ class StepSyntax extends RegExMatchedGherkinSyntax {
@override @override
Runnable toRunnable(String line, RunnableDebugInformation debug) { Runnable toRunnable(String line, RunnableDebugInformation debug) {
final runnable = new StepRunnable(line, debug); final runnable = StepRunnable(line, debug);
return runnable; return runnable;
} }
} }

View File

@ -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'; import 'package:flutter_gherkin/src/gherkin/syntax/syntax_matcher.dart';
class TableLineSyntax extends RegExMatchedGherkinSyntax { class TableLineSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = final RegExp pattern =
RegExp(r"^\s*\|.*\|\s*$", multiLine: false, caseSensitive: false); RegExp(r"^\s*\|.*\|\s*$", multiLine: false, caseSensitive: false);
@ -22,7 +23,7 @@ class TableLineSyntax extends RegExMatchedGherkinSyntax {
@override @override
Runnable toRunnable(String line, RunnableDebugInformation debug) { Runnable toRunnable(String line, RunnableDebugInformation debug) {
final runnable = new TableRunnable(debug); final runnable = TableRunnable(debug);
runnable.rows.add(line.trim()); runnable.rows.add(line.trim());
return runnable; return runnable;
} }

View File

@ -4,11 +4,12 @@ import 'package:flutter_gherkin/src/gherkin/runnables/tags.dart';
import 'package:flutter_gherkin/src/gherkin/syntax/regex_matched_syntax.dart'; import 'package:flutter_gherkin/src/gherkin/syntax/regex_matched_syntax.dart';
class TagSyntax extends RegExMatchedGherkinSyntax { class TagSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = RegExp("^@", multiLine: false, caseSensitive: false); final RegExp pattern = RegExp("^@", multiLine: false, caseSensitive: false);
@override @override
Runnable toRunnable(String line, RunnableDebugInformation debug) { Runnable toRunnable(String line, RunnableDebugInformation debug) {
final runnable = new TagsRunnable(debug); final runnable = TagsRunnable(debug);
runnable.tags = line runnable.tags = line
.trim() .trim()
.split(RegExp("@")) .split(RegExp("@"))

View File

@ -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'; import 'package:flutter_gherkin/src/gherkin/syntax/regex_matched_syntax.dart';
class TextLineSyntax extends RegExMatchedGherkinSyntax { class TextLineSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = final RegExp pattern =
RegExp(r"^\s*(?!#)\w+.*]*$", multiLine: false, caseSensitive: false); RegExp(r"^\s*(?!#)\w+.*]*$", multiLine: false, caseSensitive: false);
@override @override
Runnable toRunnable(String line, RunnableDebugInformation debug) { Runnable toRunnable(String line, RunnableDebugInformation debug) {
final runnable = new TextLineRunnable(debug); final runnable = TextLineRunnable(debug);
runnable.text = line.trim(); runnable.text = line.trim();
return runnable; return runnable;
} }

View File

@ -9,29 +9,34 @@ class AggregatedHook extends Hook {
_orderedHooks = hooks.toList()..sort((a, b) => b.priority - a.priority); _orderedHooks = hooks.toList()..sort((a, b) => b.priority - a.priority);
} }
@override
Future<void> onBeforeRun(TestConfiguration config) async => Future<void> onBeforeRun(TestConfiguration config) async =>
await _invokeHooks((h) => h.onBeforeRun(config)); await _invokeHooks((h) => h.onBeforeRun(config));
/// Run after all scenerios in a test run have completed /// Run after all scenerios in a test run have completed
@override
Future<void> onAfterRun(TestConfiguration config) async => Future<void> onAfterRun(TestConfiguration config) async =>
await _invokeHooks((h) => h.onAfterRun(config)); await _invokeHooks((h) => h.onAfterRun(config));
@override
Future<void> onAfterScenarioWorldCreated( Future<void> onAfterScenarioWorldCreated(
World world, String scenario) async => World world, String scenario) async =>
await _invokeHooks((h) => h.onAfterScenarioWorldCreated(world, scenario)); await _invokeHooks((h) => h.onAfterScenarioWorldCreated(world, scenario));
/// Run before a scenario and it steps are executed /// Run before a scenario and it steps are executed
@override
Future<void> onBeforeScenario( Future<void> onBeforeScenario(
TestConfiguration config, String scenario) async => TestConfiguration config, String scenario) async =>
await _invokeHooks((h) => h.onBeforeScenario(config, scenario)); await _invokeHooks((h) => h.onBeforeScenario(config, scenario));
/// Run after a scenario has executed /// Run after a scenario has executed
@override
Future<void> onAfterScenario( Future<void> onAfterScenario(
TestConfiguration config, String scenario) async => TestConfiguration config, String scenario) async =>
await _invokeHooks((h) => h.onAfterScenario(config, scenario)); await _invokeHooks((h) => h.onAfterScenario(config, scenario));
Future<void> _invokeHooks(Future<void> invoke(Hook h)) async { Future<void> _invokeHooks(Future<void> invoke(Hook h)) async {
if (_orderedHooks != null && _orderedHooks.length > 0) { if (_orderedHooks != null && _orderedHooks.isNotEmpty) {
for (var hook in _orderedHooks) { for (var hook in _orderedHooks) {
await invoke(hook); await invoke(hook);
} }

View File

@ -3,7 +3,7 @@ import 'package:flutter_gherkin/src/reporters/message_level.dart';
import 'package:flutter_gherkin/src/reporters/reporter.dart'; import 'package:flutter_gherkin/src/reporters/reporter.dart';
class AggregatedReporter extends Reporter { class AggregatedReporter extends Reporter {
final List<Reporter> _reporters = new List<Reporter>(); final List<Reporter> _reporters = <Reporter>[];
void addReporter(Reporter reporter) => _reporters.add(reporter); void addReporter(Reporter reporter) => _reporters.add(reporter);
@ -64,7 +64,7 @@ class AggregatedReporter extends Reporter {
} }
Future<void> _invokeReporters(Future<void> invoke(Reporter r)) async { Future<void> _invokeReporters(Future<void> invoke(Reporter r)) async {
if (_reporters != null && _reporters.length > 0) { if (_reporters != null && _reporters.isNotEmpty) {
for (var reporter in _reporters) { for (var reporter in _reporters) {
try { try {
await invoke(reporter); await invoke(reporter);

View File

@ -33,6 +33,7 @@ class ProgressReporter extends StdoutReporter {
_getMessageColour(message.result.result)); _getMessageColour(message.result.result));
} }
@override
Future<void> message(String message, MessageLevel level) async { Future<void> message(String message, MessageLevel level) async {
// ignore messages // ignore messages
} }

View File

@ -13,6 +13,7 @@ class StdoutReporter extends Reporter {
StdoutReporter([this._logLevel = MessageLevel.verbose]); StdoutReporter([this._logLevel = MessageLevel.verbose]);
@override
Future<void> message(String message, MessageLevel level) async { Future<void> message(String message, MessageLevel level) async {
if (level.index >= _logLevel.index) { if (level.index >= _logLevel.index) {
printMessageLine(message, getColour(level)); printMessageLine(message, getColour(level));

View File

@ -4,10 +4,10 @@ import 'package:flutter_gherkin/src/reporters/message_level.dart';
import 'package:flutter_gherkin/src/reporters/messages.dart'; import 'package:flutter_gherkin/src/reporters/messages.dart';
class TestRunSummaryReporter extends StdoutReporter { class TestRunSummaryReporter extends StdoutReporter {
final _timer = new Stopwatch(); final _timer = Stopwatch();
final List<StepFinishedMessage> _ranSteps = List<StepFinishedMessage>(); final List<StepFinishedMessage> _ranSteps = <StepFinishedMessage>[];
final List<ScenarioFinishedMessage> _ranScenarios = final List<ScenarioFinishedMessage> _ranScenarios =
List<ScenarioFinishedMessage>(); <ScenarioFinishedMessage>[];
@override @override
Future<void> onScenarioFinished(ScenarioFinishedMessage message) async { Future<void> onScenarioFinished(ScenarioFinishedMessage message) async {
@ -47,7 +47,7 @@ class TestRunSummaryReporter extends StdoutReporter {
} }
String _collectScenarioSummary(Iterable<ScenarioFinishedMessage> scenarios) { String _collectScenarioSummary(Iterable<ScenarioFinishedMessage> scenarios) {
List<String> summaries = List<String>(); final List<String> summaries = <String>[];
if (scenarios.any((s) => s.passed)) { if (scenarios.any((s) => s.passed)) {
summaries.add( summaries.add(
"${StdoutReporter.PASS_COLOR}${scenarios.where((s) => s.passed).length} passed${StdoutReporter.RESET_COLOR}"); "${StdoutReporter.PASS_COLOR}${scenarios.where((s) => s.passed).length} passed${StdoutReporter.RESET_COLOR}");
@ -62,7 +62,7 @@ class TestRunSummaryReporter extends StdoutReporter {
} }
String _collectStepSummary(Iterable<StepFinishedMessage> steps) { String _collectStepSummary(Iterable<StepFinishedMessage> steps) {
List<String> summaries = List<String>(); final List<String> summaries = <String>[];
final passed = final passed =
steps.where((s) => s.result.result == StepExecutionResult.pass); steps.where((s) => s.result.result == StepExecutionResult.pass);
final skipped = final skipped =
@ -71,17 +71,17 @@ class TestRunSummaryReporter extends StdoutReporter {
s.result.result == StepExecutionResult.error || s.result.result == StepExecutionResult.error ||
s.result.result == StepExecutionResult.fail || s.result.result == StepExecutionResult.fail ||
s.result.result == StepExecutionResult.timeout); s.result.result == StepExecutionResult.timeout);
if (passed.length > 0) { if (passed.isNotEmpty) {
summaries.add( summaries.add(
"${StdoutReporter.PASS_COLOR}${passed.length} passed${StdoutReporter.RESET_COLOR}"); "${StdoutReporter.PASS_COLOR}${passed.length} passed${StdoutReporter.RESET_COLOR}");
} }
if (skipped.length > 0) { if (skipped.isNotEmpty) {
summaries.add( summaries.add(
"${StdoutReporter.WARN_COLOR}${skipped.length} skipped${StdoutReporter.RESET_COLOR}"); "${StdoutReporter.WARN_COLOR}${skipped.length} skipped${StdoutReporter.RESET_COLOR}");
} }
if (failed.length > 0) { if (failed.isNotEmpty) {
summaries.add( summaries.add(
"${StdoutReporter.FAIL_COLOR}${failed.length} failed${StdoutReporter.RESET_COLOR}"); "${StdoutReporter.FAIL_COLOR}${failed.length} failed${StdoutReporter.RESET_COLOR}");
} }

View File

@ -20,12 +20,12 @@ import 'package:flutter_gherkin/src/reporters/message_level.dart';
import 'package:flutter_gherkin/src/reporters/reporter.dart'; import 'package:flutter_gherkin/src/reporters/reporter.dart';
class GherkinRunner { class GherkinRunner {
final _reporter = new AggregatedReporter(); final _reporter = AggregatedReporter();
final _hook = new AggregatedHook(); final _hook = AggregatedHook();
final _parser = new GherkinParser(); final _parser = GherkinParser();
final _tagExpressionEvaluator = new TagExpressionEvaluator(); final _tagExpressionEvaluator = TagExpressionEvaluator();
final List<ExectuableStep> _executableSteps = new List<ExectuableStep>(); final List<ExectuableStep> _executableSteps = <ExectuableStep>[];
final List<CustomParameter> _customParameters = new List<CustomParameter>(); final List<CustomParameter> _customParameters = <CustomParameter>[];
Future<void> execute(TestConfiguration config) async { Future<void> execute(TestConfiguration config) async {
config.prepare(); config.prepare();
@ -34,7 +34,7 @@ class GherkinRunner {
_registerCustomParameters(config.customStepParameterDefinitions); _registerCustomParameters(config.customStepParameterDefinitions);
_registerStepDefinitions(config.stepDefinitions); _registerStepDefinitions(config.stepDefinitions);
List<FeatureFile> featureFiles = List<FeatureFile>(); List<FeatureFile> featureFiles = <FeatureFile>[];
for (var glob in config.features) { for (var glob in config.features) {
for (var entity in glob.listSync()) { for (var entity in glob.listSync()) {
await _reporter.message( await _reporter.message(
@ -48,7 +48,7 @@ class GherkinRunner {
bool allFeaturesPassed = true; bool allFeaturesPassed = true;
if (featureFiles.length == 0) { if (featureFiles.isEmpty) {
await _reporter.message( await _reporter.message(
"No feature files found to run, exitting without running any scenarios", "No feature files found to run, exitting without running any scenarios",
MessageLevel.warning); MessageLevel.warning);
@ -68,9 +68,9 @@ class GherkinRunner {
try { try {
await _reporter.onTestRunStarted(); await _reporter.onTestRunStarted();
for (var featureFile in featureFiles) { for (var featureFile in featureFiles) {
final runner = new FeatureFileRunner(config, _tagExpressionEvaluator, final runner = FeatureFileRunner(config, _tagExpressionEvaluator,
_executableSteps, _reporter, _hook); _executableSteps, _reporter, _hook);
await runner.run(featureFile); allFeaturesPassed &= await runner.run(featureFile);
} }
} finally { } finally {
await _reporter.onTestRunFinished(); await _reporter.onTestRunFinished();
@ -94,17 +94,17 @@ class GherkinRunner {
} }
void _registerCustomParameters(Iterable<CustomParameter> customParameters) { void _registerCustomParameters(Iterable<CustomParameter> customParameters) {
_customParameters.add(new FloatParameterLower()); _customParameters.add(FloatParameterLower());
_customParameters.add(new FloatParameterCamel()); _customParameters.add(FloatParameterCamel());
_customParameters.add(new NumParameterLower()); _customParameters.add(NumParameterLower());
_customParameters.add(new NumParameterCamel()); _customParameters.add(NumParameterCamel());
_customParameters.add(new IntParameterLower()); _customParameters.add(IntParameterLower());
_customParameters.add(new IntParameterCamel()); _customParameters.add(IntParameterCamel());
_customParameters.add(new StringParameterLower()); _customParameters.add(StringParameterLower());
_customParameters.add(new StringParameterCamel()); _customParameters.add(StringParameterCamel());
_customParameters.add(new WordParameterLower()); _customParameters.add(WordParameterLower());
_customParameters.add(new WordParameterCamel()); _customParameters.add(WordParameterCamel());
_customParameters.add(new PluralParameter()); _customParameters.add(PluralParameter());
if (customParameters != null) _customParameters.addAll(customParameters); if (customParameters != null) _customParameters.addAll(customParameters);
} }

View File

@ -3,7 +3,7 @@ import 'dart:async';
class Perf { class Perf {
static Future<T> measure<T>( static Future<T> measure<T>(
Future<T> action(), void logFn(int elapsedMilliseconds)) async { Future<T> action(), void logFn(int elapsedMilliseconds)) async {
final timer = new Stopwatch(); final timer = Stopwatch();
timer.start(); timer.start();
try { try {
return await action(); return await action();

View File

@ -231,6 +231,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.6.2" version: "1.6.2"
pedantic:
dependency: "direct main"
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.0"
platform: platform:
dependency: transitive dependency: transitive
description: description:

View File

@ -1,6 +1,6 @@
name: flutter_gherkin name: flutter_gherkin
description: A Gherkin / Cucumber parser and test runner for Dart and Flutter description: A Gherkin / Cucumber parser and test runner for Dart and Flutter
version: 0.0.10 version: 0.0.11
author: Jon Samwell <jonsamwell@gmail.com> author: Jon Samwell <jonsamwell@gmail.com>
homepage: https://github.com/jonsamwell/flutter_gherkin homepage: https://github.com/jonsamwell/flutter_gherkin
@ -18,6 +18,7 @@ dependencies:
sdk: flutter sdk: flutter
flutter_driver: flutter_driver:
sdk: flutter sdk: flutter
pedantic: ^1.4.0
dev_dependencies: dev_dependencies:

View File

@ -23,22 +23,21 @@ void main() {
test("run simple feature file scenario", () async { test("run simple feature file scenario", () async {
final stepDefiniton = MockStepDefinition(); final stepDefiniton = MockStepDefinition();
final executableStep = final executableStep =
new ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton); ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton);
final runner = new FeatureFileRunner( final runner = FeatureFileRunner(
TestConfiguration(), TestConfiguration(),
MockTagExpressionEvaluator(), MockTagExpressionEvaluator(),
[executableStep], [executableStep],
ReporterMock(), ReporterMock(),
HookMock()); HookMock());
final step = new StepRunnable( final step = StepRunnable(
"Step 1", RunnableDebugInformation("", 0, "Given I do a")); "Step 1", RunnableDebugInformation("", 0, "Given I do a"));
final scenario = new ScenarioRunnable("Scenario: 1", emptyDebuggable) final scenario = ScenarioRunnable("Scenario: 1", emptyDebuggable)
..steps.add(step); ..steps.add(step);
final feature = new FeatureRunnable("1", emptyDebuggable) final feature = FeatureRunnable("1", emptyDebuggable)
..scenarios.add(scenario); ..scenarios.add(scenario);
final featureFile = new FeatureFile(emptyDebuggable) final featureFile = FeatureFile(emptyDebuggable)..features.add(feature);
..features.add(feature);
await runner.run(featureFile); await runner.run(featureFile);
expect(stepDefiniton.hasRun, true); expect(stepDefiniton.hasRun, true);
expect(stepDefiniton.runCount, 1); expect(stepDefiniton.runCount, 1);
@ -49,8 +48,8 @@ void main() {
bool worldCreationFnInoked = false; bool worldCreationFnInoked = false;
final stepDefiniton = MockStepDefinition(); final stepDefiniton = MockStepDefinition();
final executableStep = final executableStep =
new ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton); ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton);
final runner = new FeatureFileRunner( final runner = FeatureFileRunner(
TestConfiguration() TestConfiguration()
..createWorld = (_) async { ..createWorld = (_) async {
worldCreationFnInoked = true; worldCreationFnInoked = true;
@ -61,14 +60,13 @@ void main() {
ReporterMock(), ReporterMock(),
HookMock()); HookMock());
final step = new StepRunnable( final step = StepRunnable(
"Step 1", RunnableDebugInformation("", 0, "Given I do a")); "Step 1", RunnableDebugInformation("", 0, "Given I do a"));
final scenario = new ScenarioRunnable("Scenario: 1", emptyDebuggable) final scenario = ScenarioRunnable("Scenario: 1", emptyDebuggable)
..steps.add(step); ..steps.add(step);
final feature = new FeatureRunnable("1", emptyDebuggable) final feature = FeatureRunnable("1", emptyDebuggable)
..scenarios.add(scenario); ..scenarios.add(scenario);
final featureFile = new FeatureFile(emptyDebuggable) final featureFile = FeatureFile(emptyDebuggable)..features.add(feature);
..features.add(feature);
await runner.run(featureFile); await runner.run(featureFile);
expect(worldCreationFnInoked, true); expect(worldCreationFnInoked, true);
expect(worldMock.disposeFnInvoked, true); expect(worldMock.disposeFnInvoked, true);
@ -77,30 +75,29 @@ void main() {
test("steps are skipped if previous step failed", () async { test("steps are skipped if previous step failed", () async {
final stepTextOne = "Given I do a"; final stepTextOne = "Given I do a";
final stepTextTwo = "Given I do b"; final stepTextTwo = "Given I do b";
final stepDefiniton = MockStepDefinition((_) => throw new Exception()); final stepDefiniton = MockStepDefinition((_) => throw Exception());
final stepDefinitonTwo = MockStepDefinition(); final stepDefinitonTwo = MockStepDefinition();
final executableStep = new ExectuableStep( final executableStep = ExectuableStep(
MockGherkinExpression((s) => s == stepTextOne), stepDefiniton); MockGherkinExpression((s) => s == stepTextOne), stepDefiniton);
final executableStepTwo = new ExectuableStep( final executableStepTwo = ExectuableStep(
MockGherkinExpression((s) => s == stepTextTwo), stepDefinitonTwo); MockGherkinExpression((s) => s == stepTextTwo), stepDefinitonTwo);
final runner = new FeatureFileRunner( final runner = FeatureFileRunner(
TestConfiguration(), TestConfiguration(),
MockTagExpressionEvaluator(), MockTagExpressionEvaluator(),
[executableStep, executableStepTwo], [executableStep, executableStepTwo],
ReporterMock(), ReporterMock(),
HookMock()); HookMock());
final step = new StepRunnable( final step =
"Step 1", RunnableDebugInformation("", 0, stepTextOne)); StepRunnable("Step 1", RunnableDebugInformation("", 0, stepTextOne));
final stepTwo = new StepRunnable( final stepTwo =
"Step 2", RunnableDebugInformation("", 0, stepTextTwo)); StepRunnable("Step 2", RunnableDebugInformation("", 0, stepTextTwo));
final scenario = new ScenarioRunnable("Scenario: 1", emptyDebuggable) final scenario = ScenarioRunnable("Scenario: 1", emptyDebuggable)
..steps.add(step) ..steps.add(step)
..steps.add(stepTwo); ..steps.add(stepTwo);
final feature = new FeatureRunnable("1", emptyDebuggable) final feature = FeatureRunnable("1", emptyDebuggable)
..scenarios.add(scenario); ..scenarios.add(scenario);
final featureFile = new FeatureFile(emptyDebuggable) final featureFile = FeatureFile(emptyDebuggable)..features.add(feature);
..features.add(feature);
await runner.run(featureFile); await runner.run(featureFile);
expect(stepDefiniton.hasRun, true); expect(stepDefiniton.hasRun, true);
expect(stepDefiniton.runCount, 1); expect(stepDefiniton.runCount, 1);
@ -110,23 +107,22 @@ void main() {
group("step matching", () { group("step matching", () {
test("exception throw when matching step definition not found", () async { test("exception throw when matching step definition not found", () async {
final stepDefiniton = MockStepDefinition(); final stepDefiniton = MockStepDefinition();
final executableStep = new ExectuableStep( final executableStep =
MockGherkinExpression((_) => false), stepDefiniton); ExectuableStep(MockGherkinExpression((_) => false), stepDefiniton);
final runner = new FeatureFileRunner( final runner = FeatureFileRunner(
TestConfiguration(), TestConfiguration(),
MockTagExpressionEvaluator(), MockTagExpressionEvaluator(),
[executableStep], [executableStep],
ReporterMock(), ReporterMock(),
HookMock()); HookMock());
final step = new StepRunnable("Step 1", final step = StepRunnable("Step 1",
RunnableDebugInformation("File Path", 2, "Given I do 'a'")); RunnableDebugInformation("File Path", 2, "Given I do 'a'"));
final scenario = new ScenarioRunnable("Scenario: 1", emptyDebuggable) final scenario = ScenarioRunnable("Scenario: 1", emptyDebuggable)
..steps.add(step); ..steps.add(step);
final feature = new FeatureRunnable("1", emptyDebuggable) final feature = FeatureRunnable("1", emptyDebuggable)
..scenarios.add(scenario); ..scenarios.add(scenario);
final featureFile = new FeatureFile(emptyDebuggable) final featureFile = FeatureFile(emptyDebuggable)..features.add(feature);
..features.add(feature);
expect( expect(
() async => await runner.run(featureFile), () async => await runner.run(featureFile),
throwsA(allOf( throwsA(allOf(
@ -172,24 +168,23 @@ void main() {
MockStepDefinition((Iterable<dynamic> parameters) async { MockStepDefinition((Iterable<dynamic> parameters) async {
tableParameterProvided = parameters.first is Table; tableParameterProvided = parameters.first is Table;
}, 1); }, 1);
final executableStep = new ExectuableStep( final executableStep =
MockGherkinExpression((_) => true), stepDefiniton); ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton);
final runner = new FeatureFileRunner( final runner = FeatureFileRunner(
TestConfiguration(), TestConfiguration(),
MockTagExpressionEvaluator(), MockTagExpressionEvaluator(),
[executableStep], [executableStep],
ReporterMock(), ReporterMock(),
HookMock()); HookMock());
final step = new StepRunnable( final step = StepRunnable(
"Step 1", RunnableDebugInformation("", 0, "Given I do a")); "Step 1", RunnableDebugInformation("", 0, "Given I do a"));
step.table = new Table(null, null); step.table = Table(null, null);
final scenario = new ScenarioRunnable("Scenario: 1", emptyDebuggable) final scenario = ScenarioRunnable("Scenario: 1", emptyDebuggable)
..steps.add(step); ..steps.add(step);
final feature = new FeatureRunnable("1", emptyDebuggable) final feature = FeatureRunnable("1", emptyDebuggable)
..scenarios.add(scenario); ..scenarios.add(scenario);
final featureFile = new FeatureFile(emptyDebuggable) final featureFile = FeatureFile(emptyDebuggable)..features.add(feature);
..features.add(feature);
await runner.run(featureFile); await runner.run(featureFile);
expect(stepDefiniton.hasRun, true); expect(stepDefiniton.hasRun, true);
expect(stepDefiniton.runCount, 1); expect(stepDefiniton.runCount, 1);
@ -201,26 +196,25 @@ void main() {
test("hook is called when starting and finishing scenarios", () async { test("hook is called when starting and finishing scenarios", () async {
final hookMock = HookMock(); final hookMock = HookMock();
final stepDefiniton = MockStepDefinition(); final stepDefiniton = MockStepDefinition();
final executableStep = new ExectuableStep( final executableStep =
MockGherkinExpression((_) => true), stepDefiniton); ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton);
final runner = new FeatureFileRunner( final runner = FeatureFileRunner(
TestConfiguration(), TestConfiguration(),
MockTagExpressionEvaluator(), MockTagExpressionEvaluator(),
[executableStep], [executableStep],
ReporterMock(), ReporterMock(),
hookMock); hookMock);
final step = new StepRunnable( final step = StepRunnable(
"Step 1", RunnableDebugInformation("", 0, "Given I do a")); "Step 1", RunnableDebugInformation("", 0, "Given I do a"));
final scenario1 = new ScenarioRunnable("Scenario: 1", emptyDebuggable) final scenario1 = ScenarioRunnable("Scenario: 1", emptyDebuggable)
..steps.add(step); ..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(scenario1)
..scenarios.add(scenario2); ..scenarios.add(scenario2);
final featureFile = new FeatureFile(emptyDebuggable) final featureFile = FeatureFile(emptyDebuggable)..features.add(feature);
..features.add(feature);
await runner.run(featureFile); await runner.run(featureFile);
expect(hookMock.onBeforeScenarioInvocationCount, 2); expect(hookMock.onBeforeScenarioInvocationCount, 2);
expect(hookMock.onAfterScenarioInvocationCount, 2); expect(hookMock.onAfterScenarioInvocationCount, 2);
@ -232,27 +226,26 @@ void main() {
() async { () async {
final reporterMock = ReporterMock(); final reporterMock = ReporterMock();
final stepDefiniton = MockStepDefinition(); final stepDefiniton = MockStepDefinition();
final executableStep = new ExectuableStep( final executableStep =
MockGherkinExpression((_) => true), stepDefiniton); ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton);
final runner = new FeatureFileRunner( final runner = FeatureFileRunner(
TestConfiguration(), TestConfiguration(),
MockTagExpressionEvaluator(), MockTagExpressionEvaluator(),
[executableStep], [executableStep],
reporterMock, reporterMock,
HookMock()); HookMock());
final step = new StepRunnable( final step = StepRunnable(
"Step 1", RunnableDebugInformation("", 0, "Given I do a")); "Step 1", RunnableDebugInformation("", 0, "Given I do a"));
final scenario1 = new ScenarioRunnable("Scenario: 1", emptyDebuggable) final scenario1 = ScenarioRunnable("Scenario: 1", emptyDebuggable)
..steps.add(step); ..steps.add(step);
final scenario2 = new ScenarioRunnable("Scenario: 2", emptyDebuggable) final scenario2 = ScenarioRunnable("Scenario: 2", emptyDebuggable)
..steps.add(step) ..steps.add(step)
..steps.add(step); ..steps.add(step);
final feature = new FeatureRunnable("1", emptyDebuggable) final feature = FeatureRunnable("1", emptyDebuggable)
..scenarios.add(scenario1) ..scenarios.add(scenario1)
..scenarios.add(scenario2); ..scenarios.add(scenario2);
final featureFile = new FeatureFile(emptyDebuggable) final featureFile = FeatureFile(emptyDebuggable)..features.add(feature);
..features.add(feature);
await runner.run(featureFile); await runner.run(featureFile);
expect(reporterMock.onFeatureStartedInvocationCount, 1); expect(reporterMock.onFeatureStartedInvocationCount, 1);
expect(reporterMock.onFeatureFinishedInvocationCount, 1); expect(reporterMock.onFeatureFinishedInvocationCount, 1);
@ -269,23 +262,22 @@ void main() {
final reporterMock = ReporterMock(); final reporterMock = ReporterMock();
reporterMock.onStepFinishedFn = (message) => finishedMessage = message; reporterMock.onStepFinishedFn = (message) => finishedMessage = message;
final stepDefiniton = MockStepDefinition(); final stepDefiniton = MockStepDefinition();
final executableStep = new ExectuableStep( final executableStep =
MockGherkinExpression((_) => true), stepDefiniton); ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton);
final runner = new FeatureFileRunner( final runner = FeatureFileRunner(
TestConfiguration(), TestConfiguration(),
MockTagExpressionEvaluator(), MockTagExpressionEvaluator(),
[executableStep], [executableStep],
reporterMock, reporterMock,
HookMock()); HookMock());
final step = new StepRunnable( final step = StepRunnable(
"Step 1", RunnableDebugInformation("", 0, "Given I do a")); "Step 1", RunnableDebugInformation("", 0, "Given I do a"));
final scenario1 = new ScenarioRunnable("Scenario: 1", emptyDebuggable) final scenario1 = ScenarioRunnable("Scenario: 1", emptyDebuggable)
..steps.add(step); ..steps.add(step);
final feature = new FeatureRunnable("1", emptyDebuggable) final feature = FeatureRunnable("1", emptyDebuggable)
..scenarios.add(scenario1); ..scenarios.add(scenario1);
final featureFile = new FeatureFile(emptyDebuggable) final featureFile = FeatureFile(emptyDebuggable)..features.add(feature);
..features.add(feature);
await runner.run(featureFile); await runner.run(featureFile);
expect(stepDefiniton.hasRun, true); expect(stepDefiniton.hasRun, true);
expect(finishedMessage, (m) => m.name == "Step 1"); expect(finishedMessage, (m) => m.name == "Step 1");
@ -300,23 +292,22 @@ void main() {
reporterMock.onStepFinishedFn = (message) => finishedMessage = message; reporterMock.onStepFinishedFn = (message) => finishedMessage = message;
final stepDefiniton = final stepDefiniton =
MockStepDefinition((_) => throw testFailureException); MockStepDefinition((_) => throw testFailureException);
final executableStep = new ExectuableStep( final executableStep =
MockGherkinExpression((_) => true), stepDefiniton); ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton);
final runner = new FeatureFileRunner( final runner = FeatureFileRunner(
TestConfiguration(), TestConfiguration(),
MockTagExpressionEvaluator(), MockTagExpressionEvaluator(),
[executableStep], [executableStep],
reporterMock, reporterMock,
HookMock()); HookMock());
final step = new StepRunnable( final step = StepRunnable(
"Step 1", RunnableDebugInformation("", 0, "Given I do a")); "Step 1", RunnableDebugInformation("", 0, "Given I do a"));
final scenario1 = new ScenarioRunnable("Scenario: 1", emptyDebuggable) final scenario1 = ScenarioRunnable("Scenario: 1", emptyDebuggable)
..steps.add(step); ..steps.add(step);
final feature = new FeatureRunnable("1", emptyDebuggable) final feature = FeatureRunnable("1", emptyDebuggable)
..scenarios.add(scenario1); ..scenarios.add(scenario1);
final featureFile = new FeatureFile(emptyDebuggable) final featureFile = FeatureFile(emptyDebuggable)..features.add(feature);
..features.add(feature);
await runner.run(featureFile); await runner.run(featureFile);
expect(stepDefiniton.hasRun, true); expect(stepDefiniton.hasRun, true);
expect(finishedMessage, (m) => m.name == "Step 1"); expect(finishedMessage, (m) => m.name == "Step 1");
@ -332,23 +323,22 @@ void main() {
reporterMock.onStepFinishedFn = (message) => finishedMessage = message; reporterMock.onStepFinishedFn = (message) => finishedMessage = message;
final stepDefiniton = MockStepDefinition( final stepDefiniton = MockStepDefinition(
(_) async => await Future.delayed(Duration(seconds: 2))); (_) async => await Future.delayed(Duration(seconds: 2)));
final executableStep = new ExectuableStep( final executableStep =
MockGherkinExpression((_) => true), stepDefiniton); ExectuableStep(MockGherkinExpression((_) => true), stepDefiniton);
final runner = new FeatureFileRunner( final runner = FeatureFileRunner(
TestConfiguration()..defaultTimeout = Duration(milliseconds: 1), TestConfiguration()..defaultTimeout = Duration(milliseconds: 1),
MockTagExpressionEvaluator(), MockTagExpressionEvaluator(),
[executableStep], [executableStep],
reporterMock, reporterMock,
HookMock()); HookMock());
final step = new StepRunnable( final step = StepRunnable(
"Step 1", RunnableDebugInformation("", 0, "Given I do a")); "Step 1", RunnableDebugInformation("", 0, "Given I do a"));
final scenario1 = new ScenarioRunnable("Scenario: 1", emptyDebuggable) final scenario1 = ScenarioRunnable("Scenario: 1", emptyDebuggable)
..steps.add(step); ..steps.add(step);
final feature = new FeatureRunnable("1", emptyDebuggable) final feature = FeatureRunnable("1", emptyDebuggable)
..scenarios.add(scenario1); ..scenarios.add(scenario1);
final featureFile = new FeatureFile(emptyDebuggable) final featureFile = FeatureFile(emptyDebuggable)..features.add(feature);
..features.add(feature);
await runner.run(featureFile); await runner.run(featureFile);
expect(stepDefiniton.hasRun, true); expect(stepDefiniton.hasRun, true);
expect(finishedMessage, (m) => m.name == "Step 1"); expect(finishedMessage, (m) => m.name == "Step 1");
@ -357,7 +347,7 @@ void main() {
}); });
test("skipped step reported correctly", () async { test("skipped step reported correctly", () async {
final finishedMessages = List<StepFinishedMessage>(); final finishedMessages = <StepFinishedMessage>[];
final reporterMock = ReporterMock(); final reporterMock = ReporterMock();
reporterMock.onStepFinishedFn = reporterMock.onStepFinishedFn =
(message) => finishedMessages.add(message); (message) => finishedMessages.add(message);
@ -365,37 +355,36 @@ void main() {
final stepTextOne = "Given I do a"; final stepTextOne = "Given I do a";
final stepTextTwo = "Given I do b"; final stepTextTwo = "Given I do b";
final stepTextThree = "Given I do c"; final stepTextThree = "Given I do c";
final stepDefiniton = MockStepDefinition((_) => throw new Exception()); final stepDefiniton = MockStepDefinition((_) => throw Exception());
final stepDefinitonTwo = MockStepDefinition(); final stepDefinitonTwo = MockStepDefinition();
final stepDefinitonThree = MockStepDefinition(); final stepDefinitonThree = MockStepDefinition();
final executableStep = new ExectuableStep( final executableStep = ExectuableStep(
MockGherkinExpression((s) => s == stepTextOne), stepDefiniton); MockGherkinExpression((s) => s == stepTextOne), stepDefiniton);
final executableStepTwo = new ExectuableStep( final executableStepTwo = ExectuableStep(
MockGherkinExpression((s) => s == stepTextTwo), stepDefinitonTwo); MockGherkinExpression((s) => s == stepTextTwo), stepDefinitonTwo);
final executableStepThree = new ExectuableStep( final executableStepThree = ExectuableStep(
MockGherkinExpression((s) => s == stepTextThree), MockGherkinExpression((s) => s == stepTextThree),
stepDefinitonThree); stepDefinitonThree);
final runner = new FeatureFileRunner( final runner = FeatureFileRunner(
TestConfiguration()..defaultTimeout = Duration(milliseconds: 1), TestConfiguration()..defaultTimeout = Duration(milliseconds: 1),
MockTagExpressionEvaluator(), MockTagExpressionEvaluator(),
[executableStep, executableStepTwo, executableStepThree], [executableStep, executableStepTwo, executableStepThree],
reporterMock, reporterMock,
HookMock()); HookMock());
final step = new StepRunnable( final step = StepRunnable(
"Step 1", RunnableDebugInformation("", 0, stepTextOne)); "Step 1", RunnableDebugInformation("", 0, stepTextOne));
final stepTwo = new StepRunnable( final stepTwo = StepRunnable(
"Step 2", RunnableDebugInformation("", 0, stepTextTwo)); "Step 2", RunnableDebugInformation("", 0, stepTextTwo));
final stepThree = new StepRunnable( final stepThree = StepRunnable(
"Step 3", RunnableDebugInformation("", 0, stepTextThree)); "Step 3", RunnableDebugInformation("", 0, stepTextThree));
final scenario1 = new ScenarioRunnable("Scenario: 1", emptyDebuggable) final scenario1 = ScenarioRunnable("Scenario: 1", emptyDebuggable)
..steps.add(step) ..steps.add(step)
..steps.add(stepTwo) ..steps.add(stepTwo)
..steps.add(stepThree); ..steps.add(stepThree);
final feature = new FeatureRunnable("1", emptyDebuggable) final feature = FeatureRunnable("1", emptyDebuggable)
..scenarios.add(scenario1); ..scenarios.add(scenario1);
final featureFile = new FeatureFile(emptyDebuggable) final featureFile = FeatureFile(emptyDebuggable)..features.add(feature);
..features.add(feature);
await runner.run(featureFile); await runner.run(featureFile);
expect(stepDefiniton.hasRun, true); expect(stepDefiniton.hasRun, true);
expect(finishedMessages.length, 3); expect(finishedMessages.length, 3);

View File

@ -9,7 +9,7 @@ import 'package:test/test.dart';
void main() { void main() {
group("GherkinExpression", () { group("GherkinExpression", () {
test('parse simple regex expression correctly', () async { 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()]); [WordParameterLower(), WordParameterCamel()]);
expect(parser.isMatch("I open the drawer"), equals(true)); expect(parser.isMatch("I open the drawer"), equals(true));
@ -20,7 +20,7 @@ void main() {
test('parse complex regex with custom parameters expression correctly', test('parse complex regex with custom parameters expression correctly',
() async { () async {
final parser = new GherkinExpression( final parser = GherkinExpression(
RegExp( RegExp(
'I (open|close) the drawer {int} time(s) and find {word} which is (good|bad)'), 'I (open|close) the drawer {int} time(s) and find {word} which is (good|bad)'),
[WordParameterLower(), IntParameterLower(), PluralParameter()]); [WordParameterLower(), IntParameterLower(), PluralParameter()]);
@ -44,7 +44,7 @@ void main() {
}); });
test('parse simple {word} expression correctly', () async { 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()]); [WordParameterLower(), WordParameterCamel()]);
expect(parser.isMatch("I am 'happy'"), equals(false)); expect(parser.isMatch("I am 'happy'"), equals(false));
@ -54,8 +54,8 @@ void main() {
}); });
test('parse simple {string} expression correctly', () async { test('parse simple {string} expression correctly', () async {
final parser = new GherkinExpression( final parser =
RegExp('I am {string}'), [StringParameterLower()]); GherkinExpression(RegExp('I am {string}'), [StringParameterLower()]);
expect(parser.isMatch("I am 'happy as Larry'"), equals(true)); expect(parser.isMatch("I am 'happy as Larry'"), equals(true));
expect(parser.getParameters("I am 'happy as Larry'"), expect(parser.getParameters("I am 'happy as Larry'"),
@ -63,7 +63,7 @@ void main() {
}); });
test('parse simple {int} expression correctly', () async { test('parse simple {int} expression correctly', () async {
final parser = new GherkinExpression( final parser = GherkinExpression(
RegExp('I am {int} years and {Int} days old'), RegExp('I am {int} years and {Int} days old'),
[IntParameterLower(), IntParameterCamel()]); [IntParameterLower(), IntParameterCamel()]);
@ -73,7 +73,7 @@ void main() {
}); });
test('parse simple {float} expression correctly', () async { test('parse simple {float} expression correctly', () async {
final parser = new GherkinExpression( final parser = GherkinExpression(
RegExp('I am {float} years and {Float} days old'), RegExp('I am {float} years and {Float} days old'),
[FloatParameterLower(), FloatParameterCamel()]); [FloatParameterLower(), FloatParameterCamel()]);
@ -84,7 +84,7 @@ void main() {
}); });
test('parse simple plural (s) expression correctly', () async { test('parse simple plural (s) expression correctly', () async {
final parser = new GherkinExpression( final parser = GherkinExpression(
RegExp('I have {int} cucumber(s) in my belly'), RegExp('I have {int} cucumber(s) in my belly'),
[IntParameterLower(), PluralParameter()]); [IntParameterLower(), PluralParameter()]);
@ -97,7 +97,7 @@ void main() {
}); });
test('parse complex expression correctly', () async { test('parse complex expression correctly', () async {
final parser = new GherkinExpression( final parser = GherkinExpression(
RegExp( RegExp(
'{word} {int} {string} {int} (jon|laurie) {float} {word} {float} cucumber(s)'), '{word} {int} {string} {int} (jon|laurie) {float} {word} {float} cucumber(s)'),
[ [

View File

@ -4,7 +4,7 @@ import "package:test/test.dart";
void main() { void main() {
group("TagExpression", () { group("TagExpression", () {
test("evaluate simple single tag expression correctly", () async { test("evaluate simple single tag expression correctly", () async {
final evaluator = new TagExpressionEvaluator(); final evaluator = TagExpressionEvaluator();
final tags = ["a", "b", "c"]; final tags = ["a", "b", "c"];
expect(evaluator.evaluate("@a", tags), true); expect(evaluator.evaluate("@a", tags), true);
@ -13,7 +13,7 @@ void main() {
}); });
test("evaluate complex and tag expression correctly", () async { test("evaluate complex and tag expression correctly", () async {
final evaluator = new TagExpressionEvaluator(); final evaluator = TagExpressionEvaluator();
final tags = ["a", "b", "c"]; final tags = ["a", "b", "c"];
expect(evaluator.evaluate("@a and @d", tags), false); expect(evaluator.evaluate("@a and @d", tags), false);
@ -22,7 +22,7 @@ void main() {
}); });
test("evaluate complex or tag expression correctly", () async { test("evaluate complex or tag expression correctly", () async {
final evaluator = new TagExpressionEvaluator(); final evaluator = TagExpressionEvaluator();
final tags = ["a", "b", "c"]; final tags = ["a", "b", "c"];
expect(evaluator.evaluate("(@a or @b)", tags), true); expect(evaluator.evaluate("(@a or @b)", tags), true);
@ -31,7 +31,7 @@ void main() {
}); });
test("evaluate complex bracket tag expression correctly", () async { test("evaluate complex bracket tag expression correctly", () async {
final evaluator = new TagExpressionEvaluator(); final evaluator = TagExpressionEvaluator();
final tags = ["a", "b", "c"]; final tags = ["a", "b", "c"];
expect(evaluator.evaluate("@a or (@b and @c)", tags), true); expect(evaluator.evaluate("@a or (@b and @c)", tags), true);

View File

@ -6,7 +6,7 @@ import '../mocks/reporter_mock.dart';
void main() { void main() {
group("parse", () { group("parse", () {
test('parses simple, single scenario correctly', () async { test('parses simple, single scenario correctly', () async {
final parser = new GherkinParser(); final parser = GherkinParser();
final featureContents = """ final featureContents = """
# language: en # language: en
Feature: The name of the feature Feature: The name of the feature
@ -30,7 +30,7 @@ void main() {
When I do step c When I do step c
Then I expect to see d Then I expect to see d
"""; """;
FeatureFile featureFile = final FeatureFile featureFile =
await parser.parseFeatureFile(featureContents, "", ReporterMock()); await parser.parseFeatureFile(featureContents, "", ReporterMock());
expect(featureFile, isNot(null)); expect(featureFile, isNot(null));
expect(featureFile.langauge, equals("en")); expect(featureFile.langauge, equals("en"));
@ -66,7 +66,7 @@ void main() {
}); });
test('parses complex multi-scenario correctly', () async { test('parses complex multi-scenario correctly', () async {
final parser = new GherkinParser(); final parser = GherkinParser();
final featureContents = """ final featureContents = """
# language: en # language: en
Feature: The name of the feature Feature: The name of the feature
@ -97,7 +97,7 @@ void main() {
# When I do step c.1 # When I do step c.1
Then I expect to see d Then I expect to see d
"""; """;
FeatureFile featureFile = final FeatureFile featureFile =
await parser.parseFeatureFile(featureContents, "", ReporterMock()); await parser.parseFeatureFile(featureContents, "", ReporterMock());
expect(featureFile, isNot(null)); expect(featureFile, isNot(null));
expect(featureFile.langauge, equals("en")); expect(featureFile.langauge, equals("en"));

View File

@ -8,12 +8,12 @@ void main() {
final debugInfo = RunnableDebugInformation(null, 0, null); final debugInfo = RunnableDebugInformation(null, 0, null);
group("addChild", () { group("addChild", () {
test('can add LangaugeRunnable', () { test('can add LangaugeRunnable', () {
final runnable = new FeatureFile(debugInfo); final runnable = FeatureFile(debugInfo);
runnable.addChild(LanguageRunnable(debugInfo)..language = "en"); runnable.addChild(LanguageRunnable(debugInfo)..language = "en");
expect(runnable.langauge, "en"); expect(runnable.langauge, "en");
}); });
test('can add TagsRunnable', () { test('can add TagsRunnable', () {
final runnable = new FeatureFile(debugInfo); final runnable = FeatureFile(debugInfo);
runnable.addChild(FeatureRunnable("1", debugInfo)); runnable.addChild(FeatureRunnable("1", debugInfo));
runnable.addChild(FeatureRunnable("2", debugInfo)); runnable.addChild(FeatureRunnable("2", debugInfo));
runnable.addChild(FeatureRunnable("3", debugInfo)); runnable.addChild(FeatureRunnable("3", debugInfo));

View File

@ -12,27 +12,27 @@ void main() {
final debugInfo = RunnableDebugInformation(null, 0, null); final debugInfo = RunnableDebugInformation(null, 0, null);
group("addChild", () { group("addChild", () {
test('can add TextLineRunnable', () { 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");
runnable.addChild(TextLineRunnable(debugInfo)..text = "text line two"); runnable.addChild(TextLineRunnable(debugInfo)..text = "text line two");
expect(runnable.description, "text\ntext line two"); expect(runnable.description, "text\ntext line two");
}); });
test('can add TagsRunnable', () { 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 = ["one", "two"]);
runnable.addChild(TagsRunnable(debugInfo)..tags = ["three"]); runnable.addChild(TagsRunnable(debugInfo)..tags = ["three"]);
expect(runnable.tags, ["one", "two", "three"]); expect(runnable.tags, ["one", "two", "three"]);
}); });
test('can add EmptyLineRunnable', () { test('can add EmptyLineRunnable', () {
final runnable = new FeatureRunnable("", debugInfo); final runnable = FeatureRunnable("", debugInfo);
runnable.addChild(EmptyLineRunnable(debugInfo)); runnable.addChild(EmptyLineRunnable(debugInfo));
}); });
test('can add CommentLineRunnable', () { test('can add CommentLineRunnable', () {
final runnable = new FeatureRunnable("", debugInfo); final runnable = FeatureRunnable("", debugInfo);
runnable.addChild(CommentLineRunnable("", debugInfo)); runnable.addChild(CommentLineRunnable("", debugInfo));
}); });
test('can add ScenarioRunnable', () { test('can add ScenarioRunnable', () {
final runnable = new FeatureRunnable("", debugInfo); final runnable = FeatureRunnable("", debugInfo);
runnable.addChild(ScenarioRunnable("1", debugInfo)); runnable.addChild(ScenarioRunnable("1", debugInfo));
runnable.addChild(ScenarioRunnable("2", debugInfo)); runnable.addChild(ScenarioRunnable("2", debugInfo));
runnable.addChild(ScenarioRunnable("3", debugInfo)); runnable.addChild(ScenarioRunnable("3", debugInfo));
@ -42,7 +42,7 @@ void main() {
expect(runnable.scenarios.elementAt(2).name, "3"); expect(runnable.scenarios.elementAt(2).name, "3");
}); });
test('can add BackgroundRunnable', () { test('can add BackgroundRunnable', () {
final runnable = new FeatureRunnable("", debugInfo); final runnable = FeatureRunnable("", debugInfo);
runnable.addChild(BackgroundRunnable("1", debugInfo)); runnable.addChild(BackgroundRunnable("1", debugInfo));
expect(runnable.background, isNotNull); expect(runnable.background, isNotNull);
expect(runnable.background.name, "1"); expect(runnable.background.name, "1");

View File

@ -8,11 +8,11 @@ void main() {
final debugInfo = RunnableDebugInformation(null, 0, null); final debugInfo = RunnableDebugInformation(null, 0, null);
group("addChild", () { group("addChild", () {
test('can add EmptyLineRunnable', () { test('can add EmptyLineRunnable', () {
final runnable = new MultilineStringRunnable(debugInfo); final runnable = MultilineStringRunnable(debugInfo);
runnable.addChild(EmptyLineRunnable(debugInfo)); runnable.addChild(EmptyLineRunnable(debugInfo));
}); });
test('can add TextLineRunnable', () { test('can add TextLineRunnable', () {
final runnable = new MultilineStringRunnable(debugInfo); final runnable = MultilineStringRunnable(debugInfo);
runnable.addChild(TextLineRunnable(debugInfo)..text = "1"); runnable.addChild(TextLineRunnable(debugInfo)..text = "1");
runnable.addChild(TextLineRunnable(debugInfo)..text = "2"); runnable.addChild(TextLineRunnable(debugInfo)..text = "2");
runnable.addChild(TextLineRunnable(debugInfo)..text = "3"); runnable.addChild(TextLineRunnable(debugInfo)..text = "3");

View File

@ -9,11 +9,11 @@ void main() {
final debugInfo = RunnableDebugInformation(null, 0, null); final debugInfo = RunnableDebugInformation(null, 0, null);
group("addChild", () { group("addChild", () {
test('can add EmptyLineRunnable', () { test('can add EmptyLineRunnable', () {
final runnable = new ScenarioRunnable("", debugInfo); final runnable = ScenarioRunnable("", debugInfo);
runnable.addChild(EmptyLineRunnable(debugInfo)); runnable.addChild(EmptyLineRunnable(debugInfo));
}); });
test('can add StepRunnable', () { test('can add StepRunnable', () {
final runnable = new ScenarioRunnable("", debugInfo); final runnable = ScenarioRunnable("", debugInfo);
runnable.addChild(StepRunnable("1", debugInfo)); runnable.addChild(StepRunnable("1", debugInfo));
runnable.addChild(StepRunnable("2", debugInfo)); runnable.addChild(StepRunnable("2", debugInfo));
runnable.addChild(StepRunnable("3", debugInfo)); runnable.addChild(StepRunnable("3", debugInfo));
@ -23,7 +23,7 @@ void main() {
expect(runnable.steps.elementAt(2).name, "3"); expect(runnable.steps.elementAt(2).name, "3");
}); });
test('can add TagsRunnable', () { 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 = ["one", "two"]);
runnable.addChild(TagsRunnable(debugInfo)..tags = ["three"]); runnable.addChild(TagsRunnable(debugInfo)..tags = ["three"]);
expect(runnable.tags, ["one", "two", "three"]); expect(runnable.tags, ["one", "two", "three"]);

View File

@ -9,7 +9,7 @@ void main() {
final debugInfo = RunnableDebugInformation(null, 0, null); final debugInfo = RunnableDebugInformation(null, 0, null);
group("addChild", () { group("addChild", () {
test('can add MultilineStringRunnable', () { test('can add MultilineStringRunnable', () {
final runnable = new StepRunnable("", debugInfo); final runnable = StepRunnable("", debugInfo);
runnable.addChild( runnable.addChild(
MultilineStringRunnable(debugInfo)..lines = ["1", "2", "3"].toList()); MultilineStringRunnable(debugInfo)..lines = ["1", "2", "3"].toList());
runnable.addChild( runnable.addChild(
@ -20,7 +20,7 @@ void main() {
}); });
test('can add TableRunnable', () { test('can add TableRunnable', () {
final runnable = new StepRunnable("", debugInfo); final runnable = StepRunnable("", debugInfo);
runnable.addChild(TableRunnable(debugInfo) runnable.addChild(TableRunnable(debugInfo)
..addChild(TableRunnable(debugInfo)..rows.add("|Col A|Col B|")) ..addChild(TableRunnable(debugInfo)..rows.add("|Col A|Col B|"))
..addChild(TableRunnable(debugInfo)..rows.add("|1|2|")) ..addChild(TableRunnable(debugInfo)..rows.add("|1|2|"))
@ -33,7 +33,7 @@ void main() {
}); });
test('can only add single TableRunnable', () { test('can only add single TableRunnable', () {
final runnable = new StepRunnable("Step A", debugInfo); final runnable = StepRunnable("Step A", debugInfo);
runnable.addChild(TableRunnable(debugInfo) runnable.addChild(TableRunnable(debugInfo)
..addChild(TableRunnable(debugInfo)..rows.add("|Col A|Col B|")) ..addChild(TableRunnable(debugInfo)..rows.add("|Col A|Col B|"))
..addChild(TableRunnable(debugInfo)..rows.add("|1|2|")) ..addChild(TableRunnable(debugInfo)..rows.add("|1|2|"))

View File

@ -7,11 +7,11 @@ void main() {
final debugInfo = RunnableDebugInformation(null, 0, null); final debugInfo = RunnableDebugInformation(null, 0, null);
group("addChild", () { group("addChild", () {
test('can add CommentLineRunnable', () { test('can add CommentLineRunnable', () {
final runnable = new TableRunnable(debugInfo); final runnable = TableRunnable(debugInfo);
runnable.addChild(CommentLineRunnable("", debugInfo)); runnable.addChild(CommentLineRunnable("", debugInfo));
}); });
test('can add TableRunnable', () { test('can add TableRunnable', () {
final runnable = new TableRunnable(debugInfo); final runnable = TableRunnable(debugInfo);
runnable.addChild( runnable.addChild(
TableRunnable(debugInfo)..rows.add("| Header 1 | Header 2 |")); TableRunnable(debugInfo)..rows.add("| Header 1 | Header 2 |"));
runnable.addChild(TableRunnable(debugInfo)..rows.add("| 1 | 2 |")); runnable.addChild(TableRunnable(debugInfo)..rows.add("| 1 | 2 |"));
@ -24,7 +24,7 @@ void main() {
group("to table", () { group("to table", () {
test("single row table has no header row", () async { test("single row table has no header row", () async {
final runnable = new TableRunnable(debugInfo); final runnable = TableRunnable(debugInfo);
runnable.addChild( runnable.addChild(
TableRunnable(debugInfo)..rows.add("| one | two | three |")); TableRunnable(debugInfo)..rows.add("| one | two | three |"));
final table = runnable.toTable(); final table = runnable.toTable();
@ -34,7 +34,7 @@ void main() {
}); });
test("two row table has header row", () async { test("two row table has header row", () async {
final runnable = new TableRunnable(debugInfo); final runnable = TableRunnable(debugInfo);
runnable.addChild(TableRunnable(debugInfo) runnable.addChild(TableRunnable(debugInfo)
..rows.add("| header one | header two | header three |")); ..rows.add("| header one | header two | header three |"));
runnable.addChild( runnable.addChild(
@ -48,7 +48,7 @@ void main() {
}); });
test("three row table has header row and correct rows", () async { test("three row table has header row and correct rows", () async {
final runnable = new TableRunnable(debugInfo); final runnable = TableRunnable(debugInfo);
runnable.addChild(TableRunnable(debugInfo) runnable.addChild(TableRunnable(debugInfo)
..rows.add("| header one | header two | header three |")); ..rows.add("| header one | header two | header three |"));
runnable.addChild( runnable.addChild(
@ -65,7 +65,7 @@ void main() {
}); });
test("table removes columns leading and trailing spaces", () async { test("table removes columns leading and trailing spaces", () async {
final runnable = new TableRunnable(debugInfo); final runnable = TableRunnable(debugInfo);
runnable.addChild(TableRunnable(debugInfo) runnable.addChild(TableRunnable(debugInfo)
..rows.add("| header one | header two | header three |")); ..rows.add("| header one | header two | header three |"));
runnable.addChild(TableRunnable(debugInfo) runnable.addChild(TableRunnable(debugInfo)

View File

@ -34,12 +34,12 @@ void main() {
final step = StepDefinitionMock(StepDefinitionConfiguration(), 2); final step = StepDefinitionMock(StepDefinitionConfiguration(), 2);
expect( expect(
() async => await step.run( () async => await step.run(
null, null, Duration(seconds: 1), Iterable.empty()), null, null, Duration(seconds: 1), const Iterable.empty()),
throwsA((e) => throwsA((e) =>
e is GherkinStepParameterMismatchException && e is GherkinStepParameterMismatchException &&
e.message == e.message ==
"StepDefinitionMock parameter count mismatch. Expect 2 parameters but got 0. " + "StepDefinitionMock parameter count mismatch. Expect 2 parameters but got 0. "
"Ensure you are extending the correct step class which would be Given")); "Ensure you are extending the correct step class which would be Given"));
expect(step.invocationCount, 0); expect(step.invocationCount, 0);
}); });
@ -52,8 +52,8 @@ void main() {
throwsA((e) => throwsA((e) =>
e is GherkinStepParameterMismatchException && e is GherkinStepParameterMismatchException &&
e.message == e.message ==
"StepDefinitionMock parameter count mismatch. Expect 2 parameters but got 1. " + "StepDefinitionMock parameter count mismatch. Expect 2 parameters but got 1. "
"Ensure you are extending the correct step class which would be Given1<TInputType0>")); "Ensure you are extending the correct step class which would be Given1<TInputType0>"));
expect(step.invocationCount, 0); expect(step.invocationCount, 0);
}); });
@ -71,7 +71,8 @@ void main() {
StepDefinitionConfiguration(), 0, () async => throw Exception("1")); StepDefinitionConfiguration(), 0, () async => throw Exception("1"));
expect( expect(
await step.run( await step.run(
null, null, Duration(milliseconds: 1), Iterable.empty()), (r) { null, null, Duration(milliseconds: 1), const Iterable.empty()),
(r) {
return r is ErroredStepResult && return r is ErroredStepResult &&
r.result == StepExecutionResult.error && r.result == StepExecutionResult.error &&
r.exception is Exception && r.exception is Exception &&
@ -86,7 +87,8 @@ void main() {
() async => throw TestFailure("1")); () async => throw TestFailure("1"));
expect( expect(
await step.run( await step.run(
null, null, Duration(milliseconds: 1), Iterable.empty()), (r) { null, null, Duration(milliseconds: 1), const Iterable.empty()),
(r) {
return r is StepResult && return r is StepResult &&
r.result == StepExecutionResult.fail && r.result == StepExecutionResult.fail &&
r.resultReason == "1"; r.resultReason == "1";

View File

@ -7,13 +7,13 @@ import 'package:test/test.dart';
void main() { void main() {
group("isMatch", () { group("isMatch", () {
test('matches correctly', () { test('matches correctly', () {
final syntax = new BackgroundSyntax(); final syntax = BackgroundSyntax();
expect(syntax.isMatch("Background: something"), true); expect(syntax.isMatch("Background: something"), true);
expect(syntax.isMatch(" Background: something"), true); expect(syntax.isMatch(" Background: something"), true);
}); });
test('does not match', () { test('does not match', () {
final syntax = new BackgroundSyntax(); final syntax = BackgroundSyntax();
expect(syntax.isMatch("Background something"), false); expect(syntax.isMatch("Background something"), false);
expect(syntax.isMatch("#Background: something"), false); expect(syntax.isMatch("#Background: something"), false);
}); });
@ -21,8 +21,8 @@ void main() {
group("toRunnable", () { group("toRunnable", () {
test('creates BackgroundRunnable', () { test('creates BackgroundRunnable', () {
final syntax = new BackgroundSyntax(); final syntax = BackgroundSyntax();
Runnable runnable = syntax.toRunnable("Background: A backgroun 123", final Runnable runnable = syntax.toRunnable("Background: A backgroun 123",
RunnableDebugInformation(null, 0, null)); RunnableDebugInformation(null, 0, null));
expect(runnable, isNotNull); expect(runnable, isNotNull);
expect(runnable, predicate((x) => x is BackgroundRunnable)); expect(runnable, predicate((x) => x is BackgroundRunnable));

View File

@ -4,7 +4,7 @@ import 'package:test/test.dart';
void main() { void main() {
group("isMatch", () { group("isMatch", () {
test('matches correctly', () { test('matches correctly', () {
final keyword = new CommentSyntax(); final keyword = CommentSyntax();
expect(keyword.isMatch("# I am a comment"), true); 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);
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', () { test('does not match', () {
final keyword = new CommentSyntax(); final keyword = CommentSyntax();
// expect(keyword.isMatch("# language: en"), false); // expect(keyword.isMatch("# language: en"), false);
expect(keyword.isMatch("I am not a comment"), false); expect(keyword.isMatch("I am not a comment"), false);
}); });

View File

@ -4,7 +4,7 @@ import 'package:test/test.dart';
void main() { void main() {
group("isMatch", () { group("isMatch", () {
test('matches correctly', () { test('matches correctly', () {
final keyword = new EmptyLineSyntax(); final keyword = EmptyLineSyntax();
expect(keyword.isMatch(""), true); expect(keyword.isMatch(""), true);
expect(keyword.isMatch(" "), true); expect(keyword.isMatch(" "), true);
expect(keyword.isMatch(" "), true); expect(keyword.isMatch(" "), true);
@ -12,7 +12,7 @@ void main() {
}); });
test('does not match', () { test('does not match', () {
final keyword = new EmptyLineSyntax(); final keyword = EmptyLineSyntax();
expect(keyword.isMatch("a"), false); expect(keyword.isMatch("a"), false);
expect(keyword.isMatch(" b"), false); expect(keyword.isMatch(" b"), false);
expect(keyword.isMatch(" c"), false); expect(keyword.isMatch(" c"), false);

View File

@ -7,13 +7,13 @@ import 'package:test/test.dart';
void main() { void main() {
group("isMatch", () { group("isMatch", () {
test('matches correctly', () { test('matches correctly', () {
final keyword = new FeatureSyntax(); final keyword = FeatureSyntax();
expect(keyword.isMatch("Feature: one"), true); expect(keyword.isMatch("Feature: one"), true);
expect(keyword.isMatch("Feature:one"), true); expect(keyword.isMatch("Feature:one"), true);
}); });
test('does not match', () { test('does not match', () {
final keyword = new FeatureSyntax(); final keyword = FeatureSyntax();
expect(keyword.isMatch("#Feature: no"), false); expect(keyword.isMatch("#Feature: no"), false);
expect(keyword.isMatch("# Feature no"), false); expect(keyword.isMatch("# Feature no"), false);
}); });
@ -21,8 +21,8 @@ void main() {
group("toRunnable", () { group("toRunnable", () {
test('creates FeatureRunnable', () { test('creates FeatureRunnable', () {
final keyword = new FeatureSyntax(); final keyword = FeatureSyntax();
Runnable runnable = keyword.toRunnable( final Runnable runnable = keyword.toRunnable(
"Feature: A feature 123", RunnableDebugInformation(null, 0, null)); "Feature: A feature 123", RunnableDebugInformation(null, 0, null));
expect(runnable, isNotNull); expect(runnable, isNotNull);
expect(runnable, predicate((x) => x is FeatureRunnable)); expect(runnable, predicate((x) => x is FeatureRunnable));

View File

@ -6,14 +6,14 @@ import 'package:test/test.dart';
void main() { void main() {
group("isMatch", () { group("isMatch", () {
test('matches correctly', () { test('matches correctly', () {
final keyword = new LanguageSyntax(); final keyword = LanguageSyntax();
expect(keyword.isMatch("# language: en"), true); expect(keyword.isMatch("# language: en"), true);
expect(keyword.isMatch("#language: fr"), true); expect(keyword.isMatch("#language: fr"), true);
expect(keyword.isMatch("#language:de"), true); expect(keyword.isMatch("#language:de"), true);
}); });
test('does not match', () { test('does not match', () {
final keyword = new LanguageSyntax(); final keyword = LanguageSyntax();
expect(keyword.isMatch("#language no"), false); expect(keyword.isMatch("#language no"), false);
expect(keyword.isMatch("# language comment"), false); expect(keyword.isMatch("# language comment"), false);
}); });
@ -21,8 +21,8 @@ void main() {
group("toRunnable", () { group("toRunnable", () {
test('creates LanguageRunnable', () { test('creates LanguageRunnable', () {
final keyword = new LanguageSyntax(); final keyword = LanguageSyntax();
LanguageRunnable runnable = keyword.toRunnable( final LanguageRunnable runnable = keyword.toRunnable(
"# language: de", RunnableDebugInformation(null, 0, null)); "# language: de", RunnableDebugInformation(null, 0, null));
expect(runnable, isNotNull); expect(runnable, isNotNull);
expect(runnable, predicate((x) => x is LanguageRunnable)); expect(runnable, predicate((x) => x is LanguageRunnable));

View File

@ -8,14 +8,14 @@ import 'package:test/test.dart';
void main() { void main() {
group("isMatch", () { group("isMatch", () {
test('matches correctly', () { test('matches correctly', () {
final syntax = new MultilineStringSyntax(); final syntax = MultilineStringSyntax();
expect(syntax.isMatch('"""'), true); expect(syntax.isMatch('"""'), true);
expect(syntax.isMatch('```'), true); expect(syntax.isMatch('```'), true);
expect(syntax.isMatch("'''"), true); expect(syntax.isMatch("'''"), true);
}); });
test('does not match', () { test('does not match', () {
final syntax = new MultilineStringSyntax(); final syntax = MultilineStringSyntax();
expect(syntax.isMatch('#"""'), false); expect(syntax.isMatch('#"""'), false);
expect(syntax.isMatch('#```'), false); expect(syntax.isMatch('#```'), false);
expect(syntax.isMatch("#'''"), false); expect(syntax.isMatch("#'''"), false);
@ -26,30 +26,30 @@ void main() {
}); });
group("block", () { group("block", () {
test("is block", () { test("is block", () {
final syntax = new MultilineStringSyntax(); final syntax = MultilineStringSyntax();
expect(syntax.isBlockSyntax, true); expect(syntax.isBlockSyntax, true);
}); });
test("continue block if text line string", () { test("continue block if text line string", () {
final syntax = new MultilineStringSyntax(); final syntax = MultilineStringSyntax();
expect(syntax.hasBlockEnded(new TextLineSyntax()), false); expect(syntax.hasBlockEnded(TextLineSyntax()), false);
}); });
test("continue block if comment string", () { test("continue block if comment string", () {
final syntax = new MultilineStringSyntax(); final syntax = MultilineStringSyntax();
expect(syntax.hasBlockEnded(new CommentSyntax()), false); expect(syntax.hasBlockEnded(CommentSyntax()), false);
}); });
test("end block if multiline string", () { test("end block if multiline string", () {
final syntax = new MultilineStringSyntax(); final syntax = MultilineStringSyntax();
expect(syntax.hasBlockEnded(new MultilineStringSyntax()), true); expect(syntax.hasBlockEnded(MultilineStringSyntax()), true);
}); });
}); });
group("toRunnable", () { group("toRunnable", () {
test('creates TextLineRunnable', () { test('creates TextLineRunnable', () {
final syntax = new MultilineStringSyntax(); final syntax = MultilineStringSyntax();
MultilineStringRunnable runnable = final MultilineStringRunnable runnable =
syntax.toRunnable("'''", RunnableDebugInformation(null, 0, null)); syntax.toRunnable("'''", RunnableDebugInformation(null, 0, null));
expect(runnable, isNotNull); expect(runnable, isNotNull);
expect(runnable, predicate((x) => x is MultilineStringRunnable)); expect(runnable, predicate((x) => x is MultilineStringRunnable));

View File

@ -7,13 +7,13 @@ import 'package:test/test.dart';
void main() { void main() {
group("isMatch", () { group("isMatch", () {
test('matches correctly', () { test('matches correctly', () {
final syntax = new ScenarioSyntax(); final syntax = ScenarioSyntax();
expect(syntax.isMatch("Scenario: something"), true); expect(syntax.isMatch("Scenario: something"), true);
expect(syntax.isMatch(" Scenario: something"), true); expect(syntax.isMatch(" Scenario: something"), true);
}); });
test('does not match', () { test('does not match', () {
final syntax = new ScenarioSyntax(); final syntax = ScenarioSyntax();
expect(syntax.isMatch("Scenario something"), false); expect(syntax.isMatch("Scenario something"), false);
expect(syntax.isMatch("#Scenario: something"), false); expect(syntax.isMatch("#Scenario: something"), false);
}); });
@ -21,8 +21,8 @@ void main() {
group("toRunnable", () { group("toRunnable", () {
test('creates FeatureRunnable', () { test('creates FeatureRunnable', () {
final keyword = new ScenarioSyntax(); final keyword = ScenarioSyntax();
Runnable runnable = keyword.toRunnable( final Runnable runnable = keyword.toRunnable(
"Scenario: A scenario 123", RunnableDebugInformation(null, 0, null)); "Scenario: A scenario 123", RunnableDebugInformation(null, 0, null));
expect(runnable, isNotNull); expect(runnable, isNotNull);
expect(runnable, predicate((x) => x is ScenarioRunnable)); expect(runnable, predicate((x) => x is ScenarioRunnable));

View File

@ -8,67 +8,67 @@ import 'package:test/test.dart';
void main() { void main() {
group("isMatch", () { group("isMatch", () {
test('matches given correctly', () { 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);
expect(syntax.isMatch("given a step"), true); expect(syntax.isMatch("given a step"), true);
}); });
test('matches then correctly', () { 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);
expect(syntax.isMatch("then a step"), true); expect(syntax.isMatch("then a step"), true);
}); });
test('matches when correctly', () { 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);
expect(syntax.isMatch("when I do something"), true); expect(syntax.isMatch("when I do something"), true);
}); });
test('matches and correctly', () { test('matches and correctly', () {
final syntax = new StepSyntax(); final syntax = StepSyntax();
expect(syntax.isMatch("And something"), true); expect(syntax.isMatch("And something"), true);
expect(syntax.isMatch("and something"), true); expect(syntax.isMatch("and something"), true);
}); });
test('matches but correctly', () { test('matches but correctly', () {
final syntax = new StepSyntax(); final syntax = StepSyntax();
expect(syntax.isMatch("but something"), true); expect(syntax.isMatch("but something"), true);
expect(syntax.isMatch("but something"), true); expect(syntax.isMatch("but something"), true);
}); });
test('does not match', () { test('does not match', () {
final syntax = new StepSyntax(); final syntax = StepSyntax();
expect(syntax.isMatch("#given something"), false); expect(syntax.isMatch("#given something"), false);
}); });
}); });
group("block", () { group("block", () {
test("is block", () { test("is block", () {
final syntax = new StepSyntax(); final syntax = StepSyntax();
expect(syntax.isBlockSyntax, true); expect(syntax.isBlockSyntax, true);
}); });
test("continue block if multiline string", () { test("continue block if multiline string", () {
final syntax = new StepSyntax(); final syntax = StepSyntax();
expect(syntax.hasBlockEnded(new MultilineStringSyntax()), false); expect(syntax.hasBlockEnded(MultilineStringSyntax()), false);
}); });
test("continue block if table", () { test("continue block if table", () {
final syntax = new StepSyntax(); final syntax = StepSyntax();
expect(syntax.hasBlockEnded(new TableLineSyntax()), false); expect(syntax.hasBlockEnded(TableLineSyntax()), false);
}); });
test("end block if not multiline string or table", () { test("end block if not multiline string or table", () {
final syntax = new StepSyntax(); final syntax = StepSyntax();
expect(syntax.hasBlockEnded(new StepSyntax()), true); expect(syntax.hasBlockEnded(StepSyntax()), true);
}); });
}); });
group("toRunnable", () { group("toRunnable", () {
test('creates StepRunnable', () { test('creates StepRunnable', () {
final syntax = new StepSyntax(); final syntax = StepSyntax();
StepRunnable runnable = syntax.toRunnable( final StepRunnable runnable = syntax.toRunnable(
"Given I do something", RunnableDebugInformation(null, 0, null)); "Given I do something", RunnableDebugInformation(null, 0, null));
expect(runnable, isNotNull); expect(runnable, isNotNull);
expect(runnable, predicate((x) => x is StepRunnable)); expect(runnable, predicate((x) => x is StepRunnable));

View File

@ -9,14 +9,14 @@ import 'package:test/test.dart';
void main() { void main() {
group("isMatch", () { group("isMatch", () {
test('matches correctly', () { test('matches correctly', () {
final syntax = new TableLineSyntax(); final syntax = TableLineSyntax();
expect(syntax.isMatch('||'), true); expect(syntax.isMatch('||'), true);
expect(syntax.isMatch(' | | '), true); expect(syntax.isMatch(' | | '), true);
expect(syntax.isMatch(" |a|b|c| "), true); expect(syntax.isMatch(" |a|b|c| "), true);
}); });
test('does not match', () { test('does not match', () {
final syntax = new TableLineSyntax(); final syntax = TableLineSyntax();
expect(syntax.isMatch('#||'), false); expect(syntax.isMatch('#||'), false);
expect(syntax.isMatch(' | '), false); expect(syntax.isMatch(' | '), false);
expect(syntax.isMatch(" |a|b|c "), false); expect(syntax.isMatch(" |a|b|c "), false);
@ -25,57 +25,57 @@ void main() {
group("block", () { group("block", () {
test("is block", () { test("is block", () {
final syntax = new TableLineSyntax(); final syntax = TableLineSyntax();
expect(syntax.isBlockSyntax, true); expect(syntax.isBlockSyntax, true);
}); });
test("continue block if table line string", () { test("continue block if table line string", () {
final syntax = new TableLineSyntax(); final syntax = TableLineSyntax();
expect(syntax.hasBlockEnded(new TableLineSyntax()), false); expect(syntax.hasBlockEnded(TableLineSyntax()), false);
}); });
test("continue block if comment string", () { test("continue block if comment string", () {
final syntax = new TableLineSyntax(); final syntax = TableLineSyntax();
expect(syntax.hasBlockEnded(new CommentSyntax()), false); expect(syntax.hasBlockEnded(CommentSyntax()), false);
}); });
test("end block if not table line string", () { test("end block if not table line string", () {
final syntax = new TableLineSyntax(); final syntax = TableLineSyntax();
expect(syntax.hasBlockEnded(new MultilineStringSyntax()), true); expect(syntax.hasBlockEnded(MultilineStringSyntax()), true);
}); });
}); });
group("block", () { group("block", () {
test("is block", () { test("is block", () {
final syntax = new TableLineSyntax(); final syntax = TableLineSyntax();
expect(syntax.isBlockSyntax, true); expect(syntax.isBlockSyntax, true);
}); });
test("continue block if table line", () { test("continue block if table line", () {
final syntax = new TableLineSyntax(); final syntax = TableLineSyntax();
expect(syntax.hasBlockEnded(new TableLineSyntax()), false); expect(syntax.hasBlockEnded(TableLineSyntax()), false);
}); });
test("continue block if comment string", () { test("continue block if comment string", () {
final syntax = new TableLineSyntax(); final syntax = TableLineSyntax();
expect(syntax.hasBlockEnded(new CommentSyntax()), false); expect(syntax.hasBlockEnded(CommentSyntax()), false);
}); });
test("end block if step", () { test("end block if step", () {
final syntax = new TableLineSyntax(); final syntax = TableLineSyntax();
expect(syntax.hasBlockEnded(new StepSyntax()), true); expect(syntax.hasBlockEnded(StepSyntax()), true);
}); });
test("end block if multiline string", () { test("end block if multiline string", () {
final syntax = new TableLineSyntax(); final syntax = TableLineSyntax();
expect(syntax.hasBlockEnded(new MultilineStringSyntax()), true); expect(syntax.hasBlockEnded(MultilineStringSyntax()), true);
}); });
}); });
group("toRunnable", () { group("toRunnable", () {
test('creates TableRunnable', () { test('creates TableRunnable', () {
final syntax = new TableLineSyntax(); final syntax = TableLineSyntax();
TableRunnable runnable = syntax.toRunnable( final TableRunnable runnable = syntax.toRunnable(
" | Row One | Row Two | ", RunnableDebugInformation(null, 0, null)); " | Row One | Row Two | ", RunnableDebugInformation(null, 0, null));
expect(runnable, isNotNull); expect(runnable, isNotNull);
expect(runnable, predicate((x) => x is TableRunnable)); expect(runnable, predicate((x) => x is TableRunnable));

View File

@ -6,13 +6,13 @@ import 'package:test/test.dart';
void main() { void main() {
group("isMatch", () { group("isMatch", () {
test('matches correctly', () { test('matches correctly', () {
final syntax = new TagSyntax(); final syntax = TagSyntax();
expect(syntax.isMatch("@tagone @tagtow @tag_three"), true); expect(syntax.isMatch("@tagone @tagtow @tag_three"), true);
expect(syntax.isMatch("@tag"), true); expect(syntax.isMatch("@tag"), true);
}); });
test('does not match', () { test('does not match', () {
final syntax = new TagSyntax(); final syntax = TagSyntax();
expect(syntax.isMatch("not a tag"), false); expect(syntax.isMatch("not a tag"), false);
expect(syntax.isMatch("#@tag @tag2"), false); expect(syntax.isMatch("#@tag @tag2"), false);
}); });
@ -20,8 +20,8 @@ void main() {
group("toRunnable", () { group("toRunnable", () {
test('creates TextLineRunnable', () { test('creates TextLineRunnable', () {
final syntax = new TagSyntax(); final syntax = TagSyntax();
TagsRunnable runnable = syntax.toRunnable( final TagsRunnable runnable = syntax.toRunnable(
"@tag1 @tag2 @tag3@tag_4", RunnableDebugInformation(null, 0, null)); "@tag1 @tag2 @tag3@tag_4", RunnableDebugInformation(null, 0, null));
expect(runnable, isNotNull); expect(runnable, isNotNull);
expect(runnable, predicate((x) => x is TagsRunnable)); expect(runnable, predicate((x) => x is TagsRunnable));

View File

@ -6,7 +6,7 @@ import 'package:test/test.dart';
void main() { void main() {
group("isMatch", () { group("isMatch", () {
test('matches correctly', () { 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); 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', () { 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); 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", () { group("toRunnable", () {
test('creates TextLineRunnable', () { test('creates TextLineRunnable', () {
final syntax = new TextLineSyntax(); final syntax = TextLineSyntax();
TextLineRunnable runnable = syntax.toRunnable( final TextLineRunnable runnable = syntax.toRunnable(
" Some text ", RunnableDebugInformation(null, 0, null)); " Some text ", RunnableDebugInformation(null, 0, null));
expect(runnable, isNotNull); expect(runnable, isNotNull);
expect(runnable, predicate((x) => x is TextLineRunnable)); expect(runnable, predicate((x) => x is TextLineRunnable));

View File

@ -5,7 +5,7 @@ import '../mocks/hook_mock.dart';
void main() { void main() {
group("orders hooks", () { group("orders hooks", () {
test("executes hooks in correct order", () async { test("executes hooks in correct order", () async {
final executionOrder = List<int>(); final executionOrder = <int>[];
final hookOne = HookMock( final hookOne = HookMock(
providedPriority: 0, onBeforeRunCode: () => executionOrder.add(3)); providedPriority: 0, onBeforeRunCode: () => executionOrder.add(3));
final hookTwo = HookMock( final hookTwo = HookMock(

View File

@ -8,7 +8,7 @@ class MockGherkinExpression implements GherkinExpression {
MockGherkinExpression(this.isMatchFn); MockGherkinExpression(this.isMatchFn);
@override @override
Iterable getParameters(String input) => Iterable.empty(); Iterable getParameters(String input) => const Iterable.empty();
@override @override
bool isMatch(String input) => isMatchFn(input); bool isMatch(String input) => isMatchFn(input);

View File

@ -17,6 +17,7 @@ class HookMock extends Hook {
HookMock({this.onBeforeRunCode, this.providedPriority = 0}); HookMock({this.onBeforeRunCode, this.providedPriority = 0});
@override
Future<void> onBeforeRun(TestConfiguration config) async { Future<void> onBeforeRun(TestConfiguration config) async {
onBeforeRunInvocationCount += 1; onBeforeRunInvocationCount += 1;
if (onBeforeRunCode != null) { if (onBeforeRunCode != null) {
@ -24,17 +25,21 @@ class HookMock extends Hook {
} }
} }
@override
Future<void> onAfterRun(TestConfiguration config) async => Future<void> onAfterRun(TestConfiguration config) async =>
onAfterRunInvocationCount += 1; onAfterRunInvocationCount += 1;
@override
Future<void> onBeforeScenario( Future<void> onBeforeScenario(
TestConfiguration config, String scenario) async => TestConfiguration config, String scenario) async =>
onBeforeScenarioInvocationCount += 1; onBeforeScenarioInvocationCount += 1;
@override
Future<void> onAfterScenario( Future<void> onAfterScenario(
TestConfiguration config, String scenario) async => TestConfiguration config, String scenario) async =>
onAfterScenarioInvocationCount += 1; onAfterScenarioInvocationCount += 1;
@override
Future<void> onAfterScenarioWorldCreated( Future<void> onAfterScenarioWorldCreated(
World world, String scenario) async => World world, String scenario) async =>
onAfterScenarioWorldCreatedInvocationCount += 1; onAfterScenarioWorldCreatedInvocationCount += 1;

View File

@ -17,27 +17,38 @@ class ReporterMock extends Reporter {
OnStepFinished onStepFinishedFn; OnStepFinished onStepFinishedFn;
@override
Future<void> onTestRunStarted() async => onTestRunStartedInvocationCount += 1; Future<void> onTestRunStarted() async => onTestRunStartedInvocationCount += 1;
@override
Future<void> onTestRunFinished() async => Future<void> onTestRunFinished() async =>
onTestRunfinishedInvocationCount += 1; onTestRunfinishedInvocationCount += 1;
@override
Future<void> onFeatureStarted(StartedMessage message) async => Future<void> onFeatureStarted(StartedMessage message) async =>
onFeatureStartedInvocationCount += 1; onFeatureStartedInvocationCount += 1;
@override
Future<void> onFeatureFinished(FinishedMessage message) async => Future<void> onFeatureFinished(FinishedMessage message) async =>
onFeatureFinishedInvocationCount += 1; onFeatureFinishedInvocationCount += 1;
@override
Future<void> onScenarioStarted(StartedMessage message) async => Future<void> onScenarioStarted(StartedMessage message) async =>
onScenarioStartedInvocationCount += 1; onScenarioStartedInvocationCount += 1;
@override
Future<void> onScenarioFinished(FinishedMessage message) async => Future<void> onScenarioFinished(FinishedMessage message) async =>
onScenarioFinishedInvocationCount += 1; onScenarioFinishedInvocationCount += 1;
@override
Future<void> onStepStarted(StartedMessage message) async => Future<void> onStepStarted(StartedMessage message) async =>
onStepStartedInvocationCount += 1; onStepStartedInvocationCount += 1;
@override
Future<void> onStepFinished(StepFinishedMessage message) async { Future<void> onStepFinished(StepFinishedMessage message) async {
if (onStepFinishedFn != null) onStepFinishedFn(message); if (onStepFinishedFn != null) onStepFinishedFn(message);
onStepFinishedInvocationCount += 1; onStepFinishedInvocationCount += 1;
} }
@override
Future<void> onException(Exception exception, StackTrace stackTrace) async => Future<void> onException(Exception exception, StackTrace stackTrace) async =>
onExceptionInvocationCount += 1; onExceptionInvocationCount += 1;
@override
Future<void> message(String message, MessageLevel level) async => Future<void> message(String message, MessageLevel level) async =>
messageInvocationCount += 1; messageInvocationCount += 1;
@override
Future<void> dispose() async => disposeInvocationCount += 1; Future<void> dispose() async => disposeInvocationCount += 1;
} }

View File

@ -6,6 +6,7 @@ typedef Future<void> OnRunCode(Iterable parameters);
class MockStepDefinition extends StepDefinitionBase<World, Function> { class MockStepDefinition extends StepDefinitionBase<World, Function> {
bool hasRun = false; bool hasRun = false;
int runCount = 0; int runCount = 0;
@override
final OnRunCode code; final OnRunCode code;
MockStepDefinition([this.code, int expectedParameterCount = 0]) MockStepDefinition([this.code, int expectedParameterCount = 0])

View File

@ -4,7 +4,7 @@ import "package:flutter_gherkin/src/gherkin/steps/step_run_result.dart";
import "package:test/test.dart"; import "package:test/test.dart";
class TestableProgressReporter extends ProgressReporter { class TestableProgressReporter extends ProgressReporter {
final output = List<String>(); final output = <String>[];
@override @override
void printMessageLine(String message, [String colour]) { void printMessageLine(String message, [String colour]) {
output.add(message); output.add(message);
@ -39,8 +39,7 @@ void main() {
expect(reporter.output, [ expect(reporter.output, [
" √ Step 1 # filePath:1 took 0ms", " √ Step 1 # filePath:1 took 0ms",
" × Step 2 # filePath:2 took 0ms \n" " × Step 2 # filePath:2 took 0ms \n Failed Reason",
" Failed Reason",
" - Step 3 # filePath:3 took 0ms", " - Step 3 # filePath:3 took 0ms",
" × Step 4 # filePath:4 took 0ms", " × Step 4 # filePath:4 took 0ms",
" × Step 5 # filePath:5 took 1ms" " × Step 5 # filePath:5 took 1ms"

View File

@ -3,7 +3,7 @@ import 'package:flutter_gherkin/src/gherkin/steps/step_run_result.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
class TestableTestRunSummaryReporter extends TestRunSummaryReporter { class TestableTestRunSummaryReporter extends TestRunSummaryReporter {
final output = List<String>(); final output = <String>[];
@override @override
void printMessageLine(String message, [String colour]) { void printMessageLine(String message, [String colour]) {
output.add(message); output.add(message);