Skip to content

Commit

Permalink
Update helper test function assert_result() to swap arguments order
Browse files Browse the repository at this point in the history
  • Loading branch information
iangmaia committed Feb 19, 2025
1 parent d9f3659 commit e55dd43
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions tests/pr_changed_files/test_all_match_patterns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ git commit -m "Add doc files"
# [Test] All changes in docs - exit code only
output=$(pr_changed_files --all-match 'docs/*')
result=$?
assert_result 0 $result "$output" "" "Should match when all changes are in docs"
assert_result 0 $result "" "$output" "Should match when all changes are in docs"

# Test with stdout
output=$(pr_changed_files --stdout --all-match 'docs/*')
result=$?
assert_result 0 $result "$output" "true" "Should match when all changes are in docs with --stdout"
assert_result 0 $result "true" "$output" "Should match when all changes are in docs with --stdout"

# [Test] All changes in docs with explicit patterns including spaces and special chars - exit code only
output=$(pr_changed_files --all-match 'docs/read me.md' 'docs/guide with spaces.md' 'docs/special\\!@\*#$chars.md')
Expand Down
4 changes: 2 additions & 2 deletions tests/pr_changed_files/test_any_match_patterns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ git commit -m "Add test files"
# [Test] Match specific extension - exit code only
output=$(pr_changed_files --any-match '*.swift')
result=$?
assert_result 0 $result "$output" "" "Should match .swift files"
assert_result 0 $result "" "$output" "Should match .swift files"

# Test with stdout
output=$(pr_changed_files --stdout --any-match '*.swift')
result=$?
assert_result 0 $result "$output" "true" "Should match .swift files with --stdout"
assert_result 0 $result "true" "$output" "Should match .swift files with --stdout"

# [Test] Match multiple patterns - exit code only
output=$(pr_changed_files --any-match 'docs/*.md' '*.rb')
Expand Down
4 changes: 2 additions & 2 deletions tests/pr_changed_files/test_basic_changes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ init_test_repo "$repo_path"
# [Test] No changes - exit code only
output=$(pr_changed_files)
result=$?
assert_result 1 $result "$output" "" "Should return 1 when no files changed"
assert_result 1 $result "" "$output" "Should return 1 when no files changed"

# [Test] No changes - with stdout
output=$(pr_changed_files --stdout)
result=$?
assert_result 0 $result "$output" "false" "Should output 'false' and return 0 with --stdout when no files changed"
assert_result 0 $result "false" "$output" "Should output 'false' and return 0 with --stdout when no files changed"

# [Test] Single file change - exit code only
echo "change" > new.txt
Expand Down
8 changes: 4 additions & 4 deletions tests/pr_changed_files/test_edge_cases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ init_test_repo "$repo_path"
unset BUILDKITE_PULL_REQUEST
output=$(pr_changed_files 2>&1)
result=$?
assert_result 255 $result "$output" "Error: this tool can only be called from a Buildkite PR job" "Should fail when not in PR environment"
assert_result 255 $result "Error: this tool can only be called from a Buildkite PR job" "$output" "Should fail when not in PR environment"

export BUILDKITE_PULL_REQUEST="123"

# [Test] No patterns provided
output=$(pr_changed_files --any-match 2>&1)
result=$?
assert_result 255 $result "$output" "Error: must specify at least one file pattern" "Should fail when no patterns provided"
assert_result 255 $result "Error: must specify at least one file pattern" "$output" "Should fail when no patterns provided"

# [Test] Flag followed by another flag
output=$(pr_changed_files --any-match --something 2>&1)
result=$?
assert_result 255 $result "$output" "Error: must specify at least one file pattern" "Should fail with correct error when flag is followed by another flag"
assert_result 255 $result "Error: must specify at least one file pattern" "$output" "Should fail with correct error when flag is followed by another flag"

# [Test] Mutually exclusive options
output=$(pr_changed_files --any-match "*.txt" --all-match "*.md" 2>&1)
result=$?
assert_result 255 $result "$output" "Error: either specify --all-match or --any-match; cannot specify both" "Should fail with correct error when using mutually exclusive options"
assert_result 255 $result "Error: either specify --all-match or --any-match; cannot specify both" "$output" "Should fail with correct error when using mutually exclusive options"

# [Test] Files with spaces and special characters
mkdir -p 'folder with spaces/nested!\@*#$folder'
Expand Down
8 changes: 4 additions & 4 deletions tests/pr_changed_files/test_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ cleanup_git_repo() {
# Arguments:
# $1 - Expected return code
# $2 - Actual return code
# $3 - Actual output
# $4 - Expected output
# $3 - Expected output
# $4 - Actual output
# $5 - Optional message to display with the assertion result
assert_result() {
local expected_code="$1"
local actual_code="$2"
local actual_output="$3"
local expected_output="$4"
local expected_output="$3"
local actual_output="$4"
local message="$5"

assert_equal "$expected_code" "$actual_code" "Exit code - $message"
Expand Down

0 comments on commit e55dd43

Please sign in to comment.