Skip to content

Commit 40cac25

Browse files
committed
Improve tests with special characters
Using single quotes to make it easier to understand the use of special characters—including in the code creating the test files
1 parent 4cc76b2 commit 40cac25

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

tests/pr_changed_files/test_all_match_patterns.sh

+18-8
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ export BUILDKITE_PULL_REQUEST_BASE_BRANCH="base"
1717
# Initialize the repository
1818
init_test_repo "$repo_path"
1919

20-
# Create test files
20+
# Create test files (using single quotes to avoid special chars being interpreted by the shell)
2121
mkdir -p docs src/swift
22-
echo "doc" > "docs/read me.md"
23-
echo "doc2" > "docs/guide with spaces.md"
24-
echo "doc3" > "docs/special\!\@\#\$chars.md"
22+
echo "doc1" > 'docs/read me.md'
23+
echo "doc2" > 'docs/guide with spaces.md'
24+
echo "doc3" > 'docs/special\!@*#$chars.md'
2525
git add .
2626
git commit -m "Add doc files"
2727

@@ -30,20 +30,30 @@ result=$(pr_changed_files --all-match "docs/*")
3030
assert_output "true" "$result" "Should return true when all changes match patterns"
3131

3232
# [Test] All changes in docs with explicit patterns including spaces and special chars
33-
result=$(pr_changed_files --all-match 'docs/read me.md' 'docs/guide with spaces.md' 'docs/special\\!\\@\\#\$chars.md')
33+
# Note: we need to escape the '\` and `*` special chars in the pattern to match them literally instead of as special characters
34+
result=$(pr_changed_files --all-match 'docs/read me.md' 'docs/guide with spaces.md' 'docs/special\\!@\*#$chars.md')
3435
assert_output "true" "$result" "Should return true when all changes match patterns with spaces and special chars"
3536

37+
# [Test] All changes in docs with globbing patterns including spaces and special chars
38+
result=$(pr_changed_files --all-match 'docs/read me.md' 'docs/guide with spaces.md' 'docs/special\\!*.md')
39+
assert_output "true" "$result" "Should return true when all changes match patterns with spaces and special chars, even when using globbing"
40+
3641
# [Test] Changes outside pattern
37-
echo "swift" > "src/swift/main with spaces.swift"
38-
echo "swift" > "src/swift/special\!\@\#\$chars.swift"
42+
echo "swift" > 'src/swift/main with spaces.swift'
43+
echo "swift" > 'src/swift/special!\@#*$chars.swift'
3944
git add .
4045
git commit -m "Add swift file"
4146

4247
result=$(pr_changed_files --all-match "docs/*")
4348
assert_output "false" "$result" "Should return false when changes exist outside patterns"
4449

4550
# [Test] Multiple patterns, all matching
46-
result=$(pr_changed_files --all-match 'docs/*' 'src/swift/main with spaces.swift' 'src/swift/special\\!\\@\\#\$chars.swift')
51+
# Note: we need to escape the '\` and `*` special chars in the pattern to match them literally instead of as special characters
52+
result=$(pr_changed_files --all-match 'docs/*' 'src/swift/main with spaces.swift' 'src/swift/special\!\\@#\*$chars.swift')
4753
assert_output "true" "$result" "Should return true when all changes match multiple patterns"
4854

55+
# [Test] Multiple patterns, all matching, including some using globbing
56+
result=$(pr_changed_files --all-match 'docs/*' 'src/swift/main with spaces.swift' 'src/swift/special*chars.swift')
57+
assert_output "true" "$result" "Should return true when all changes match multiple patterns, including some using globbing"
58+
4959
echo "✅ All-match pattern tests passed"

0 commit comments

Comments
 (0)