slitaz-base-files annotate 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
rev   line source
pankso@125 1 #!/bin/sh
pankso@125 2 #
pankso@125 3 . rootfs/lib/libtaz.sh
pankso@125 4
pankso@136 5 check_libtaz() {
al@221 6 newline; longline "This package provides the base system files and \
al@221 7 directories, it is built using a wok receipt and Cookutils. The creation of \
al@221 8 the initial files are described in the SliTaz Scratchbook: http://www.slitaz.\
al@221 9 org/en/doc/scratchbook/"
al@221 10
al@221 11 newline; boldify Available functions list:
al@221 12 separator
al@221 13 optlist "\
al@221 14 _ Alias for eval_gettext with newline. Can be used with success both instead of gettext and eval_gettext.
al@221 15 _n Alias for eval_gettext without newline at end.
al@221 16 get_cols Get width of current terminal emulator or console. Number in columns.
al@221 17 status Output localized short message based on the previous command exit status (0 - OK, other than 0 - error).
al@221 18 separator Line separator for full terminal width.
al@221 19 newline Produces empty line.
al@221 20 boldify Display a bold message.
al@221 21 colorize Color messages for terminal.
al@221 22 indent Jump to specified column, useful for simple tabulated lists (tables).
al@221 23 emsg All-in-one tool that contains: boldify, colorize, newline, separator and indent.
al@221 24 check_root Check if user have root permissions (logged as root or used su for become root) for execute something.
al@221 25 debug Display debug info when --debug is used.
al@221 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.
al@221 27 log Log activities in /var/log/slitaz/libtaz.log (by default) or in specified log file.
al@221 28 optlist Sophisticated, UTF-8 friendly, function to print two-column list of options with descriptions.
al@221 29 longline Not break words into two lines of terminal when display long messages."
al@221 30 separator; newline
al@221 31
al@221 32
pankso@136 33 echo -n "Checking libtaz.sh: status() 0"
pankso@136 34 status
pankso@164 35
pankso@136 36 echo -n "Checking libtaz.sh: status() 1"
pankso@136 37 touch /tmp/1/2/2/4 2>/dev/null
pankso@136 38 status
pankso@164 39
pankso@136 40 echo -n "Checking libtaz.sh: boldify() "
pankso@136 41 boldify "Message"
pankso@164 42
pankso@167 43 echo -n "Checking libtaz.sh: colorize() "
meshca@175 44 echo -n $(colorize 33 "Message ")
meshca@175 45 echo -n $(colorize 35 "Message ")
meshca@175 46 colorize 36 "Message"
pankso@167 47
pankso@136 48 echo "Checking libtaz.sh: separator"
pankso@136 49 separator
al@193 50
al@193 51 echo -n "Checking libtaz.sh: emsg() "
al@193 52 emsg "<b>bold</b> color: <c 31>bold red</c> <c 32>bold green</c> separator:<->newline:<n> message with<i 26>indent"
pankso@136 53 }
pankso@125 54
pankso@170 55 # Usage: check_functions path/to/lib.sh
pankso@170 56 check_functions() {
pankso@170 57 lib=$1
pankso@170 58 echo -n "$(boldify "Checking: $(basename $lib) functions")"
meshca@176 59 indent 34 "$(colorize 32 $(grep "[a-z]() {" $lib | wc -l))"
pankso@170 60 separator
pankso@170 61 grep "[a-z]() {" $lib | while read line
pankso@170 62 do
pankso@170 63 func=`echo "$line" | cut -d '(' -f 1`
pankso@170 64 count=0
pankso@170 65 usage=0
pankso@170 66 echo -n "Checking: ${func}()"
pankso@170 67 for tool in /usr/bin/cook* /usr/bin/taz* /usr/bin/spk* /usr/sbin/spk* \
al@221 68 /sbin/taz* /sbin/hwsetup /var/www/cgi-bin/* /var/www/cooker/*.cgi \
al@221 69 /var/www/tazpanel/*.cgi
pankso@170 70 do
pankso@170 71 [ -x "$tool" ] || continue
pankso@170 72 count=$(grep "$func" $tool | wc -l)
pankso@170 73 usage=$(($usage + $count))
pankso@170 74 done
pankso@170 75 indent 34 "$usage"
pankso@170 76 done
pankso@170 77 separator
pankso@170 78 }
pankso@170 79
pankso@170 80 #clear
pankso@164 81 echo -n "Checking libtaz.sh: log()"
pankso@164 82 activity=/tmp/testsuite.log
pankso@164 83 log "Message from SliTaz testsuite"
pankso@164 84 status
pankso@164 85 cat $activity
pankso@164 86 rm -f $activity
pankso@164 87
pankso@136 88 check_libtaz
pankso@136 89 output="raw"
al@193 90 echo -e "\nChecking libtaz.sh: --output=raw"
pankso@136 91 check_libtaz
pankso@125 92
pankso@170 93 # Check libtaz.sh functions usage
pankso@170 94 output="term"
pankso@170 95 check_functions 'rootfs/lib/libtaz.sh'
pankso@170 96
pankso@170 97 # Check libpkg.sh functions usage
pankso@170 98 check_functions 'rootfs/usr/lib/slitaz/libpkg.sh'
pankso@170 99
pankso@137 100 [ "$forced" ] && echo "Checking option: forced=$forced"
pankso@137 101 [ "$root" ] && echo "Checking option: root=$root"
pankso@137 102 [ ! "$1" ] && echo "Check options: $(basename $0) --forced --root=/dev/null"
pankso@125 103 exit 0