slitaz-base-files view testsuite.sh @ rev 296

man: no choice if only one matching section
author Lucas Levrel <llevrel@yahoo.fr>
date Sat Jan 16 19:08:30 2016 +0100 (2016-01-16)
parents 3a790a182103
children 65248d132cd2
line source
1 #!/bin/sh
2 #
3 . rootfs/lib/libtaz.sh
5 check_libtaz() {
6 newline; longline "This package provides the base system files and \
7 directories, it is built using a wok receipt and Cookutils. The creation of \
8 the initial files are described in the SliTaz Scratchbook: http://www.slitaz.\
9 org/en/doc/scratchbook/"
12 title 'Available functions list:'
14 optlist "\
15 _ Alias for gettext function with newline. Can be used with success both instead of gettext and eval_gettext.
16 _n Alias for gettext function without newline at end.
17 _p Alias for plural gettext function.
18 get_cols Get width of current terminal emulator or console. Number in columns.
19 status Output localized short message based on the previous command exit status (0 - OK, other than 0 - error).
20 separator Line separator for full terminal width.
21 newline Produces empty line.
22 boldify Display a bold message.
23 colorize Color messages for terminal.
24 indent Jump to specified column, useful for simple tabulated lists (tables).
25 emsg All-in-one tool that contains: boldify, colorize, newline, separator and indent.
26 check_root Check if user has root permissions (logged as root or used su for becoming root) for executing something.
27 debug Display debug info when --debug is used.
28 confirm Used at end of questions - adds '(y/N)?' and waits for answer. Press 'y' if yes, any other letters/words or just Enter - if no.
29 Note that 'y' and 'N' can be localized and this function knows about that.
30 log Log activities in /var/log/slitaz/libtaz.log (by default) or in specified log file.
31 optlist Sophisticated, UTF-8 friendly, function to print two-column list of options with descriptions.
32 longline Doesn't break words into two lines of terminal when displaying long messages.
33 title Print localized title.
34 footer Print footer.
35 action Print action.
36 itemize Print long line as list item, check for markers: colon (:), dash (-), and asterisk (*)."
37 separator '~'; newline
40 action 'Checking libtaz.sh: status() 0'
41 status
43 action 'Checking libtaz.sh: status() 1'
44 touch /tmp/1/2/2/4 2>/dev/null
45 status
47 action 'Checking libtaz.sh: boldify() '
48 boldify "Message"
50 action 'Checking libtaz.sh: colorize() '
51 echo -n $(colorize 33 "Message ")
52 echo -n $(colorize 35 "Message ")
53 colorize 36 "Message"
55 action 'Checking libtaz.sh: separator'; newline
56 separator
58 action 'Checking libtaz.sh: emsg() '
59 emsg '<b>bold</b> color: <c 31>bold red</c> <c 32>bold green</c> separator:<->newline:<n> message with<i 26>indent'
61 itemize "Fish: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed\
62 do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad mini\
63 m veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commo\
64 do consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse ci\
65 llum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non pro\
66 ident, sunt in culpa qui officia deserunt mollit anim id est laborum."
68 newline
70 itemize " * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed d\
71 o eiusmod tempor incididunt ut labore et dolore magna aliqua."
72 itemize " * Ut enim ad minim veniam, quis nostrud exercitation ullamco lab\
73 oris nisi ut aliquip ex ea commodo consequat."
74 itemize " * Duis aute irure dolor in reprehenderit in voluptate velit esse\
75 cillum dolore eu fugiat nulla pariatur."
76 itemize " * Excepteur sint occaecat cupidatat non proident, sunt in culpa \
77 qui officia deserunt mollit anim id est laborum."
80 newline; echo 'Using itemize() in the tazpkg:'
81 tazpkg info gtk+
83 title "$(emsg '<c 31>C<c 32>o<c 33>l<c 34>o<c 35>r<c 36>s</c>')"
84 for i in $(seq 0 7); do
85 case $i in
86 0) c='Gray ';;
87 1) c='Red ';;
88 2) c='Green ';;
89 3) c='Yellow ';;
90 4) c='Blue ';;
91 5) c='Magenta';;
92 6) c='Cyan ';;
93 7) c='White ';;
94 esac
95 echo -n "$c "
96 echo -n "$(colorize "03$i" "03$i") $(colorize "3$i" "3$i") " # test `colorize`: fg
97 echo -n "$(colorize "04$i" "04$i") $(colorize "4$i" "4$i") " # test `colorize`: bg
98 echo -n ": "
99 emsg "<c 03$i>03$i $c</c> <c 3$i>3$i Bold $c</c> <c 04$i>04$i $c</c> <c 4$i>4$i Bold $c</c>" # test `emsg`
100 done
101 }
103 # Usage: check_functions path/to/lib.sh
104 check_functions() {
105 lib="$1"
106 echo -n "$(boldify "Checking: $(basename $lib) functions")"
107 indent 34 "$(colorize 32 $(grep "[a-z_]() {" $lib | wc -l))"
108 separator
109 grep "[a-z_]() *{" $lib | while read line; do
110 func=`echo "$line" | cut -d'(' -f1`
111 count='0'
112 usage='0'
113 for tool in /usr/bin/cook* /usr/bin/taz* /usr/bin/spk* /usr/sbin/spk* \
114 /sbin/taz* /sbin/hwsetup /var/www/cgi-bin/* /var/www/cooker/*.cgi \
115 /var/www/tazpanel/*.cgi
116 do
117 [ -x "$tool" ] || continue
118 count=$(grep "$func[^a-z]" $tool | wc -l)
119 usage=$(($usage + $count))
120 done
121 printf '%-34s%4d\n' "Checking: ${func}()" "$usage"
122 done
123 separator
124 }
126 #clear
127 action 'Checking libtaz.sh: log()'
128 activity='/tmp/testsuite.log'
129 log 'Message from SliTaz testsuite'
130 status
131 cat $activity
132 rm -f $activity
134 for output in '' raw gtk html; do
135 export output
136 newline; newline
137 title 'Checking libtaz.sh: --output=$output'
138 check_libtaz
139 done
141 # Check libtaz.sh functions usage
142 output='term'
143 check_functions 'rootfs/lib/libtaz.sh'
145 # Check libpkg.sh functions usage
146 check_functions 'rootfs/usr/lib/slitaz/libpkg.sh'
148 [ -n "$forced" ] && echo "Checking option: forced=$forced"
149 [ -n "$root" ] && echo "Checking option: root=$root"
150 [ -z "$1" ] && echo "Check options: $(basename $0) --forced --root=/dev/null"
151 exit 0