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

libtaz.sh: add _p(), title(), footer(), action(), itemize(); update doc/libtaz.sh and testsuite.sh
author Aleksej Bobylev <al.bobylev@gmail.com>
date Mon May 25 19:32:59 2015 +0300 (2015-05-25)
parents 7626b79a1b31
children 3a790a182103
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+
82 }
84 # Usage: check_functions path/to/lib.sh
85 check_functions() {
86 lib="$1"
87 echo -n "$(boldify "Checking: $(basename $lib) functions")"
88 indent 34 "$(colorize 32 $(grep "[a-z_]() {" $lib | wc -l))"
89 separator
90 grep "[a-z_]() *{" $lib | while read line; do
91 func=`echo "$line" | cut -d'(' -f1`
92 count='0'
93 usage='0'
94 for tool in /usr/bin/cook* /usr/bin/taz* /usr/bin/spk* /usr/sbin/spk* \
95 /sbin/taz* /sbin/hwsetup /var/www/cgi-bin/* /var/www/cooker/*.cgi \
96 /var/www/tazpanel/*.cgi
97 do
98 [ -x "$tool" ] || continue
99 count=$(grep "$func[^a-z]" $tool | wc -l)
100 usage=$(($usage + $count))
101 done
102 printf '%-34s%4d\n' "Checking: ${func}()" "$usage"
103 done
104 separator
105 }
107 #clear
108 action 'Checking libtaz.sh: log()'
109 activity='/tmp/testsuite.log'
110 log 'Message from SliTaz testsuite'
111 status
112 cat $activity
113 rm -f $activity
115 check_libtaz
116 output='raw'
117 title 'Checking libtaz.sh: --output=raw'
118 check_libtaz
120 # Check libtaz.sh functions usage
121 output='term'
122 check_functions 'rootfs/lib/libtaz.sh'
124 # Check libpkg.sh functions usage
125 check_functions 'rootfs/usr/lib/slitaz/libpkg.sh'
127 [ -n "$forced" ] && echo "Checking option: forced=$forced"
128 [ -n "$root" ] && echo "Checking option: root=$root"
129 [ -z "$1" ] && echo "Check options: $(basename $0) --forced --root=/dev/null"
130 exit 0