diff --git a/docs/assertions.md b/docs/assertions.md index 3591065d..783edbb8 100644 --- a/docs/assertions.md +++ b/docs/assertions.md @@ -36,11 +36,21 @@ to narrow it (`bashunit doc json`). ## assert_true > `assert_true bool|function|command` -Takes a **command**, not a test expression. A bracketed condition of the form -used inside `if` is run as a command word, so the shell reports exit code 127 and -the assertion fails with `unknown command`. Use the `test` builtin instead — -`assert_true "test -d /tmp"` — or a purpose-built assertion such as -`assert_directory_exists`. +The argument is run as a **single command word**, so it must be a bare command or +function name with no arguments. Anything with arguments — including a bracketed +condition of the form used inside `if` — is treated as one long command name, and +the assertion fails with `unknown command`. + +Prefix with `eval` to run anything more than a bare name: + +```bash +assert_true "my_function" # bare name: works +assert_true "eval test -d /tmp" # arguments: needs eval +assert_true "eval grep -q foo file" # arguments: needs eval +``` + +A purpose-built assertion is usually clearer still — `assert_directory_exists` +rather than a hand-rolled `test -d`. Reports an error if the argument result in a truthy value: `true` or `0`. diff --git a/tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_all_assert_docs.snapshot b/tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_all_assert_docs.snapshot index 53f416a7..2139b6f3 100644 --- a/tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_all_assert_docs.snapshot +++ b/tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_all_assert_docs.snapshot @@ -2,15 +2,12 @@ -------------- > `assert_true bool|function|command` -Takes a **command**, not a test expression. A bracketed condition of the form -used inside `if` is run as a command word, so the shell reports exit code 127 and -the assertion fails with `unknown command`. Use the `test` builtin instead — -`assert_true "test -d /tmp"` — or a purpose-built assertion such as -`assert_directory_exists`. +The argument is run as a **single command word**, so it must be a bare command or +function name with no arguments. Anything with arguments — including a bracketed +condition of the form used inside `if` — is treated as one long command name, and +the assertion fails with `unknown command`. -Reports an error if the argument result in a truthy value: `true` or `0`. - -- assert_false is similar but different. +Prefix with `eval` to run anything more than a bare name: ## assert_false