Skip to content

Commit e47c8ed

Browse files
authored
Merge pull request #96 from wp-cli/add/allow-negated-match
2 parents 8822837 + f109fd3 commit e47c8ed

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

.travis.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
sudo: false
2-
dist: trusty
1+
os: linux
2+
dist: xenial
33

44
language: php
5-
php: 7.2
5+
php: 7.4
6+
7+
services:
8+
- mysql
69

710
notifications:
811
email:
@@ -57,6 +60,12 @@ jobs:
5760
- composer phpcs
5861
- diff -B --tabsize=4 ./WP_CLI_CS/ruleset.xml <(xmllint --format "./WP_CLI_CS/ruleset.xml")
5962
env: BUILD=sniff
63+
- stage: test
64+
php: 7.4
65+
env: WP_VERSION=latest
66+
- stage: test
67+
php: 7.3
68+
env: WP_VERSION=latest
6069
- stage: test
6170
php: 7.2
6271
env: WP_VERSION=latest
@@ -72,10 +81,7 @@ jobs:
7281
- stage: test
7382
php: 5.6
7483
env: WP_VERSION=3.7.11
84+
dist: trusty
7585
- stage: test
7686
php: 5.6
7787
env: WP_VERSION=trunk
78-
- stage: test
79-
php: 5.4
80-
dist: precise
81-
env: WP_VERSION=5.1

features/bootstrap/support.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ function assert_regex( $regex, $actual ) {
1515
}
1616
}
1717

18+
function assert_not_regex( $regex, $actual ) {
19+
if ( preg_match( $regex, $actual ) ) {
20+
throw new Exception( 'Actual value: ' . var_export( $actual, true ) );
21+
}
22+
}
23+
1824
function assert_equals( $expected, $actual ) {
1925
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Deliberate loose comparison.
2026
if ( $expected != $actual ) {

features/steps/then.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,23 +225,31 @@ function ( $world, $path, $type, $action, $expected = null ) {
225225
);
226226

227227
$steps->Then(
228-
'/^the contents of the (.+) file should match (((\/.+\/)|(#.+#))([a-z]+)?)$/',
229-
function ( $world, $path, $expected ) {
228+
'/^the contents of the (.+) file should( not)? match (((\/.+\/)|(#.+#))([a-z]+)?)$/',
229+
function ( $world, $path, $not, $expected ) {
230230
$path = $world->replace_variables( $path );
231231
// If it's a relative path, make it relative to the current test dir.
232232
if ( '/' !== $path[0] ) {
233233
$path = $world->variables['RUN_DIR'] . "/$path";
234234
}
235235
$contents = file_get_contents( $path );
236-
Support\assert_regex( $expected, $contents );
236+
if ( $not ) {
237+
Support\assert_not_regex( $expected, $contents );
238+
} else {
239+
Support\assert_regex( $expected, $contents );
240+
}
237241
}
238242
);
239243

240244
$steps->Then(
241-
'/^(STDOUT|STDERR) should match (((\/.+\/)|(#.+#))([a-z]+)?)$/',
242-
function ( $world, $stream, $expected ) {
245+
'/^(STDOUT|STDERR) should( not)? match (((\/.+\/)|(#.+#))([a-z]+)?)$/',
246+
function ( $world, $stream, $not, $expected ) {
243247
$stream = strtolower( $stream );
244-
Support\assert_regex( $expected, $world->result->$stream );
248+
if ( $not ) {
249+
Support\assert_not_regex( $expected, $world->result->$stream );
250+
} else {
251+
Support\assert_regex( $expected, $world->result->$stream );
252+
}
245253
}
246254
);
247255

0 commit comments

Comments
 (0)