Skip to content

Commit

Permalink
Merge pull request #10 from wp-cli/configurable-features-folder
Browse files Browse the repository at this point in the history
Make features folder configurable in behat-tags.php
  • Loading branch information
schlessera authored Aug 6, 2018
2 parents c68fa22 + e82332f commit fcc1f29
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions utils/behat-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
* vendor/bin/behat --format progress $BEHAT_TAGS
*/

function version_tags( $prefix, $current, $operator = '<' ) {
function version_tags(
$prefix,
$current,
$operator = '<',
$features_folder = 'features'
) {
if ( ! $current ) {
return array();
}

exec( "grep '@{$prefix}-[0-9\.]*' -h -o features/*.feature | uniq", $existing_tags );
exec( "grep '@{$prefix}-[0-9\.]*' -h -o {$features_folder}/*.feature | uniq",
$existing_tags );

$skip_tags = array();

Expand All @@ -32,27 +38,34 @@ function version_tags( $prefix, $current, $operator = '<' ) {
return $skip_tags;
}

$features_folder = getenv( 'BEHAT_FEATURES_FOLDER' ) ?: 'features';
$wp_version = getenv( 'WP_VERSION' );
$wp_version_reqs = array();
// Only apply @require-wp tags when WP_VERSION isn't 'latest', 'nightly' or 'trunk'.
// 'latest', 'nightly' and 'trunk' are expected to work with all features.
if ( $wp_version && ! in_array( $wp_version, array( 'latest', 'nightly', 'trunk' ), true ) ) {
if ( $wp_version &&
! in_array( $wp_version, array( 'latest', 'nightly', 'trunk' ), true ) ) {
$wp_version_reqs = array_merge(
version_tags( 'require-wp', $wp_version, '<' ),
version_tags( 'less-than-wp', $wp_version, '>=' )
version_tags( 'require-wp', $wp_version, '<', $features_folder ),
version_tags( 'less-than-wp', $wp_version, '>=', $features_folder )
);
} else {
// But make sure @less-than-wp tags always exist for those special cases. (Note: @less-than-wp-latest etc won't work and shouldn't be used).
$wp_version_reqs = array_merge( $wp_version_reqs, version_tags( 'less-than-wp', '9999', '>=' ) );
$wp_version_reqs = array_merge( $wp_version_reqs,
version_tags( 'less-than-wp', '9999', '>=', $features_folder ) );
}

$skip_tags = array_merge(
$wp_version_reqs,
version_tags( 'require-php', PHP_VERSION, '<' ),
version_tags( 'less-than-php', PHP_VERSION, '>=' ) // Note: this was '>' prior to WP-CLI 1.5.0 but the change is unlikely to cause BC issues as usually compared against major.minor only.
version_tags( 'require-php', PHP_VERSION, '<', $features_folder ),

// Note: this was '>' prior to WP-CLI 1.5.0 but the change is unlikely to
// cause BC issues as usually compared against major.minor only.
version_tags( 'less-than-php', PHP_VERSION, '>=', $features_folder )
);

# Skip Github API tests if `GITHUB_TOKEN` not available because of rate limiting. See https://github.com/wp-cli/wp-cli/issues/1612
// Skip Github API tests if `GITHUB_TOKEN` not available because of rate
// limiting. See https://github.com/wp-cli/wp-cli/issues/1612
if ( ! getenv( 'GITHUB_TOKEN' ) ) {
$skip_tags[] = '@github-api';
}
Expand All @@ -61,9 +74,12 @@ function version_tags( $prefix, $current, $operator = '<' ) {
$skip_tags[] = '@broken';

# Require PHP extension, eg 'imagick'.
function extension_tags() {
function extension_tags( $features_folder = 'features' ) {
$extension_tags = array();
exec( "grep '@require-extension-[A-Za-z_]*' -h -o features/*.feature | uniq", $extension_tags );
exec(
"grep '@require-extension-[A-Za-z_]*' -h -o {$features_folder}/*.feature | uniq",
$extension_tags
);

$skip_tags = array();

Expand All @@ -78,9 +94,8 @@ function extension_tags() {
return $skip_tags;
}

$skip_tags = array_merge( $skip_tags, extension_tags() );
$skip_tags = array_merge( $skip_tags, extension_tags( $features_folder ) );

if ( ! empty( $skip_tags ) ) {
echo '--tags=~' . implode( '&&~', $skip_tags );
}

0 comments on commit fcc1f29

Please sign in to comment.