-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_echo.sh
More file actions
executable file
·39 lines (31 loc) · 1.03 KB
/
Copy pathtest_echo.sh
File metadata and controls
executable file
·39 lines (31 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
set -euo pipefail
source "$(dirname "$0")/helpers.sh"
pass=0 fail=0
run_test() {
local name="$1"; shift
local expected="$1"; shift
local actual
actual=$("$CFBOX" echo "$@")
if [[ "$expected" == "$actual" ]]; then
((++pass))
else
echo "FAIL [$name]: expected=$(printf '%q' "$expected") actual=$(printf '%q' "$actual")"
((++fail))
fi
}
# basic output
run_test "basic" "hello world" hello world
# -n no trailing newline (capture shows no trailing \n)
actual=$("$CFBOX" echo -n hello; echo "X")
if [[ "$actual" == "helloX" ]]; then ((++pass)); else echo "FAIL [-n]: got $(printf '%q' "$actual")"; ((++fail)); fi
# -e escape sequences
run_test "escape_tab" $'hello\tworld' -e 'hello\tworld'
run_test "escape_newline" $'hello\nworld' -e 'hello\nworld'
run_test "escape_backslash" $'hello\world' -e 'hello\\world'
# empty args
run_test "empty" "" ""
# -- stops option parsing
run_test "doubledash" "-n hello" -- -n hello
echo "echo: $pass passed, $fail failed"
[[ $fail -eq 0 ]]