From 7a97277816bd2e952f51deffe5b44b1a14d6135c Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Fri, 14 Aug 2026 07:07:39 +0200 Subject: [PATCH] docs(patterns): fix swapped assert_file_contains arguments assert_file_contains takes "file" "search", but three examples in the guide users copy from had them reversed, so bashunit looked for a file literally named 'Error occurred' and failed with "Expected 'Error occurred'" -- which reads as missing content rather than backwards arguments. The line below one of them passed $TEST_LOG to assert_matches, matching the timestamp pattern against the path instead of the file's contents, so it never checked what its own comment described. Executed each example before and after: the originals fail, the corrections pass. Argument order is invisible to the docs-parity guards -- every symbol here exists and is spelled correctly -- so only running the examples finds it. Closes #1209 --- docs/common-patterns.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/common-patterns.md b/docs/common-patterns.md index 5074bce1..a357723c 100644 --- a/docs/common-patterns.md +++ b/docs/common-patterns.md @@ -127,7 +127,7 @@ function test_insert_record() { create_table "users" insert_record "users" "john@example.com" - assert_file_contains "john@example.com" "$TEST_DB/users.txt" + assert_file_contains "$TEST_DB/users.txt" "john@example.com" } ``` ::: @@ -252,9 +252,9 @@ function test_log_creates_file() { function test_log_writes_timestamp_and_message() { log_message "Error occurred" "$TEST_LOG" - assert_file_contains "Error occurred" "$TEST_LOG" + assert_file_contains "$TEST_LOG" "Error occurred" # Check for timestamp pattern (YYYY-MM-DD HH:MM:SS) - assert_matches "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}" "$TEST_LOG" + assert_matches "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}" "$(cat "$TEST_LOG")" } function test_log_appends_multiple_messages() { @@ -659,7 +659,7 @@ function tear_down() { function test_create_user() { create_test_user "John Doe" "john@example.com" - assert_file_contains "John Doe" "$TEST_DB/users.csv" + assert_file_contains "$TEST_DB/users.csv" "John Doe" } ``` :::