From e55dd43921f57891c9306bec0e740a3ab83c81e1 Mon Sep 17 00:00:00 2001 From: Ian Maia Date: Tue, 18 Feb 2025 20:35:31 +0100 Subject: [PATCH] Update helper test function `assert_result()` to swap arguments order --- tests/pr_changed_files/test_all_match_patterns.sh | 4 ++-- tests/pr_changed_files/test_any_match_patterns.sh | 4 ++-- tests/pr_changed_files/test_basic_changes.sh | 4 ++-- tests/pr_changed_files/test_edge_cases.sh | 8 ++++---- tests/pr_changed_files/test_helpers.sh | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/pr_changed_files/test_all_match_patterns.sh b/tests/pr_changed_files/test_all_match_patterns.sh index 8150310d..24e41cdc 100755 --- a/tests/pr_changed_files/test_all_match_patterns.sh +++ b/tests/pr_changed_files/test_all_match_patterns.sh @@ -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') diff --git a/tests/pr_changed_files/test_any_match_patterns.sh b/tests/pr_changed_files/test_any_match_patterns.sh index 59b2f661..44289c8f 100755 --- a/tests/pr_changed_files/test_any_match_patterns.sh +++ b/tests/pr_changed_files/test_any_match_patterns.sh @@ -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') diff --git a/tests/pr_changed_files/test_basic_changes.sh b/tests/pr_changed_files/test_basic_changes.sh index 0ef32f28..754e1205 100755 --- a/tests/pr_changed_files/test_basic_changes.sh +++ b/tests/pr_changed_files/test_basic_changes.sh @@ -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 diff --git a/tests/pr_changed_files/test_edge_cases.sh b/tests/pr_changed_files/test_edge_cases.sh index 7c192345..ff211a41 100755 --- a/tests/pr_changed_files/test_edge_cases.sh +++ b/tests/pr_changed_files/test_edge_cases.sh @@ -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' diff --git a/tests/pr_changed_files/test_helpers.sh b/tests/pr_changed_files/test_helpers.sh index f1ba3d94..ee3c881b 100755 --- a/tests/pr_changed_files/test_helpers.sh +++ b/tests/pr_changed_files/test_helpers.sh @@ -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"