diff --git a/bin/run-behat-tests b/bin/run-behat-tests index c9198b712..cd2ba2095 100755 --- a/bin/run-behat-tests +++ b/bin/run-behat-tests @@ -1,5 +1,13 @@ #!/bin/bash +# AI coding agents pay for every byte of a report they read back, so they get +# the compact, uncolored one by default. Setting NO_COLOR or WP_CLI_TEST_QUIET +# to an empty string keeps the full report. +if [ -n "${AI_AGENT}${CLAUDECODE}${CODEX_SANDBOX}${CURSOR_AGENT}${GEMINI_CLI}${ANTIGRAVITY_AGENT}" ]; then + [ -n "${NO_COLOR+set}" ] || export NO_COLOR=1 + [ -n "${WP_CLI_TEST_QUIET+set}" ] || export WP_CLI_TEST_QUIET=1 +fi + # Run the Behat tests only if a Behat config file is found. if [ ! -f "behat.yml" ] && [ ! -f "behat.php" ] && [ ! -f "behat.dist.php" ]; then echo 'Did not detect "behat.yml" file, skipping Behat tests.' @@ -317,6 +325,27 @@ fi # Generate the tags to apply environment-specific filters. BEHAT_TAGS=$(php "$WP_CLI_TESTS_ROOT"/utils/behat-tags.php) +# Report steps that no definition matches before any scenario is set up, each +# with the closest existing steps. Behat would only report them once a scenario +# reached them, and suggest snippets for new step definitions instead. +CHECK_STEPS=1 +for arg in "$@"; do + case "$arg" in + -d*|--definitions|--definitions=*|--rerun|--rerun-only|--init|-h|--help|--story-syntax) CHECK_STEPS="";; + esac +done +# Only a finding stops the run: if the check itself fails, for example because the PHP on the host +# cannot load the project's dependencies, Behat runs as it would without it. +if [ -n "${CHECK_STEPS}" ]; then + CHECK_STEPS_STATUS=0 + php "$WP_CLI_TESTS_ROOT"/utils/check-feature-steps.php "$BEHAT_TAGS" "$@" || CHECK_STEPS_STATUS=$? + if [ "${CHECK_STEPS_STATUS}" -eq 1 ]; then + exit 1 + elif [ "${CHECK_STEPS_STATUS}" -ne 0 ]; then + echo "Warning: could not check the feature files for undefined steps (exit status ${CHECK_STEPS_STATUS}), running Behat without the check." >&2 + fi +fi + BEHAT_EXTRA_ARGS=() if [[ "${WP_CLI_TEST_COVERAGE}" == "true" ]] && vendor/bin/behat --help 2>/dev/null | grep -q 'xdebug'; then BEHAT_EXTRA_ARGS+=('--xdebug') diff --git a/bin/run-gherkin-lint-tests b/bin/run-gherkin-lint-tests index 3a648e0ca..f2d2118a1 100755 --- a/bin/run-gherkin-lint-tests +++ b/bin/run-gherkin-lint-tests @@ -1,5 +1,13 @@ #!/bin/sh +# AI coding agents pay for every byte of a report they read back, so they get +# the compact, uncolored one by default. Setting NO_COLOR or WP_CLI_TEST_QUIET +# to an empty string keeps the full report. +if [ -n "${AI_AGENT}${CLAUDECODE}${CODEX_SANDBOX}${CURSOR_AGENT}${GEMINI_CLI}${ANTIGRAVITY_AGENT}" ]; then + [ -n "${NO_COLOR+set}" ] || export NO_COLOR=1 + [ -n "${WP_CLI_TEST_QUIET+set}" ] || export WP_CLI_TEST_QUIET=1 +fi + # Run the Gherkin linter only if there are feature files to lint. if [ ! -d "features" ] then diff --git a/bin/run-linter-tests b/bin/run-linter-tests index e43cacfc3..d642f4793 100755 --- a/bin/run-linter-tests +++ b/bin/run-linter-tests @@ -1,5 +1,13 @@ #!/bin/sh +# AI coding agents pay for every byte of a report they read back, so they get +# the compact, uncolored one by default. Setting NO_COLOR or WP_CLI_TEST_QUIET +# to an empty string keeps the full report. +if [ -n "${AI_AGENT}${CLAUDECODE}${CODEX_SANDBOX}${CURSOR_AGENT}${GEMINI_CLI}${ANTIGRAVITY_AGENT}" ]; then + [ -n "${NO_COLOR+set}" ] || export NO_COLOR=1 + [ -n "${WP_CLI_TEST_QUIET+set}" ] || export WP_CLI_TEST_QUIET=1 +fi + # Honor the NO_COLOR convention (https://no-color.org/). This has to turn the # color off explicitly rather than omit the flag, because the tool's own # detection only asks whether STDOUT is a terminal and knows nothing about diff --git a/bin/run-php-unit-tests b/bin/run-php-unit-tests index 3d89befab..5f9fa92c9 100755 --- a/bin/run-php-unit-tests +++ b/bin/run-php-unit-tests @@ -1,5 +1,13 @@ #!/bin/sh +# AI coding agents pay for every byte of a report they read back, so they get +# the compact, uncolored one by default. Setting NO_COLOR or WP_CLI_TEST_QUIET +# to an empty string keeps the full report. +if [ -n "${AI_AGENT}${CLAUDECODE}${CODEX_SANDBOX}${CURSOR_AGENT}${GEMINI_CLI}${ANTIGRAVITY_AGENT}" ]; then + [ -n "${NO_COLOR+set}" ] || export NO_COLOR=1 + [ -n "${WP_CLI_TEST_QUIET+set}" ] || export WP_CLI_TEST_QUIET=1 +fi + # Run the unit tests, if they exist if [ -f "phpunit.xml" ] || [ -f "phpunit.xml.dist" ] || [ -f ".phpunit.xml" ] || [ -f ".phpunit.xml.dist" ] then diff --git a/bin/run-phpcs-tests b/bin/run-phpcs-tests index 3c2a9f043..97408d95f 100755 --- a/bin/run-phpcs-tests +++ b/bin/run-phpcs-tests @@ -1,5 +1,13 @@ #!/bin/sh +# AI coding agents pay for every byte of a report they read back, so they get +# the compact, uncolored one by default. Setting NO_COLOR or WP_CLI_TEST_QUIET +# to an empty string keeps the full report. +if [ -n "${AI_AGENT}${CLAUDECODE}${CODEX_SANDBOX}${CURSOR_AGENT}${GEMINI_CLI}${ANTIGRAVITY_AGENT}" ]; then + [ -n "${NO_COLOR+set}" ] || export NO_COLOR=1 + [ -n "${WP_CLI_TEST_QUIET+set}" ] || export WP_CLI_TEST_QUIET=1 +fi + EXIT_CODE=0 # 1. Run standard PHP code style check if a configuration file exists. diff --git a/bin/run-phpstan-tests b/bin/run-phpstan-tests index a6cdeeac9..28495ddca 100755 --- a/bin/run-phpstan-tests +++ b/bin/run-phpstan-tests @@ -1,5 +1,13 @@ #!/bin/sh +# AI coding agents pay for every byte of a report they read back, so they get +# the compact, uncolored one by default. Setting NO_COLOR or WP_CLI_TEST_QUIET +# to an empty string keeps the full report. +if [ -n "${AI_AGENT}${CLAUDECODE}${CODEX_SANDBOX}${CURSOR_AGENT}${GEMINI_CLI}${ANTIGRAVITY_AGENT}" ]; then + [ -n "${NO_COLOR+set}" ] || export NO_COLOR=1 + [ -n "${WP_CLI_TEST_QUIET+set}" ] || export WP_CLI_TEST_QUIET=1 +fi + EXIT_CODE=0 # 1. Run the static analysis only if a configuration file exists. diff --git a/extension.neon b/extension.neon index ae4275061..73a34178f 100644 --- a/extension.neon +++ b/extension.neon @@ -25,6 +25,7 @@ services: - phpstan.parser.richParserNodeVisitor rules: - WP_CLI\Tests\PHPStan\WPCliAddHookCallbackRule + - WP_CLI\Tests\PHPStan\TestCaseParentRule parameters: dynamicConstantNames: diff --git a/src/Context/Support.php b/src/Context/Support.php index 824a496fb..c367c47e1 100644 --- a/src/Context/Support.php +++ b/src/Context/Support.php @@ -26,6 +26,10 @@ protected function missing_command_hint( $stderr = null ): string { $stderr = (string) $this->result->stderr; } + if ( preg_match( "/'([^']+)' is not a registered wp command\./", $stderr, $matches ) ) { + return "\n\nThe WP-CLI command `{$matches[1]}` is not installed. Only the commands of the packages in composer.json (`require` or `require-dev`) can be run in the tests, so add the package that provides it there."; + } + if ( ! preg_match( '/\b(?:sh|bash|dash|zsh)(?:: line \d+|: \d+)?: ([A-Za-z0-9_.+-]+): (?:command )?not found/', $stderr, $matches ) && ! preg_match( "/'([A-Za-z0-9_.+-]+)' is not recognized as an internal or external command/", $stderr, $matches ) diff --git a/src/PHPStan/TestCaseParentRule.php b/src/PHPStan/TestCaseParentRule.php new file mode 100644 index 000000000..ffb4eafa5 --- /dev/null +++ b/src/PHPStan/TestCaseParentRule.php @@ -0,0 +1,53 @@ + + */ +final class TestCaseParentRule implements Rule { + + public function getNodeType(): string { + return Class_::class; + } + + public function processNode( Node $node, Scope $scope ): array { + if ( null === $node->extends ) { + return []; + } + + $parent = $scope->resolveName( $node->extends ); + + if ( 'phpunit\\framework\\testcase' !== strtolower( $parent ) ) { + return []; + } + + return [ + RuleErrorBuilder::message( + sprintf( + 'Test class %s extends %s directly. Extend WP_CLI\\Tests\\TestCase instead, so the test runs on every supported PHPUnit version.', + null !== $node->name ? $node->name->toString() : 'class@anonymous', + $parent + ) + ) + ->identifier( 'wpcli.testCaseParent' ) + ->build(), + ]; + } +} diff --git a/src/StepChecker.php b/src/StepChecker.php new file mode 100644 index 000000000..b83f3d9d4 --- /dev/null +++ b/src/StepChecker.php @@ -0,0 +1,497 @@ + [], + 'config' => [], + 'tags' => [], + 'names' => [], + 'skip' => false, + ]; + $selects_config = false; + + for ( $i = 0, $count = count( $args ); $i < $count; $i++ ) { + $arg = $args[ $i ]; + if ( '' === $arg ) { + continue; + } + if ( '-' !== $arg[0] ) { + $result['paths'][] = $arg; + continue; + } + + $takes_next = in_array( $arg, self::VALUE_OPTIONS, true ) && $i + 1 < $count; + $value = $takes_next ? $args[ $i + 1 ] : (string) substr( $arg, (int) strpos( $arg, '=' ) + 1 ); + $option = $takes_next || false === strpos( $arg, '=' ) ? $arg : substr( $arg, 0, (int) strpos( $arg, '=' ) ); + + if ( preg_match( '/^(?:-[cps]|--config(?:=|$)|--profile(?:=|$)|--suite(?:=|$))/', $arg ) ) { + $selects_config = true; + if ( ! preg_match( '/^(?:-s|--suite)/', $arg ) ) { + $result['config'][] = $arg; + if ( $takes_next ) { + $result['config'][] = $args[ $i + 1 ]; + } + } + } elseif ( '--tags' === $option ) { + $result['tags'][] = $value; + } elseif ( '--name' === $option ) { + $result['names'][] = $value; + } elseif ( in_array( $option, [ '--tag-expression', '--role', '--narrative' ], true ) ) { + $result['skip'] = true; + } + + if ( $takes_next ) { + ++$i; + } + } + + if ( $selects_config && empty( $result['paths'] ) ) { + $result['skip'] = true; + } + + return $result; + } + + /** + * Whether the Behat configuration might filter scenarios of its own. + * + * Behat applies the filters of the configuration on top of the ones on + * the command line, which the checker does not follow. It treats any + * mention of filters, or any import that might hold them, in the + * configuration files or in BEHAT_PARAMS as a filter. + * + * @param string[] $config Configuration options from split_args(). + * @param string $dir Directory Behat runs in. + * @param string $behat_params Value of BEHAT_PARAMS. + * @return bool + */ + public static function config_may_filter( array $config, $dir, $behat_params ) { + if ( false !== stripos( $behat_params, 'filter' ) ) { + return true; + } + + $files = []; + for ( $i = 0, $count = count( $config ); $i < $count; $i++ ) { + if ( in_array( $config[ $i ], [ '-c', '--config' ], true ) && $i + 1 < $count ) { + $files[] = $config[ ++$i ]; + } elseif ( 0 === strpos( $config[ $i ], '--config=' ) ) { + $files[] = substr( $config[ $i ], strlen( '--config=' ) ); + } elseif ( preg_match( '/^-c(.+)$/', $config[ $i ], $matches ) ) { + $files[] = $matches[1]; + } + } + if ( empty( $files ) ) { + foreach ( [ '', 'config/' ] as $folder ) { + foreach ( [ 'behat.php', 'behat.dist.php', 'behat.yaml', 'behat.yml', 'behat.yaml.dist', 'behat.yml.dist', 'behat.dist.yaml', 'behat.dist.yml' ] as $name ) { + $files[] = $folder . $name; + } + } + } + + foreach ( $files as $file ) { + $path = preg_match( '#^(?:/|[A-Za-z]:[\\\\/])#', $file ) ? $file : $dir . '/' . $file; + if ( is_file( $path ) && preg_match( '/filter|import/i', (string) file_get_contents( $path ) ) ) { + return true; + } + } + + return false; + } + + /** + * Lists the feature files that the given Behat paths point to, each with the + * line ranges that select its scenarios, or null for all of them. + * + * @param string[] $paths Paths as Behat takes them, such as `features/a.feature:10`. + * @return array|null> + */ + public static function feature_files( array $paths ) { + if ( empty( $paths ) ) { + $paths = [ getenv( 'BEHAT_FEATURES_FOLDER' ) ?: 'features' ]; + } + + $files = []; + foreach ( $paths as $path ) { + $range = null; + if ( preg_match( '/^(.+):(\d+)(?:-(\d+|\*))?$/', $path, $matches ) ) { + $path = $matches[1]; + $end = isset( $matches[3] ) ? ( '*' === $matches[3] ? PHP_INT_MAX : (int) $matches[3] ) : (int) $matches[2]; + $range = [ (int) $matches[2], $end ]; + } + + if ( is_file( $path ) && '.feature' === substr( $path, -8 ) ) { + if ( null === $range ) { + $files[ $path ] = null; + } elseif ( ! array_key_exists( $path, $files ) || null !== $files[ $path ] ) { + $files[ $path ][] = $range; + } + } elseif ( is_dir( $path ) ) { + $iterator = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $path, \FilesystemIterator::SKIP_DOTS ) ); + foreach ( $iterator as $file ) { + if ( '.feature' === substr( $file->getFilename(), -8 ) ) { + $files[ $file->getPathname() ] = null; + } + } + } + } + ksort( $files ); + + return $files; + } + + /** + * Reads the definitions from the output of `behat --definitions=l`. + * + * @param string $listing Output of `behat -dl --no-colors`. + * @return array + */ + public static function parse_definitions( $listing ) { + $definitions = []; + + foreach ( preg_split( '/\R/', $listing ) ?: [] as $line ) { + if ( ! preg_match( '/^\s*\S+\s*\|\s*(Given|When|Then)\s+(.+?)\s*$/', $line, $matches ) ) { + continue; + } + + $pattern = $matches[2]; + $regex = self::is_regex( $pattern ) ? $pattern : self::turnip_to_regex( $pattern ); + + $definitions[] = [ + 'label' => $matches[1] . ' ' . $pattern, + 'regex' => $regex, + ]; + } + + return $definitions; + } + + /** + * Whether Behat reads a pattern as a regex rather than as Turnip, by the + * same rule as its RegexPatternPolicy. + * + * @param string $pattern + * @return bool + */ + public static function is_regex( $pattern ) { + return (bool) preg_match( '/^(?:\\{.*\\}|([~\\/#`]).*\1)[imsxADSUXJu]*$/s', $pattern ); + } + + /** + * Converts a Turnip pattern, such as `a WP install(ation) in :subdir`, to a + * regex the way Behat's TurnipPatternPolicy does, with the same token for + * a placeholder: a quoted value, or a word of letters, digits, `.` and `,`. + * + * @param string $pattern + * @return string + */ + public static function turnip_to_regex( $pattern ) { + $regex = preg_quote( $pattern, '/' ); + // Behat's own token: a quoted value, also inside quotes of the pattern itself, or a single word. + $regex = (string) preg_replace( '/\\\\:(\w+)/', '["\']?(?:(?<=")[^"]*(?=")|(?<=\')[^\']*(?=\')|\-?[\w\.\,]+)[\'"]?', $regex ); + // `(word)` is optional, and so are the spaces around it. + $regex = (string) preg_replace( '/(\s)?\\\\\(([^\\\]+)\\\\\)(\s)?/', '(?:\1)?(?:\2)?(?:\3)?', $regex ); + // `word/other` accepts either word; `\/` is a plain slash. + $regex = (string) preg_replace( '/(\w+)\\\\\/(\w+)/', '(?:\1|\2)', $regex ); + $regex = str_replace( '\\\/', '/', $regex ); + + return '/^' . $regex . '$/iu'; + } + + /** + * Lists the steps of a feature file that no definition matches, in the + * scenarios that Behat would run with the same paths and filters. + * + * The scenarios are selected with Behat's own Gherkin parser and filters, + * and the steps of a scenario outline are checked once per example, with + * its values filled in. + * + * @param string $contents Contents of the feature file. + * @param array $definitions + * @param array|null $lines Line ranges that select scenarios, + * as in `file.feature:10-20`, or + * null for all of them. + * @param string[] $tags Values of `--tags`, all of which + * have to match. + * @param string[] $names Values of `--name`, all of which + * have to match. + * @return array Undefined steps, with their keyword, keyed by line number. + */ + public static function find_undefined_steps( $contents, array $definitions, $lines = null, array $tags = [], array $names = [] ) { + // A project can configure the Gherkin compatibility mode, which may read a file differently, so + // only steps that are undefined however the file is read are reported, in the default reading. + $undefined = null; + foreach ( self::parse( $contents ) as $feature ) { + $found = self::undefined_steps_in( $feature, $definitions, $lines, $tags, $names ); + $undefined = null === $undefined ? $found : array_intersect_key( $undefined, $found ); + } + + return (array) $undefined; + } + + /** + * @param FeatureNode $feature + * @param array $definitions + * @param array|null $lines + * @param string[] $tags + * @param string[] $names + * @return array + */ + private static function undefined_steps_in( FeatureNode $feature, array $definitions, $lines, array $tags, array $names ) { + $filters = []; + foreach ( $tags as $tag ) { + $filters[] = new TagFilter( $tag ); + } + foreach ( $names as $name ) { + $filters[] = new NameFilter( $name ); + } + foreach ( $filters as $filter ) { + $feature = $filter->filterFeature( $feature ); + } + + // Each path is a run of its own, so the scenarios its lines select add up. Two paths can select + // different examples of one outline, so the scenarios are kept apart even when they share a line. + $scenarios = []; + $selected = null === $lines ? [ $feature ] : []; + foreach ( (array) $lines as $range ) { + $filter = $range[0] === $range[1] ? new LineFilter( $range[0] ) : new LineRangeFilter( $range[0], PHP_INT_MAX === $range[1] ? '*' : $range[1] ); + $selected[] = $filter->filterFeature( $feature ); + } + // The background of a rule only applies to the scenarios of that rule. + $backgrounds = []; + foreach ( $selected as $filtered ) { + // Newer versions of behat/gherkin deprecate getScenarios() for this. + $children = is_callable( [ $filtered, 'getExecutableChildren' ] ) ? $filtered->getExecutableChildren() : call_user_func( [ $filtered, 'getScenarios' ] ); + foreach ( $children as $child ) { + if ( $child instanceof ScenarioInterface ) { + $scenarios[] = $child; + } elseif ( is_object( $child ) && is_callable( [ $child, 'getExecutableChildren' ] ) ) { + foreach ( $child->getExecutableChildren() as $scenario ) { + // As in Behat, the steps of the background come first, and an outline fills in its examples in them too. + if ( is_callable( [ $scenario, 'extractFromRule' ] ) ) { + $scenario = $scenario->extractFromRule( $child ); + } elseif ( is_callable( [ $child, 'getBackground' ] ) && null !== $child->getBackground() ) { + $backgrounds[ $child->getBackground()->getLine() ] = $child->getBackground(); + } + $scenarios[] = $scenario; + } + } + } + } + + if ( empty( $scenarios ) ) { + return []; + } + + $steps = $feature->hasBackground() ? $feature->getBackground()->getSteps() : []; + foreach ( $backgrounds as $background ) { + $steps = array_merge( $steps, $background->getSteps() ); + } + foreach ( $scenarios as $scenario ) { + if ( $scenario instanceof OutlineNode ) { + foreach ( $scenario->getExamples() as $example ) { + $steps = array_merge( $steps, $example->getSteps() ); + } + } else { + $steps = array_merge( $steps, $scenario->getSteps() ); + } + } + + $undefined = []; + foreach ( $steps as $step ) { + if ( ! isset( $undefined[ $step->getLine() ] ) && ! self::is_defined( $step->getText(), $definitions ) ) { + $undefined[ $step->getLine() ] = rtrim( $step->getKeyword() ) . ' ' . $step->getText(); + } + } + ksort( $undefined ); + + return $undefined; + } + + /** + * Parses a feature file in every Gherkin compatibility mode that can. + * + * The reading of the mode the Behat installation uses by default comes + * first. None if no mode can parse the file, which Behat then reports. + * + * @param string $contents Contents of the feature file. + * @return FeatureNode[] + */ + private static function parse( $contents ) { + $parser = self::parser(); + $modes = [ null ]; + $enum = 'Behat\\Gherkin\\GherkinCompatibilityMode'; + if ( class_exists( $enum ) && method_exists( $parser, 'setGherkinCompatibilityMode' ) ) { + // Newest first. Behat 4 parses like recent cucumber/gherkin versions by default, Behat 3 in the legacy mode. + $modes = array_reverse( call_user_func( [ $enum, 'cases' ] ) ); + $legacy = constant( $enum . '::LEGACY' ); + $behat = class_exists( '\\Composer\\InstalledVersions' ) && \Composer\InstalledVersions::isInstalled( 'behat/behat' ) ? (string) \Composer\InstalledVersions::getVersion( 'behat/behat' ) : ''; + if ( version_compare( $behat, '4', '<' ) ) { + $others = array_filter( + $modes, + function ( $mode ) use ( $legacy ) { + return $mode !== $legacy; + } + ); + $modes = array_merge( [ $legacy ], $others ); + } + } + + $features = []; + foreach ( $modes as $mode ) { + if ( null !== $mode ) { + $parser->setGherkinCompatibilityMode( $mode ); + } + try { + $feature = $parser->parse( $contents ); + } catch ( \Exception $exception ) { + continue; + } + if ( $feature instanceof FeatureNode ) { + $features[] = $feature; + } + } + + return $features; + } + + /** + * The Gherkin parser of the Behat installation. + * + * @return Parser + */ + private static function parser() { + // Older versions of behat/gherkin ship the keywords in their root folder, newer ones still do. + $dir = dirname( (string) ( new \ReflectionClass( CachedArrayKeywords::class ) )->getFileName() ); + while ( ! file_exists( $dir . '/i18n.php' ) && dirname( $dir ) !== $dir ) { + $dir = dirname( $dir ); + } + + return new Parser( new Lexer( new CachedArrayKeywords( $dir . '/i18n.php' ) ) ); + } + + /** + * @param string $step Step text without its keyword. + * @param array $definitions + * @return bool + */ + private static function is_defined( $step, array $definitions ) { + foreach ( $definitions as $definition ) { + if ( 1 === @preg_match( $definition['regex'], $step ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- A definition this cannot parse simply does not match. + return true; + } + } + + return false; + } + + /** + * Picks the definitions that read most like the given step. + * + * @param string $step Step, with or without its keyword. + * @param array $definitions + * @param int $count + * @return array Labels of the closest definitions, closest first. + */ + public static function suggest( $step, array $definitions, $count = 3 ) { + $step = strtolower( (string) preg_replace( '/^(?:Given|When|Then|And|But|\*)\s+/', '', trim( $step ) ) ); + $scores = []; + + foreach ( $definitions as $definition ) { + similar_text( $step, self::readable( $definition['label'], $step ), $percent ); + $scores[ $definition['label'] ] = $percent; + } + + arsort( $scores ); + + return array_slice( array_keys( $scores ), 0, $count ); + } + + /** + * Renders a definition the way a step using it would read, as close to the + * given step as its alternatives allow, so that the two can be compared. + * + * @param string $label Definition label, keyword included. + * @param string $step Lowercase step text without its keyword. + * @return string + */ + private static function readable( $label, $step ) { + $text = strtolower( (string) preg_replace( '/^(?:Given|When|Then)\s+/', '', $label ) ); + + if ( ! self::is_regex( $text ) || ! preg_match( '/^[{~\/#`]\^?(.*?)\$?[}~\/#`][a-z]*$/is', $text, $matches ) ) { + // A Turnip pattern: placeholders read as a value, optional parts as written. + return (string) preg_replace( [ '/:\w+/', '/[()]/' ], [ 'x', '' ], $text ); + } + + $text = $matches[1]; + + // Innermost groups first: a list of words becomes the one closest to the + // step, an optional part stays only if the step has it, and anything + // else that captures a value reads as a value. + do { + $text = (string) preg_replace_callback( + '/\((?:\?:)?([^()]*)\)(\?)?/', + static function ( $group ) use ( $step ) { + $alternatives = explode( '|', $group[1] ); + if ( preg_match( '/[\[\\.+*]/', $group[1] ) ) { + return 'x'; + } + if ( ! empty( $group[2] ) ) { + return false !== strpos( $step, trim( $group[1] ) ) ? $group[1] : ''; + } + $best = $alternatives[0]; + foreach ( $alternatives as $alternative ) { + if ( '' !== $alternative && false !== strpos( $step, $alternative ) && strlen( $alternative ) > strlen( $best ) ) { + $best = $alternative; + } + } + return false !== strpos( $step, $best ) ? $best : $alternatives[0]; + }, + $text, + -1, + $replaced + ); + } while ( $replaced > 0 ); + + return stripslashes( $text ); + } +} diff --git a/tests/data/test_case_parent.php b/tests/data/test_case_parent.php new file mode 100644 index 000000000..028a5ab5c --- /dev/null +++ b/tests/data/test_case_parent.php @@ -0,0 +1,34 @@ + + */ +class TestTestCaseParentRule extends RuleTestCase { + + protected function getRule(): Rule { + return new TestCaseParentRule(); + } + + public function testRule(): void { + $this->analyse( + [ __DIR__ . '/../../data/test_case_parent.php' ], + [ + [ + 'Test class ExtendsPHPUnitTestCase extends PHPUnit\Framework\TestCase directly. Extend WP_CLI\Tests\TestCase instead, so the test runs on every supported PHPUnit version.', + 25, + ], + [ + 'Test class ExtendsPHPUnitTestCaseFullyQualified extends PHPUnit\Framework\TestCase directly. Extend WP_CLI\Tests\TestCase instead, so the test runs on every supported PHPUnit version.', + 29, + ], + ] + ); + } +} diff --git a/tests/tests/TestAgentReportDefaults.php b/tests/tests/TestAgentReportDefaults.php new file mode 100644 index 000000000..775d76344 --- /dev/null +++ b/tests/tests/TestAgentReportDefaults.php @@ -0,0 +1,129 @@ +markTestSkipped( 'The runner scripts are POSIX shell scripts.' ); + } + + $this->temp_dir = sys_get_temp_dir() . '/wp-cli-agent-defaults-' . uniqid(); + mkdir( $this->temp_dir . '/vendor/bin', 0777, true ); + touch( $this->temp_dir . '/phpcs.xml.dist' ); + + // Stands in for PHPCS and prints the arguments the runner passed to it. + file_put_contents( $this->temp_dir . '/vendor/bin/phpcs', "#!/bin/sh\necho \"ARGS:\$*\"\n" ); + chmod( $this->temp_dir . '/vendor/bin/phpcs', 0755 ); + } + + protected function tear_down(): void { + if ( '' !== $this->temp_dir ) { + unlink( $this->temp_dir . '/vendor/bin/phpcs' ); + unlink( $this->temp_dir . '/phpcs.xml.dist' ); + rmdir( $this->temp_dir . '/vendor/bin' ); + rmdir( $this->temp_dir . '/vendor' ); + rmdir( $this->temp_dir ); + } + + parent::tear_down(); + } + + /** + * @param array $env + */ + private function phpcs_args( array $env ): string { + // The variables go through env(1), because proc_open() drops the ones + // that are set to an empty string. + // A string rather than an array, which proc_open() only takes as of PHP 7.4. + $command = 'env'; + foreach ( $env as $name => $value ) { + $command .= ' ' . escapeshellarg( "{$name}={$value}" ); + } + $command .= ' ' . escapeshellarg( dirname( __DIR__, 2 ) . '/bin/run-phpcs-tests' ); + + $process = proc_open( + $command, + [ 1 => [ 'pipe', 'w' ] ], + $pipes, + $this->temp_dir, + [ 'PATH' => (string) getenv( 'PATH' ) ] + ); + $this->assertIsResource( $process ); + + $output = (string) stream_get_contents( $pipes[1] ); + fclose( $pipes[1] ); + proc_close( $process ); + + $this->assertSame( 1, preg_match( '/^ARGS:(.*)$/m', $output, $matches ), $output ); + + return trim( $matches[1] ); + } + + /** + * @return array, string}> + */ + public static function data_environments(): array { + return [ + 'no agent' => [ [], '' ], + 'Claude Code' => [ [ 'CLAUDECODE' => '1' ], '-q --report=emacs' ], + 'generic AI_AGENT marker' => [ [ 'AI_AGENT' => 'some-agent' ], '-q --report=emacs' ], + 'Antigravity' => [ [ 'ANTIGRAVITY_AGENT' => '1' ], '-q --report=emacs' ], + 'agent opted out' => [ + [ + 'CLAUDECODE' => '1', + 'WP_CLI_TEST_QUIET' => '', + ], + '', + ], + 'quiet asked for by a user' => [ [ 'WP_CLI_TEST_QUIET' => '1' ], '-q --report=emacs' ], + ]; + } + + /** + * @dataProvider data_environments + * + * @param array $env + */ + #[DataProvider( 'data_environments' )] // phpcs:ignore PHPCompatibility.Attributes.NewAttributes.PHPUnitAttributeFound + public function test_phpcs_report_follows_the_environment( array $env, string $expected ): void { + $this->assertSame( $expected, $this->phpcs_args( $env ) ); + } + + /** + * Every runner has to detect agents the same way, or one of them drifts. + */ + public function test_all_runners_share_the_same_detection(): void { + $blocks = []; + foreach ( self::SCRIPTS as $script ) { + $source = (string) file_get_contents( dirname( __DIR__, 2 ) . '/bin/' . $script ); + $this->assertSame( 1, preg_match( '/^# AI coding agents.*?^fi$/ms', $source, $matches ), "{$script} has no agent detection." ); + $blocks[ $script ] = $matches[0]; + } + + $this->assertCount( 1, array_unique( $blocks ), 'The agent detection differs between the runner scripts.' ); + } +} diff --git a/tests/tests/TestMissingCommandHint.php b/tests/tests/TestMissingCommandHint.php index c6aa87210..8864ad508 100644 --- a/tests/tests/TestMissingCommandHint.php +++ b/tests/tests/TestMissingCommandHint.php @@ -48,6 +48,13 @@ public static function data_missing_commands(): array { ]; } + public function test_unregistered_wp_commands_point_to_composer_json(): void { + $this->assertStringContainsString( + 'The WP-CLI command `scaffold` is not installed. Only the commands of the packages in composer.json', + $this->hint( "Error: 'scaffold' is not a registered wp command. See 'wp help' for available commands.\n" ) + ); + } + public function test_other_errors_get_no_hint(): void { $this->assertSame( '', $this->hint( "Error: not found\n" ) ); $this->assertSame( '', $this->hint( "Error: Plugin: not found\n" ) ); diff --git a/tests/tests/TestStepChecker.php b/tests/tests/TestStepChecker.php new file mode 100644 index 000000000..b27b8c2a4 --- /dev/null +++ b/tests/tests/TestStepChecker.php @@ -0,0 +1,365 @@ + + */ + private function definitions(): array { + return StepChecker::parse_definitions( self::LISTING ); + } + + public function test_parses_every_definition(): void { + $this->assertCount( 13, $this->definitions() ); + $this->assertSame( 'Given an empty directory', $this->definitions()[0]['label'] ); + } + + /** + * @return array + */ + public static function data_defined_steps(): array { + return [ + 'plain turnip' => [ 'Given an empty directory' ], + 'regex with alternatives' => [ 'And a wp-cli.yml file:' ], + 'turnip optional part' => [ 'Given a WP installation in subdir' ], + 'turnip without it' => [ "Given a WP install in 'foo bar'" ], + 'regex with backticks' => [ 'When I try `wp cli version --debug`' ], + 'optional regex group' => [ 'Then the return code should not be 1' ], + 'turnip placeholder' => [ 'Then the HTTP status code should be 200' ], + 'but keyword' => [ 'But STDERR should be empty' ], + 'star keyword' => [ '* STDOUT should strictly contain:' ], + 'turnip other case' => [ 'Given An Empty Directory' ], + 'optional word left out' => [ 'Given I have apples' ], + 'optional word written' => [ 'Given I have some apples' ], + 'tilde regex' => [ 'Given A widget named foo' ], + 'brace regex' => [ 'Then the cache should not be warm' ], + 'quoted placeholder word' => [ 'Given a file named "foo"' ], + 'quoted placeholder text' => [ 'Given a file named "foo bar"' ], + ]; + } + + /** + * @dataProvider data_defined_steps + */ + #[DataProvider( 'data_defined_steps' )] // phpcs:ignore PHPCompatibility.Attributes.NewAttributes.PHPUnitAttributeFound + public function test_defined_steps_are_not_reported( string $step ): void { + $this->assertSame( [], StepChecker::find_undefined_steps( "Feature: X\n Scenario: Y\n {$step}\n", $this->definitions() ) ); + } + + public function test_reports_undefined_steps_with_their_line(): void { + $feature = implode( + "\n", + [ + 'Feature: X', + ' Scenario: Y', + ' Given an empty directory', + ' Then STDOUT should equal:', + ' """', + ' Then this line is not a step', + ' """', + ' And the exit code should be 0', + ] + ); + + $this->assertSame( + [ + 4 => 'Then STDOUT should equal:', + 8 => 'And the exit code should be 0', + ], + StepChecker::find_undefined_steps( $feature, $this->definitions() ) + ); + } + + public function test_outline_steps_are_checked_per_example(): void { + $feature = implode( + "\n", + [ + 'Feature: X', + ' Scenario Outline: Y', + ' Then the return code should be ', + ' And the code should be 0', + '', + ' Examples:', + ' | code | noun |', + ' | 0 | return |', + ' | 1 | exit |', + ] + ); + + $this->assertSame( [ 4 => 'And the exit code should be 0' ], StepChecker::find_undefined_steps( $feature, $this->definitions() ) ); + } + + public function test_tags_and_names_select_scenarios_like_behat(): void { + $feature = implode( + "\n", + [ + 'Feature: X', + '', + ' @wip', + ' Scenario: Unfinished', + ' Given a step that does not exist yet', + '', + ' Scenario: Finished', + ' Given another missing step', + ] + ); + + $this->assertSame( [ 5, 8 ], array_keys( StepChecker::find_undefined_steps( $feature, $this->definitions() ) ) ); + $this->assertSame( [ 8 ], array_keys( StepChecker::find_undefined_steps( $feature, $this->definitions(), null, [ '~@wip&&~@broken' ] ) ) ); + $this->assertSame( [], array_keys( StepChecker::find_undefined_steps( $feature, $this->definitions(), null, [ '~@wip', '@wip' ] ) ) ); + $this->assertSame( [ 5 ], array_keys( StepChecker::find_undefined_steps( $feature, $this->definitions(), null, [], [ 'Unfinished' ] ) ) ); + } + + /** + * @return array + */ + public static function data_suggestions(): array { + return [ + 'wrong verb' => [ 'Then STDOUT should equal:', 'Then /^(STDOUT|STDERR) should( strictly)? (be|contain|not contain):$/' ], + 'wrong noun' => [ 'And the exit code should be 0', 'Then /^the return code should( not)? be (\d+)$/' ], + 'wrong article' => [ 'Given the empty directory', 'Given an empty directory' ], + 'missing colon' => [ 'Then STDOUT should be JSON containing', 'Then /^STDOUT should be JSON containing:$/' ], + ]; + } + + /** + * @dataProvider data_suggestions + */ + #[DataProvider( 'data_suggestions' )] // phpcs:ignore PHPCompatibility.Attributes.NewAttributes.PHPUnitAttributeFound + public function test_suggests_the_closest_definition_first( string $step, string $expected ): void { + $this->assertSame( $expected, StepChecker::suggest( $step, $this->definitions() )[0] ); + } + + public function test_doc_strings_may_carry_a_content_type(): void { + $feature = implode( + "\n", + [ + 'Feature: X', + ' Scenario: Y', + ' Given a wp-cli.yml file:', + ' ```yaml', + ' Then this line is not a step', + ' ```', + ' And the exit code should be 0', + ] + ); + + $this->assertSame( [ 7 => 'And the exit code should be 0' ], StepChecker::find_undefined_steps( $feature, $this->definitions() ) ); + } + + public function test_selected_lines_check_only_their_scenarios_and_the_background(): void { + $feature = implode( + "\n", + [ + 'Feature: X', // 1 + ' Background:', // 2 + ' Given no such step', // 3 + '', // 4 + ' Scenario: Selected', // 5 + ' Given another missing step', // 6 + '', // 7 + ' @tag', // 8 + ' Scenario: Not selected', // 9 + ' Given a third missing step', // 10 + ] + ); + + $this->assertSame( [ 3, 6, 10 ], array_keys( StepChecker::find_undefined_steps( $feature, $this->definitions() ) ) ); + $this->assertSame( [ 3, 6 ], array_keys( StepChecker::find_undefined_steps( $feature, $this->definitions(), [ [ 5, 5 ] ] ) ) ); + $this->assertSame( [ 3, 10 ], array_keys( StepChecker::find_undefined_steps( $feature, $this->definitions(), [ [ 9, PHP_INT_MAX ] ] ) ) ); + $this->assertSame( [ 3, 6, 10 ], array_keys( StepChecker::find_undefined_steps( $feature, $this->definitions(), [ [ 5, 5 ], [ 9, 9 ] ] ) ) ); + $this->assertSame( [], StepChecker::find_undefined_steps( $feature, $this->definitions(), [ [ 6, 6 ] ] ) ); + + $outline = implode( + "\n", + [ + 'Feature: X', // 1 + ' Scenario Outline: Codes', // 2 + ' Then the return code should be ', // 3 + '', // 4 + ' Examples:', // 5 + ' | code |', // 6 + ' | many |', // 7 + ' | 0 |', // 8 + ] + ); + + // Two paths that select different examples of one outline both count. + $this->assertSame( [ 3 ], array_keys( StepChecker::find_undefined_steps( $outline, $this->definitions(), [ [ 7, 7 ], [ 8, 8 ] ] ) ) ); + $this->assertSame( [], StepChecker::find_undefined_steps( $outline, $this->definitions(), [ [ 8, 8 ] ] ) ); + } + + public function test_a_rule_background_applies_only_to_the_scenarios_of_its_rule(): void { + if ( ! class_exists( 'Behat\\Gherkin\\GherkinCompatibilityMode' ) ) { + $this->markTestSkipped( 'This version of behat/gherkin cannot parse rules.' ); + } + + $feature = implode( + "\n", + [ + 'Feature: X', + '', + ' Rule: First', + ' Background:', + ' Given a step that does not exist yet', + '', + ' Scenario: In the first rule', + ' Given I have apples', + '', + ' Rule: Second', + ' Scenario: In the second rule', + ' Given another missing step', + ] + ); + + $expected = [ + 5 => 'Given a step that does not exist yet', + 12 => 'Given another missing step', + ]; + $this->assertSame( $expected, StepChecker::find_undefined_steps( $feature, $this->definitions() ) ); + $this->assertSame( [ 12 ], array_keys( StepChecker::find_undefined_steps( $feature, $this->definitions(), [ [ 11, 11 ] ] ) ) ); + $this->assertSame( [ 12 ], array_keys( StepChecker::find_undefined_steps( $feature, $this->definitions(), null, [], [ 'second' ] ) ) ); + $this->assertSame( [ 5 ], array_keys( StepChecker::find_undefined_steps( $feature, $this->definitions(), [ [ 7, 7 ] ] ) ) ); + + $outline = implode( + "\n", + [ + 'Feature: X', + '', + ' Rule: With examples', + ' Background:', + ' Given I have apples', + '', + ' Scenario Outline: Counting', + ' Given I have apples', + '', + ' Examples:', + ' | amount |', + ' | some |', + ' | many |', + ] + ); + + // Behat 3 parses in the legacy mode by default, which reads the rule as part of the description, + // so that its background becomes the background of the feature, which an outline does not fill in. + $behat_3 = version_compare( (string) \Composer\InstalledVersions::getVersion( 'behat/behat' ), '4', '<' ); + $expected = $behat_3 ? 'Given I have apples' : 'Given I have many apples'; + $this->assertSame( [ 5 => $expected ], StepChecker::find_undefined_steps( $outline, $this->definitions() ) ); + + // A project on Behat 3 may parse like recent cucumber/gherkin versions, which fills in the examples. + $defined = str_replace( '| many |', '| some |', $outline ); + $this->assertSame( [], StepChecker::find_undefined_steps( $defined, $this->definitions() ) ); + } + + public function test_option_values_are_not_paths_and_the_configuration_is_kept(): void { + $this->assertSame( + [ + 'paths' => [ 'features/a.feature:10' ], + 'config' => [ '--profile', 'ci', '-cbehat.yml' ], + 'tags' => [ '~@broken', '@smoke' ], + 'names' => [ 'install' ], + 'skip' => false, + ], + StepChecker::split_args( [ '--tags=~@broken', '--tags', '@smoke', '--name=install', '--profile', 'ci', '-cbehat.yml', '--format=progress', 'features/a.feature:10' ] ) + ); + } + + /** + * @return array + */ + public static function data_unfollowed_selections(): array { + return [ + 'tag expression' => [ [ '--tag-expression', 'not @wip' ] ], + 'role' => [ [ '--role=admin', 'features/a.feature' ] ], + 'profile without paths' => [ [ '-p', 'ci' ] ], + 'suite without paths' => [ [ '--suite=core' ] ], + 'config file without paths' => [ [ '--config=custom.yml' ] ], + ]; + } + + /** + * @dataProvider data_unfollowed_selections + * + * @param string[] $args + */ + #[DataProvider( 'data_unfollowed_selections' )] // phpcs:ignore PHPCompatibility.Attributes.NewAttributes.PHPUnitAttributeFound + public function test_selections_it_cannot_follow_skip_the_check( array $args ): void { + $this->assertTrue( StepChecker::split_args( $args )['skip'] ); + } + + public function test_filters_in_the_configuration_skip_the_check(): void { + $dir = sys_get_temp_dir() . '/wp-cli-step-checker-config-' . uniqid(); + mkdir( $dir ); + file_put_contents( $dir . '/behat.yml', "default:\n suites:\n default:\n paths:\n - features\n" ); + file_put_contents( $dir . '/filtered.yml', "default:\n suites:\n default:\n filters:\n tags: '~@broken'\n" ); + + try { + $this->assertFalse( StepChecker::config_may_filter( [], $dir, '' ) ); + $this->assertFalse( StepChecker::config_may_filter( [ '-p', 'default' ], $dir, '{"suites":{"default":{"paths":["features"]}}}' ) ); + $this->assertTrue( StepChecker::config_may_filter( [], $dir, '{"suites":{"default":{"filters":{"tags":"~@broken"}}}}' ) ); + $this->assertTrue( StepChecker::config_may_filter( [ '-c', 'filtered.yml' ], $dir, '' ) ); + $this->assertTrue( StepChecker::config_may_filter( [ '--config=' . $dir . '/filtered.yml' ], '/nonexistent', '' ) ); + + file_put_contents( $dir . '/behat.yml', "imports:\n - filtered.yml\n" ); + $this->assertTrue( StepChecker::config_may_filter( [], $dir, '' ) ); + } finally { + array_map( 'unlink', (array) glob( $dir . '/*' ) ); + rmdir( $dir ); + } + } + + public function test_feature_files_keep_the_selected_lines(): void { + $dir = sys_get_temp_dir() . '/wp-cli-step-checker-' . uniqid(); + mkdir( $dir . '/sub', 0777, true ); + touch( $dir . '/a.feature' ); + touch( $dir . '/sub/b.feature' ); + touch( $dir . '/sub/notes.txt' ); + + try { + $this->assertSame( + [ + $dir . '/a.feature' => [ [ 10, 10 ], [ 20, 30 ] ], + $dir . '/sub' . DIRECTORY_SEPARATOR . 'b.feature' => null, + ], + StepChecker::feature_files( [ $dir . '/a.feature:10', $dir . '/a.feature:20-30', $dir . '/sub', $dir . '/missing.feature' ] ) + ); + $this->assertSame( [ $dir . '/a.feature' => null ], StepChecker::feature_files( [ $dir . '/a.feature:5-*', $dir . '/a.feature' ] ) ); + $this->assertSame( [ [ 5, PHP_INT_MAX ] ], StepChecker::feature_files( [ $dir . '/a.feature:5-*' ] )[ $dir . '/a.feature' ] ); + + $features_folder = getenv( 'BEHAT_FEATURES_FOLDER' ); + putenv( 'BEHAT_FEATURES_FOLDER=' . $dir . '/sub' ); + $this->assertSame( [ $dir . '/sub' . DIRECTORY_SEPARATOR . 'b.feature' => null ], StepChecker::feature_files( [] ) ); + } finally { + if ( isset( $features_folder ) ) { + putenv( false === $features_folder ? 'BEHAT_FEATURES_FOLDER' : 'BEHAT_FEATURES_FOLDER=' . $features_folder ); + } + unlink( $dir . '/a.feature' ); + unlink( $dir . '/sub/b.feature' ); + unlink( $dir . '/sub/notes.txt' ); + rmdir( $dir . '/sub' ); + rmdir( $dir ); + } + } +} diff --git a/utils/check-feature-steps.php b/utils/check-feature-steps.php new file mode 100644 index 000000000..6c3bfbaee --- /dev/null +++ b/utils/check-feature-steps.php @@ -0,0 +1,76 @@ + ...] + * + * Expects to run from the package root with BEHAT_PARAMS set the way + * run-behat-tests sets it. Exits with 1 if it finds an undefined step, with 2 + * if the definitions cannot be listed, and with 0 otherwise. + */ + +namespace WP_CLI\Tests; + +if ( is_file( 'vendor/autoload.php' ) ) { + require_once 'vendor/autoload.php'; +} +if ( ! class_exists( StepChecker::class ) ) { + require_once __DIR__ . '/../src/StepChecker.php'; +} + +/** + * @param string[] $args Command-line arguments, options included. + * @return int Exit status. + */ +function check_feature_steps( array $args ) { + if ( ! is_file( 'vendor/bin/behat' ) ) { + return 0; + } + + $args = StepChecker::split_args( $args ); + if ( $args['skip'] || StepChecker::config_may_filter( $args['config'], (string) getcwd(), (string) getenv( 'BEHAT_PARAMS' ) ) ) { + return 0; + } + + // A worker of a parallel run gets a list of the scenarios to run, all of which were checked before. + foreach ( $args['paths'] as $path ) { + if ( is_file( $path ) && '.feature' !== substr( $path, -8 ) ) { + return 0; + } + } + + $listing = []; + exec( escapeshellarg( PHP_BINARY ) . ' vendor/bin/behat --definitions=l --no-colors ' . implode( ' ', array_map( 'escapeshellarg', $args['config'] ) ) . ' 2>/dev/null', $listing, $status ); + if ( 0 !== $status ) { + // Some of the definitions may be missing, which run-behat-tests does not take for a finding. + fwrite( STDERR, "Could not list the step definitions (exit status {$status}).\n" ); + return 2; + } + + $definitions = StepChecker::parse_definitions( implode( "\n", $listing ) ); + if ( empty( $definitions ) ) { + return 0; + } + + $found = 0; + foreach ( StepChecker::feature_files( $args['paths'] ) as $file => $lines ) { + foreach ( StepChecker::find_undefined_steps( (string) file_get_contents( $file ), $definitions, $lines, $args['tags'], $args['names'] ) as $line => $step ) { + ++$found; + echo "{$file}:{$line}: No step definition matches \"{$step}\". Closest existing steps:\n"; + foreach ( StepChecker::suggest( $step, $definitions ) as $suggestion ) { + echo " {$suggestion}\n"; + } + } + } + + if ( 0 === $found ) { + return 0; + } + + echo "\n{$found} undefined " . ( 1 === $found ? 'step' : 'steps' ) . ". Use an existing step rather than defining a new one; `composer behat -- --definitions=l` lists them all.\n"; + + return 1; +} + +exit( check_feature_steps( array_slice( $argv, 1 ) ) );