Skip to content

Commit abf6585

Browse files
committed
update the tess to support passing a ruleset to test
1 parent f31f193 commit abf6585

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

tests/run-test.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
#!/bin/bash
22

3-
TEST_FILE=$1
3+
RULESET=$1
4+
TEST_FILE=$2
5+
6+
if [ -z "$RULESET" ]; then
7+
echo "Usage: $0 <ruleset> <test_file>"
8+
exit 1
9+
fi
410

511
if [ ! -f "$TEST_FILE" ]; then
612
echo "Test file not found: $TEST_FILE"
713
exit 1
814
fi
915

10-
echo "Running test: $TEST_FILE"
16+
echo "Running test: $TEST_FILE with ruleset: $RULESET"
1117

1218
# Use --basepath=. to ensure relative paths in the report.
13-
JSON_REPORT=$(phpcs --standard=Pantheon-WP-Minimum/ruleset.xml --report=json --basepath=. --warning-severity=0 "$TEST_FILE" 2>/dev/null | sed -n '/{/,$p')
19+
JSON_REPORT=$(phpcs --standard="./$RULESET/ruleset.xml" --report=json --basepath=. "$TEST_FILE" 2>/dev/null | sed -n '/{/,$p')
20+
21+
# Debug
22+
# echo "JSON Report:"
23+
# echo "$JSON_REPORT"
1424

1525
# Extract actual and expected errors.
1626
ACTUAL_OUTPUT=$(echo "$JSON_REPORT" | jq -r '.files."'"$TEST_FILE"'".messages[]?.source' | sort)
17-
EXPECTED_OUTPUT=$(sed -n 's/.*@expectedError //p' "$TEST_FILE" | sort)
27+
EXPECTED_OUTPUT=$( (sed -n "s/.*@expectedError\[$RULESET\] //p" "$TEST_FILE"; sed -n "s/.*@expectedWarning\[$RULESET\] //p" "$TEST_FILE") | sort)
1828

1929
echo "--------------------------------------------------"
20-
echo "EXPECTED ERRORS:"
30+
echo "EXPECTED ISSUES:"
2131
echo -e "${EXPECTED_OUTPUT:-<none>}"
2232
echo "--------------------------------------------------"
23-
echo "ACTUAL ERRORS:"
33+
echo "ACTUAL ISSUES:"
2434
echo -e "${ACTUAL_OUTPUT:-<none>}"
2535
echo "--------------------------------------------------"
2636

tests/test-disallow-multiline-slash-comment.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
/**
33
* Disallow usage of multiline slash comments.
44
*
5-
* @expectedError Pantheon_WP_Minimum.Commenting.DisallowMultilineSlashComment.Found
6-
* @expectedWarning Pantheon_WP_Minimum.Commenting.DisallowMultilineSlashComment.LongLine
5+
* @expectedWarning[Pantheon-WP-Minimum] Pantheon_WP_Minimum.Commenting.DisallowMultilineSlashComment.Found
6+
* @expectedError[Pantheon-WP] Pantheon_WP.Commenting.DisallowMultilineSlashComment.Found
7+
* @expectedWarning[Pantheon-WP] Pantheon_WP.Commenting.DisallowMultilineSlashComment.LongLine
78
*
89
* @package Pantheon-WP-Coding-Standards
910
*/
@@ -22,8 +23,8 @@
2223
/*
2324
* This comment is ideal. It uses the correct syntax and is not too long.
2425
* What's with the life preserver? Doc, she's beautiful. She's crazy about me.
25-
* Look at this, look what she wrote me, Doc. That says it all. Doc, you're my
26-
* only hope. Oh, uh, hey you, get your damn hands off her. Do you really think
27-
* I oughta swear? Well, now we gotta sneak this back into my laboratory, we've
26+
* Look at this, look what she wrote me, Doc. That says it all. Doc, you're my
27+
* only hope. Oh, uh, hey you, get your damn hands off her. Do you really think
28+
* I oughta swear? Well, now we gotta sneak this back into my laboratory, we've
2829
* gotta get you home. Jennifer.
2930
*/

tests/test-disallow-rename-function.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
/**
33
* DisallowRenameFunctionTest.inc
44
*
5-
* @expectedError Pantheon_WP_Minimum.Files.DisallowRenameFunction.RenameFunctionDisallowed
5+
* @expectedError[Pantheon-WP-Minimum] Pantheon_WP_Minimum.Files.DisallowRenameFunction.RenameFunctionDisallowed
6+
* @expectedError[Pantheon-WP] Pantheon_WP_Minimum.Files.DisallowRenameFunction.RenameFunctionDisallowed
67
*
78
* @package Pantheon-WP-Coding-Standards
89
*/

0 commit comments

Comments
 (0)