| Q | A |
|---|
| OS | macOS |
| Shell & version | bash 5.3.15 |
| bashunit version | 0.47.0 |
Summary
Current behavior
grep will fail in assert_file_contains, and assert_equals can't distinguish between backslashes or escaped control characters.
How to reproduce
functiontest_file_contains_with_leading_dash_pattern() {
local log
log=$(mktemp)printf'ssh -o BatchMode=yes host uptime\n'>"$log"
assert_file_contains "$log""-o BatchMode=yes"
rm -f "$log"
}
functiontest_equals_cannot_distinguish_backslashes() {
assert_equals 'C:\''C:\\'
}
functiontest_equals_cannot_distinguish_escape_from_literal() {
assert_equals 'a\tb'"$(printf 'a\tb')"
}
functiontest_same_distinguishes_them_correctly() {
assert_same 'C:\''C:\\'
}Expected behavior
First test should pass, second and third tests should fail.
Output:
There were 2 failures:
|1) test.sh:1
|✗ Failed: File contains with leading dash pattern
| Expected '/var/folders/z8/gsfp0t4n0fl8mp5xyrz5xptc0000gr/T/tmp.QRjrbletxK'
| to contain '-o BatchMode=yes'
| at test.sh:1
| Output:
|grep: invalid option --
|usage: grep [-abcdDEFGHhIiJLlMmnOopqRSsUVvwXxZz] [-A num] [-B num] [-C[num]]
| [-e pattern] [-f file] [--binary-files=value] [--color=when]
| [--context[=num]] [--directories=action] [--label] [--line-buffered]
| [--null] [pattern] [file ...]
| Source:
| 5: assert_file_contains "$log" "-o BatchMode=yes"
|2) test.sh:17
|✗ Failed: Same distinguishes them correctly
| Expected 'C:\'
| but got 'C:\'
| at test.sh:17
| Source:
| 18: assert_same 'C:\' 'C:\'
Tests: 2 passed, 2 failed, 4 total
Assertions: 2 passed, 2 failed, 4 total
Some tests failed
Time taken: 646ms
Summary
Current behavior
grep will fail in
assert_file_contains, andassert_equalscan't distinguish between backslashes or escaped control characters.How to reproduce
Expected behavior
First test should pass, second and third tests should fail.
Output: