Print this page
XXX Remove nawk(1)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libshell/common/tests/sun_solaris_builtin_sum.sh
+++ new/usr/src/lib/libshell/common/tests/sun_solaris_builtin_sum.sh
1 1 #
2 2 # CDDL HEADER START
3 3 #
4 4 # The contents of this file are subject to the terms of the
5 5 # Common Development and Distribution License (the "License").
6 6 # You may not use this file except in compliance with the License.
7 7 #
8 8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 # or http://www.opensolaris.org/os/licensing.
10 10 # See the License for the specific language governing permissions
11 11 # and limitations under the License.
12 12 #
13 13 # When distributing Covered Code, include this CDDL HEADER in each
14 14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 # If applicable, add the following below this CDDL HEADER, with the
16 16 # fields enclosed by brackets "[]" replaced with your own identifying
17 17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 18 #
19 19 # CDDL HEADER END
20 20 #
21 21
22 22 #
23 23 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 #
25 25
26 26 #
27 27 # Test whether the ksh93/libcmd sum builtin is compatible to
28 28 # Solaris/SystemV /usr/bin/sum
29 29 #
30 30
31 31 # test setup
32 32 function err_exit
33 33 {
34 34 print -u2 -n "\t"
35 35 print -u2 -r ${Command}[$1]: "${@:2}"
36 36 (( Errors < 127 && Errors++ ))
37 37 }
38 38 alias err_exit='err_exit $LINENO'
39 39
40 40 set -o nounset
41 41 Command=${0##*/}
42 42 integer Errors=0
43 43
44 44
45 45 typeset x
46 46
47 47 builtin sum || err_exit "sum builtin not found"
48 48
49 49 # Basic tests
50 50 x="$(print 'hello' | /usr/bin/sum)" || err_exit "/usr/bin/sum pipe failed."
51 51 [[ "$x" == "542 1" ]] || err_exit "print 'hello' | /usr/bin/sum did not return 542 1, got $x"
52 52 x="$(print 'hello' | sum)" || err_exit "sum builtin pipe failed."
53 53 [[ "$x" == "542 1" ]] || err_exit "print 'hello' | sum builtin did not return 542 1, got $x"
54 54 x="$(print 'hello' | sum -x md5)" || err_exit "sum md5 builtin pipe failed."
55 55 [[ "$x" == "b1946ac92492d2347c6235b4d2611184" ]] || err_exit "print 'hello' | sum md5 builtin did not return b1946ac92492d2347c6235b4d2611184, got $x"
56 56 x="$(print 'hello' | sum -x sha1)" || err_exit "sum sha1 builtin pipe failed."
57 57 [[ "$x" == "f572d396fae9206628714fb2ce00f72e94f2258f" ]] || err_exit "print 'hello' | sum sha1 builtin did not return f572d396fae9206628714fb2ce00f72e94f2258f, got $x"
58 58 x="$(print 'hello' | sum -x sha256)" || err_exit "sum sha256 builtin pipe failed."
59 59 [[ "$x" == "5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03" ]] || err_exit "print 'hello' | sum sha256 builtin did not return 5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03, got $x"
60 60 x="$(print 'hello' | sum -x sha512)" || err_exit "sum sha512 builtin pipe failed."
61 61 [[ "$x" == "e7c22b994c59d9cf2b48e549b1e24666636045930d3da7c1acb299d1c3b7f931f94aae41edda2c2b207a36e10f8bcb8d45223e54878f5b316e7ce3b6bc019629" ]] || err_exit "print 'hello' | sum sha512 builtin did not return e7c22b994c59d9cf2b48e549b1e24666636045930d3da7c1acb299d1c3b7f931f94aae41edda2c2b207a36e10f8bcb8d45223e54878f5b316e7ce3b6bc019629, got $x"
62 62 # note that Solaris /usr/bin/cksum outputs $'3015617425\t6' (which may be a bug in Solaris /usr/bin/cksum)
63 63 x="$(print 'hello' | sum -x cksum)" || err_exit "sum cksum builtin pipe failed."
64 64 [[ "$x" == $'3015617425 6' ]] || err_exit "print 'hello' | sum cksum builtin did not return \$'3015617425 6', got $(printf "%q\n" "$x")"
65 65
66 66 [[ "$(print 'hello' | /usr/bin/sum)" == "$(print 'hello' | sum)" ]] || err_exit "sum hello != /usr/bin/sum hello"
67 67 [[ "$(print 'fish' | /usr/bin/sum)" == "$(print 'fish' | sum)" ]] || err_exit "sum fish != /usr/bin/sum fish"
68 68 [[ "$(print '12345' | /usr/bin/sum)" == "$(print '12345' | sum)" ]] || err_exit "sum 12345 != /usr/bin/sum 12345"
69 69 [[ "$(print '\n\r\n \v' | /usr/bin/sum)" == "$(print '\n\r\n \v' | sum)" ]] || err_exit "sum spaces != /usr/bin/sum spaces"
70 70
71 71 # Test some binary files...
72 72 x="/usr/bin/ls"
73 73 [[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]] || err_exit "pipe: /usr/bin/sum $x != sum $x"
74 74 [[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]] || err_exit "file: /usr/bin/sum $x != sum $x"
75 75
76 76 x="/usr/bin/chmod"
77 77 [[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]] || err_exit "pipe: /usr/bin/sum $x != sum $x"
78 78 [[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]] || err_exit "file: /usr/bin/sum $x != sum $x"
79 79
80 80 x="/usr/bin/tee"
81 81 [[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]] || err_exit "pipe: /usr/bin/sum $x != sum $x"
82 82 [[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]] || err_exit "file: /usr/bin/sum $x != sum $x"
83 83
84 84 x="/usr/bin/grep"
85 85 [[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]] || err_exit "pipe: /usr/bin/sum $x != sum $x"
↓ open down ↓ |
85 lines elided |
↑ open up ↑ |
86 86 [[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]] || err_exit "file: /usr/bin/sum $x != sum $x"
87 87
88 88 x="/usr/bin/egrep"
89 89 [[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]] || err_exit "pipe: /usr/bin/sum $x != sum $x"
90 90 [[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]] || err_exit "file: /usr/bin/sum $x != sum $x"
91 91
92 92 x="/usr/bin/awk"
93 93 [[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]] || err_exit "pipe: /usr/bin/sum $x != sum $x"
94 94 [[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]] || err_exit "file: /usr/bin/sum $x != sum $x"
95 95
96 -x="/usr/bin/nawk"
96 +x="/usr/xpg4/bin/awk"
97 97 [[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]] || err_exit "pipe: /usr/bin/sum $x != sum $x"
98 98 [[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]] || err_exit "file: /usr/bin/sum $x != sum $x"
99 99
100 100 x="/usr/bin/ksh"
101 101 [[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]] || err_exit "pipe: /usr/bin/sum $x != sum $x"
102 102 [[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]] || err_exit "file: /usr/bin/sum $x != sum $x"
103 103
104 104 x="/usr/bin/sh"
105 105 [[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]] || err_exit "pipe: /usr/bin/sum $x != sum $x"
106 106 [[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]] || err_exit "file: /usr/bin/sum $x != sum $x"
107 107
108 108
109 109 # tests done
110 110 exit $((Errors))
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX