Bash · 1682 bytes Raw Blame History
1 #!/bin/sh
2 TEST_PREFIX="[echo]"
3 . "$(cd "$(dirname "$0")" && pwd)/test_harness.sh"
4
5 section "1. echo basic"
6 compare_output "echo basic string" 'echo hello world'
7 compare_output "echo with no arguments" 'echo'
8 compare_output "echo with multiple spaced args" 'echo a b c'
9 compare_output "echo single arg" 'echo hello'
10 compare_output "echo preserves quotes in args" 'echo "hello world"'
11 compare_output "echo multiple quoted args" 'echo "hello" "world"'
12 compare_output "echo with special characters" 'echo "hello*world"'
13 compare_output "echo empty string" 'echo ""'
14
15 section "2. echo flags"
16 compare_output "echo -n suppresses newline" 'echo -n hello'
17 compare_output "echo -n with multiple args" 'echo -n hello world'
18 compare_output "echo -e interprets backslash-n" 'echo -e "hello\nworld"'
19 compare_output "echo -e interprets backslash-t" 'echo -e "hello\tworld"'
20 compare_output "echo -e interprets double backslash" 'echo -e "back\\\\slash"'
21 compare_output "echo -e interprets backslash-a and backslash-b" 'echo -e "x\b\ay"'
22 compare_output "echo -E disables escape interpretation" 'echo -E "hello\nworld"'
23 compare_output "echo -en combines flags" 'echo -en "hello\nworld"'
24 compare_output "echo -ne combines flags reversed" 'echo -ne "hello\tworld"'
25
26 section "3. echo edge cases"
27 compare_output "echo dash-dash is literal" 'echo -- hello'
28 compare_output "echo treats unknown flag as text" 'echo -z hello'
29 compare_output "echo -e with \\c truncates" 'echo -e "hello\cworld"'
30 compare_output "echo -e with \\0NNN octal" 'echo -e "\0101"'
31 compare_output "echo -e with \\xNN hex" 'echo -e "\x41"'
32 compare_output "echo preserves trailing spaces in quotes" 'echo "hello "'
33
34 print_summary