tests: add test for locale decimal processing
[coreutils.git] / tests / misc / echo.sh
blob04ffc9b82e5157d5ab5fbe34bbd5d6ba3cee0f8a
1 #!/bin/sh
2 # basic tests for echo
4 # Copyright (C) 2018-2019 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 prog='env echo'
21 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
22 print_ver_ echo
25 # Verify the methods of specifying "Escape":
26 # Note 4 octal digits are allowed (unlike printf which uses up to 3)
27 printf '%s\n' . . . . . | tr . '\033' > exp
28 $prog -n -e '\x1b\n\e\n\33\n\033\n\0033\n' > out || fail=1
29 compare exp out || fail=1
31 # Incomplete hex escapes are output as is (unlike printf)
32 printf '\\x\n' > exp
33 $prog -n -e '\x\n' > out || fail=1
34 compare exp out || fail=1
36 # Always output -- (unlike printf)
37 $prog -- 'foo' > out || fail=1
38 $prog -n -e -- 'foo\n' >> out || fail=1
39 cat <<\EOF > exp
40 -- foo
41 -- foo
42 EOF
43 compare exp out || fail=1
45 # Ensure \c stops processing
46 $prog -e 'foo\n\cbar' > out || fail=1
47 printf 'foo\n' > exp
48 compare exp out || fail=1
50 # With POSIXLY_CORRECT:
51 # only -n as the first (separate) option enables option processing
52 # -E is ignored
53 # escapes are processed by default
54 POSIXLY_CORRECT=1 $prog -n -E 'foo\n' > out || fail=1
55 POSIXLY_CORRECT=1 $prog -nE 'foo' >> out || fail=1
56 POSIXLY_CORRECT=1 $prog -E -n 'foo' >> out || fail=1
57 POSIXLY_CORRECT=1 $prog --version >> out || fail=1
58 cat <<\EOF > exp
59 foo
60 -nE foo
61 -E -n foo
62 --version
63 EOF
64 compare exp out || fail=1
66 # Further test coverage.
67 # Output a literal '-' (on a line itself).
68 $prog - > out || fail=1
69 # Output a literal backslash '\', no newline.
70 $prog -n -e '\\' >> out || fail=1
71 # Output an empty line (merely to have a newline after the previous test).
72 $prog >> out || fail=1
73 # Test other characters escaped by a backslash:
74 # \a hex 07 alert, bell
75 # \b hex 08 backspace
76 # \e hex 1b escape
77 # \f hex 0c form feed
78 # \n hex 0a new line
79 # \r hex 0d carriage return
80 # \t hex 09 horizontal tab
81 # \v hex 0b vertical tab
82 # Convert output, yet checking the exit status of $prog.
83 { $prog -n -e '\a\b\e\f\n\r\t\v' || touch fail; } | od -tx1 >> out || fail=1
84 test '!' -f fail || fail=1
85 # Output hex values which contain hexadecimal characters to test hextobin().
86 # Hex values 4a through 4f are ASCII "JKLMNO".
87 $prog -n -e '\x4a\x4b\x4c\x4d\x4e\x4f\x4A\x4B\x4C\x4D\x4E\x4F' >> out || fail=1
88 # Output another newline.
89 $prog >> out || fail=1
90 cat <<\EOF > exp
93 0000000 07 08 1b 0c 0a 0d 09 0b
94 0000010
95 JKLMNOJKLMNO
96 EOF
97 compare exp out || fail=1
99 Exit $fail