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

libtaz.sh: add new functions - optlist and longline
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Aug 24 14:48:45 2013 +0300 (2013-08-24)
parents d4df77afbed6
children 7626b79a1b31
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/"
11 newline; boldify Available functions list:
12 separator
13 optlist "\
14 _ Alias for eval_gettext with newline. Can be used with success both instead of gettext and eval_gettext.
15 _n Alias for eval_gettext without newline at end.
16 get_cols Get width of current terminal emulator or console. Number in columns.
17 status Output localized short message based on the previous command exit status (0 - OK, other than 0 - error).
18 separator Line separator for full terminal width.
19 newline Produces empty line.
20 boldify Display a bold message.
21 colorize Color messages for terminal.
22 indent Jump to specified column, useful for simple tabulated lists (tables).
23 emsg All-in-one tool that contains: boldify, colorize, newline, separator and indent.
24 check_root Check if user have root permissions (logged as root or used su for become root) for execute something.
25 debug Display debug info when --debug is used.
26 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. Note that 'y' and 'N' can be localized and this function know about that.
27 log Log activities in /var/log/slitaz/libtaz.log (by default) or in specified log file.
28 optlist Sophisticated, UTF-8 friendly, function to print two-column list of options with descriptions.
29 longline Not break words into two lines of terminal when display long messages."
30 separator; newline
33 echo -n "Checking libtaz.sh: status() 0"
34 status
36 echo -n "Checking libtaz.sh: status() 1"
37 touch /tmp/1/2/2/4 2>/dev/null
38 status
40 echo -n "Checking libtaz.sh: boldify() "
41 boldify "Message"
43 echo -n "Checking libtaz.sh: colorize() "
44 echo -n $(colorize 33 "Message ")
45 echo -n $(colorize 35 "Message ")
46 colorize 36 "Message"
48 echo "Checking libtaz.sh: separator"
49 separator
51 echo -n "Checking libtaz.sh: emsg() "
52 emsg "<b>bold</b> color: <c 31>bold red</c> <c 32>bold green</c> separator:<->newline:<n> message with<i 26>indent"
53 }
55 # Usage: check_functions path/to/lib.sh
56 check_functions() {
57 lib=$1
58 echo -n "$(boldify "Checking: $(basename $lib) functions")"
59 indent 34 "$(colorize 32 $(grep "[a-z]() {" $lib | wc -l))"
60 separator
61 grep "[a-z]() {" $lib | while read line
62 do
63 func=`echo "$line" | cut -d '(' -f 1`
64 count=0
65 usage=0
66 echo -n "Checking: ${func}()"
67 for tool in /usr/bin/cook* /usr/bin/taz* /usr/bin/spk* /usr/sbin/spk* \
68 /sbin/taz* /sbin/hwsetup /var/www/cgi-bin/* /var/www/cooker/*.cgi \
69 /var/www/tazpanel/*.cgi
70 do
71 [ -x "$tool" ] || continue
72 count=$(grep "$func" $tool | wc -l)
73 usage=$(($usage + $count))
74 done
75 indent 34 "$usage"
76 done
77 separator
78 }
80 #clear
81 echo -n "Checking libtaz.sh: log()"
82 activity=/tmp/testsuite.log
83 log "Message from SliTaz testsuite"
84 status
85 cat $activity
86 rm -f $activity
88 check_libtaz
89 output="raw"
90 echo -e "\nChecking libtaz.sh: --output=raw"
91 check_libtaz
93 # Check libtaz.sh functions usage
94 output="term"
95 check_functions 'rootfs/lib/libtaz.sh'
97 # Check libpkg.sh functions usage
98 check_functions 'rootfs/usr/lib/slitaz/libpkg.sh'
100 [ "$forced" ] && echo "Checking option: forced=$forced"
101 [ "$root" ] && echo "Checking option: root=$root"
102 [ ! "$1" ] && echo "Check options: $(basename $0) --forced --root=/dev/null"
103 exit 0