Mercurial > hg > toybox
comparison tests/printf.test @ 1648:d27136a0811b draft
Since "printf" is a shell builtin, printf.test wasn't actually testing anything.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 06 Jan 2015 15:06:51 -0600 |
parents | 35c035b7e3e0 |
children | 66bb2847993d |
comparison
equal
deleted
inserted
replaced
1647:35c035b7e3e0 | 1648:d27136a0811b |
---|---|
5 | 5 |
6 [ -f testing.sh ] && . testing.sh | 6 [ -f testing.sh ] && . testing.sh |
7 | 7 |
8 #testing "name" "command" "result" "infile" "stdin" | 8 #testing "name" "command" "result" "infile" "stdin" |
9 | 9 |
10 testing "" "printf TEXT" "TEXT" "" "" | 10 # Disable shell builtin |
11 testing "printf escapes" "printf 'one\ntwo\n\v\t\r\f\e\b\athree'" \ | 11 PRINTF="$(which printf)" |
12 | |
13 testing "printf text" "$PRINTF TEXT" "TEXT" "" "" | |
14 testing "printf escapes" "$PRINTF 'one\ntwo\n\v\t\r\f\e\b\athree'" \ | |
12 "one\ntwo\n\v\t\r\f\e\b\athree" "" "" | 15 "one\ntwo\n\v\t\r\f\e\b\athree" "" "" |
13 testing "printf %b escapes" "printf %b 'one\ntwo\n\v\t\r\f\e\b\athree'" \ | 16 testing "printf %b escapes" "$PRINTF %b 'one\ntwo\n\v\t\r\f\e\b\athree'" \ |
14 "one\ntwo\n\v\t\r\f\e\b\athree" "" "" | 17 "one\ntwo\n\v\t\r\f\e\b\athree" "" "" |
15 testing "printf null" "printf 'x\0y' | od -An -tx1" ' 78 00 79\n' "" "" | 18 testing "printf null" "$PRINTF 'x\0y' | od -An -tx1" ' 78 00 79\n' "" "" |
16 testing "printf trailing slash" "printf 'abc\'" 'abc\' "" "" | 19 testing "printf trailing slash" "$PRINTF 'abc\'" 'abc\' "" "" |
17 testing "printf octal" "printf ' \1\002\429\045x'" ' \001\002"9%x' "" "" | 20 testing "printf octal" "$PRINTF ' \1\002\429\045x'" ' \001\002"9%x' "" "" |
18 testing "printf not octal" "printf '\9'" '\9' "" "" | 21 testing "printf not octal" "$PRINTF '\9'" '\9' "" "" |
19 testing "printf hex" "printf 'A\x1b\x2B\x3Q\xa' | od -An -tx1" \ | 22 testing "printf hex" "$PRINTF 'A\x1b\x2B\x3Q\xa' | od -An -tx1" \ |
20 ' 41 1b 2b 03 51 0a\n' "" "" | 23 ' 41 1b 2b 03 51 0a\n' "" "" |
21 testing "" "printf '%x\\n' 0x2a" "2a\n" "" "" | 24 testing "printf " "$PRINTF '%x\n' 0x2a" "2a\n" "" "" |
22 | 25 |
23 testing "" "printf %d 42" "42" "" "" | 26 testing "printf %d 42" "$PRINTF %d 42" "42" "" "" |
24 testing "" "printf %d 0x2a" "42" "" "" | 27 testing "printf %d 0x2a" "$PRINTF %d 0x2a" "42" "" "" |
25 testing "" "printf %d 052" "42" "" "" | 28 testing "printf %d 052" "$PRINTF %d 052" "42" "" "" |
29 | |
30 testing "printf %s width precision" \ | |
31 "$PRINTF '%3s,%.3s,%10s,%10.3s' abcde fghij klmno pqrst" \ | |
32 "abcde,fgh, klmno, pqr" "" "" | |
26 | 33 |
27 testing "printf '%5d%4d' 1 21 321 4321 54321" \ | 34 testing "printf '%5d%4d' 1 21 321 4321 54321" \ |
28 "printf '%5d%4d' 1 21 321 4321 54321" " 1 21 321432154321 0" "" "" | 35 "$PRINTF '%5d%4d' 1 21 321 4321 54321" " 1 21 321432154321 0" "" "" |
29 testing "printf '%c %c' 78 79" "printf '%c %c' 78 79" "7 7" "" "" | 36 testing "printf '%c %c' 78 79" "$PRINTF '%c %c' 78 79" "7 7" "" "" |
30 testing "printf '%d %d' 78 79" "printf '%d %d' 78 79" "78 79" "" "" | 37 testing "printf '%d %d' 78 79" "$PRINTF '%d %d' 78 79" "78 79" "" "" |
31 testing "printf '%f %f' 78 79" "printf '%f %f' 78 79" \ | 38 testing "printf '%f %f' 78 79" "$PRINTF '%f %f' 78 79" \ |
32 "78.000000 79.000000" "" "" | 39 "78.000000 79.000000" "" "" |
33 testing "printf 'f f' 78 79" "printf 'f f' 78 79" "f f" "" "" | 40 testing "printf 'f f' 78 79" "$PRINTF 'f f' 78 79" "f f" "" "" |
34 testing "printf '%i %i' 78 79" "printf '%i %i' 78 79" "78 79" "" "" | 41 testing "printf '%i %i' 78 79" "$PRINTF '%i %i' 78 79" "78 79" "" "" |
35 testing "printf '%o %o' 78 79" "printf '%o %o' 78 79" "116 117" "" "" | 42 testing "printf '%o %o' 78 79" "$PRINTF '%o %o' 78 79" "116 117" "" "" |
36 testing "printf '%u %u' 78 79" "printf '%u %u' 78 79" "78 79" "" "" | 43 testing "printf '%u %u' 78 79" "$PRINTF '%u %u' 78 79" "78 79" "" "" |
37 testing "printf '%u %u' -1 -2" "printf '%u %u' -1 -2" \ | 44 testing "printf '%u %u' -1 -2" "$PRINTF '%u %u' -1 -2" \ |
38 "18446744073709551615 18446744073709551614" "" "" | 45 "18446744073709551615 18446744073709551614" "" "" |
39 testing "printf '%x %X' 78 79" "printf '%x %X' 78 79" "4e 4F" "" "" | 46 testing "printf '%x %X' 78 79" "$PRINTF '%x %X' 78 79" "4e 4F" "" "" |
40 testing "printf '%g %G' 78 79" "printf '%g %G' 78 79" "78 79" "" "" | 47 testing "printf '%g %G' 78 79" "$PRINTF '%g %G' 78 79" "78 79" "" "" |
41 testing "printf '%s %s' 78 79" "printf '%s %s' 78 79" "78 79" "" "" | 48 testing "printf '%s %s' 78 79" "$PRINTF '%s %s' 78 79" "78 79" "" "" |