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

View File

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

View File

@ -3,33 +3,30 @@ import 'package:flutter_gherkin/flutter_gherkin.dart';
class HookExample extends Hook {
/// The priority to assign to this hook.
/// Higher priority gets run first so a priority of 10 is run before a priority of 2
@override
int get priority => 1;
@override
/// Run before any scenario in a test run have executed
@override
Future<void> onBeforeRun(TestConfiguration config) async {
print("before run hook");
}
@override
/// Run after all scenarios in a test run have completed
@override
Future<void> onAfterRun(TestConfiguration config) async {
print("after run hook");
}
@override
/// Run before a scenario and it steps are executed
@override
Future<void> onBeforeScenario(
TestConfiguration config, String scenario) async {
print("running hook before scenario '$scenario'");
}
@override
/// Run after a scenario has executed
@override
Future<void> onAfterScenario(
TestConfiguration config, String scenario) async {
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
/// can call [expectLater] instead and `await` the result.
void expect(actualValue, matcher, {String reason}) {
var matchState = {};
final matchState = {};
matcher = wrapMatcher(matcher);
final result = matcher.matches(actualValue, matchState);
final formatter = (actual, matcher, reason, matchState, verbose) {
var mismatchDescription = new StringDescription();
final mismatchDescription = StringDescription();
matcher.describeMismatch(
actual, mismatchDescription, matchState, verbose);

View File

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

View File

@ -85,7 +85,7 @@ class FeatureFileRunner {
await _hook.onAfterScenarioWorldCreated(world, scenario.name);
}
_reporter.onScenarioStarted(
await _reporter.onScenarioStarted(
StartedMessage(Target.scenario, scenario.name, scenario.debug));
if (background != null) {
await _log("Running background steps for scenerio '${scenario.name}'",
@ -95,7 +95,7 @@ class FeatureFileRunner {
scenarioPassed = result.result == StepExecutionResult.pass;
if (!_canContinueScenario(result)) {
scenarioPassed = false;
_log(
await _log(
"Background step '${step.name}' did not pass, all remaining steps will be skiped",
step.debug,
MessageLevel.warning);
@ -108,7 +108,7 @@ class FeatureFileRunner {
scenarioPassed = result.result == StepExecutionResult.pass;
if (!_canContinueScenario(result)) {
scenarioPassed = false;
_log(
await _log(
"Step '${step.name}' did not pass, all remaining steps will be skiped",
step.debug,
MessageLevel.warning);
@ -130,8 +130,8 @@ class FeatureFileRunner {
Future<StepResult> _runStep(
StepRunnable step, World world, bool skipExecution) async {
StepResult result;
ExectuableStep code = _matchStepToExectuableStep(step);
Iterable<dynamic> parameters = _getStepParameters(step, code);
final ExectuableStep code = _matchStepToExectuableStep(step);
final Iterable<dynamic> parameters = _getStepParameters(step, code);
await _log(
"Attempting to run step '${step.name}'", step.debug, MessageLevel.info);
@ -206,7 +206,7 @@ class FeatureFileRunner {
}
""";
_reporter.message(message, MessageLevel.error);
throw new GherkinStepNotDefinedException(message);
throw GherkinStepNotDefinedException(message);
}
return executable;
@ -215,7 +215,7 @@ class FeatureFileRunner {
Iterable<dynamic> _getStepParameters(StepRunnable step, ExectuableStep code) {
Iterable<dynamic> parameters =
code.expression.getParameters(step.debug.lineText);
if (step.multilineStrings.length > 0) {
if (step.multilineStrings.isNotEmpty) {
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);
Process _runningProcess;
Stream<String> _processStdoutStream;
List<StreamSubscription> _openSubscriptions = List<StreamSubscription>();
List<StreamSubscription> _openSubscriptions = <StreamSubscription>[];
String _appTarget;
String _workingDirectory;
@ -86,7 +86,7 @@ class FlutterRunProcessHandler extends ProcessHandler {
void _ensureRunningProcess() {
if (_runningProcess == null) {
throw new Exception(
throw Exception(
"FlutterRunProcessHandler: flutter run process is not active");
}
}

View File

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

View File

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

View File

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

View File

@ -21,7 +21,7 @@ class GivenOpenDrawer extends Given1WithWorld<String, FlutterWorld> {
if (isOpen && action == "close") {
// Swipe to the left across the whole app to close the drawer
await world.driver
.scroll(drawerFinder, -300.0, 0.0, Duration(milliseconds: 300));
.scroll(drawerFinder, -300.0, 0.0, const Duration(milliseconds: 300));
} else if (!isOpen && action == "open") {
await FlutterDriverUtils.tap(
world.driver, find.byTooltip("Open navigation menu"),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

View File

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

View File

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

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

View File

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

View File

@ -28,6 +28,7 @@ abstract class StepDefinition<TWorld extends World>
StepDefinition([StepDefinitionConfiguration configuration])
: super(configuration, 0);
@override
Future<void> onRun(Iterable<dynamic> parameters) async => await code();
}
@ -36,6 +37,7 @@ abstract class StepDefinition1<TWorld extends World, TInput1>
StepDefinition1([StepDefinitionConfiguration configuration])
: super(configuration, 1);
@override
Future<void> onRun(Iterable<dynamic> parameters) async =>
await code(parameters.elementAt(0));
}
@ -45,6 +47,7 @@ abstract class StepDefinition2<TWorld extends World, TInput1, TInput2>
StepDefinition2([StepDefinitionConfiguration configuration])
: super(configuration, 2);
@override
Future<void> onRun(Iterable<dynamic> parameters) async =>
await code(parameters.elementAt(0), parameters.elementAt(1));
}
@ -55,6 +58,7 @@ abstract class StepDefinition3<TWorld extends World, TInput1, TInput2, TInput3>
StepDefinition3([StepDefinitionConfiguration configuration])
: super(configuration, 3);
@override
Future<void> onRun(Iterable<dynamic> parameters) async => await code(
parameters.elementAt(0),
parameters.elementAt(1),
@ -68,6 +72,7 @@ abstract class StepDefinition4<TWorld extends World, TInput1, TInput2, TInput3,
StepDefinition4([StepDefinitionConfiguration configuration])
: super(configuration, 4);
@override
Future<void> onRun(Iterable<dynamic> parameters) async => await code(
parameters.elementAt(0),
parameters.elementAt(1),
@ -82,6 +87,7 @@ abstract class StepDefinition5<TWorld extends World, TInput1, TInput2, TInput3,
StepDefinition5([StepDefinitionConfiguration configuration])
: super(configuration, 5);
@override
Future<void> onRun(Iterable<dynamic> parameters) async => await code(
parameters.elementAt(0),
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';
class BackgroundSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = RegExp(r"^\s*Background:\s*(.+)\s*$",
multiLine: false, caseSensitive: false);
@ -23,7 +24,7 @@ class BackgroundSyntax extends RegExMatchedGherkinSyntax {
@override
Runnable toRunnable(String line, RunnableDebugInformation debug) {
final name = pattern.firstMatch(line).group(1);
final runnable = new BackgroundRunnable(name, debug);
final runnable = BackgroundRunnable(name, debug);
return runnable;
}
}

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';
class CommentSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = RegExp("^#", multiLine: false, caseSensitive: false);
@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';
class EmptyLineSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern =
RegExp(r"^\s*$", multiLine: false, caseSensitive: false);

View File

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

View File

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

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

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';
class ScenarioSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = RegExp(r"^\s*Scenario:\s*(.+)\s*$",
multiLine: false, caseSensitive: false);
@ -19,7 +20,7 @@ class ScenarioSyntax extends RegExMatchedGherkinSyntax {
@override
Runnable toRunnable(String line, RunnableDebugInformation debug) {
final name = pattern.firstMatch(line).group(1);
final runnable = new ScenarioRunnable(name, debug);
final runnable = ScenarioRunnable(name, debug);
return runnable;
}
}

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

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

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';
class TagSyntax extends RegExMatchedGherkinSyntax {
@override
final RegExp pattern = RegExp("^@", multiLine: false, caseSensitive: false);
@override
Runnable toRunnable(String line, RunnableDebugInformation debug) {
final runnable = new TagsRunnable(debug);
final runnable = TagsRunnable(debug);
runnable.tags = line
.trim()
.split(RegExp("@"))

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

View File

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

View File

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

View File

@ -13,6 +13,7 @@ class StdoutReporter extends Reporter {
StdoutReporter([this._logLevel = MessageLevel.verbose]);
@override
Future<void> message(String message, MessageLevel level) async {
if (level.index >= _logLevel.index) {
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';
class TestRunSummaryReporter extends StdoutReporter {
final _timer = new Stopwatch();
final List<StepFinishedMessage> _ranSteps = List<StepFinishedMessage>();
final _timer = Stopwatch();
final List<StepFinishedMessage> _ranSteps = <StepFinishedMessage>[];
final List<ScenarioFinishedMessage> _ranScenarios =
List<ScenarioFinishedMessage>();
<ScenarioFinishedMessage>[];
@override
Future<void> onScenarioFinished(ScenarioFinishedMessage message) async {
@ -47,7 +47,7 @@ class TestRunSummaryReporter extends StdoutReporter {
}
String _collectScenarioSummary(Iterable<ScenarioFinishedMessage> scenarios) {
List<String> summaries = List<String>();
final List<String> summaries = <String>[];
if (scenarios.any((s) => s.passed)) {
summaries.add(
"${StdoutReporter.PASS_COLOR}${scenarios.where((s) => s.passed).length} passed${StdoutReporter.RESET_COLOR}");
@ -62,7 +62,7 @@ class TestRunSummaryReporter extends StdoutReporter {
}
String _collectStepSummary(Iterable<StepFinishedMessage> steps) {
List<String> summaries = List<String>();
final List<String> summaries = <String>[];
final passed =
steps.where((s) => s.result.result == StepExecutionResult.pass);
final skipped =
@ -71,17 +71,17 @@ class TestRunSummaryReporter extends StdoutReporter {
s.result.result == StepExecutionResult.error ||
s.result.result == StepExecutionResult.fail ||
s.result.result == StepExecutionResult.timeout);
if (passed.length > 0) {
if (passed.isNotEmpty) {
summaries.add(
"${StdoutReporter.PASS_COLOR}${passed.length} passed${StdoutReporter.RESET_COLOR}");
}
if (skipped.length > 0) {
if (skipped.isNotEmpty) {
summaries.add(
"${StdoutReporter.WARN_COLOR}${skipped.length} skipped${StdoutReporter.RESET_COLOR}");
}
if (failed.length > 0) {
if (failed.isNotEmpty) {
summaries.add(
"${StdoutReporter.FAIL_COLOR}${failed.length} failed${StdoutReporter.RESET_COLOR}");
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ import 'package:test/test.dart';
void main() {
group("isMatch", () {
test('matches correctly', () {
final syntax = new TextLineSyntax();
final syntax = TextLineSyntax();
expect(syntax.isMatch("Hello Jon"), true);
expect(syntax.isMatch("Hello 'Jon'!"), true);
expect(syntax.isMatch(" Hello Jon"), true);
@ -15,7 +15,7 @@ void main() {
});
test('does not match', () {
final syntax = new TextLineSyntax();
final syntax = TextLineSyntax();
expect(syntax.isMatch("#Hello Jon"), false);
expect(syntax.isMatch("# Hello Jon"), false);
expect(syntax.isMatch("# Hello Jon"), false);
@ -26,8 +26,8 @@ void main() {
group("toRunnable", () {
test('creates TextLineRunnable', () {
final syntax = new TextLineSyntax();
TextLineRunnable runnable = syntax.toRunnable(
final syntax = TextLineSyntax();
final TextLineRunnable runnable = syntax.toRunnable(
" Some text ", RunnableDebugInformation(null, 0, null));
expect(runnable, isNotNull);
expect(runnable, predicate((x) => x is TextLineRunnable));

View File

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

View File

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

View File

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

View File

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

View File

@ -6,6 +6,7 @@ typedef Future<void> OnRunCode(Iterable parameters);
class MockStepDefinition extends StepDefinitionBase<World, Function> {
bool hasRun = false;
int runCount = 0;
@override
final OnRunCode code;
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";
class TestableProgressReporter extends ProgressReporter {
final output = List<String>();
final output = <String>[];
@override
void printMessageLine(String message, [String colour]) {
output.add(message);
@ -39,8 +39,7 @@ void main() {
expect(reporter.output, [
" √ Step 1 # filePath:1 took 0ms",
" × Step 2 # filePath:2 took 0ms \n"
" Failed Reason",
" × Step 2 # filePath:2 took 0ms \n Failed Reason",
" - Step 3 # filePath:3 took 0ms",
" × Step 4 # filePath:4 took 0ms",
" × Step 5 # filePath:5 took 1ms"

View File

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