slitaz-base-files diff 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 diff
     1.1 --- a/testsuite.sh	Sat Sep 07 02:20:23 2013 +0100
     1.2 +++ b/testsuite.sh	Mon May 25 19:32:59 2015 +0300
     1.3 @@ -8,11 +8,13 @@
     1.4  the initial files are described in the SliTaz Scratchbook: http://www.slitaz.\
     1.5  org/en/doc/scratchbook/"
     1.6  
     1.7 -	newline; boldify Available functions list:
     1.8 -	separator
     1.9 +
    1.10 +	title 'Available functions list:'
    1.11 +
    1.12  	optlist "\
    1.13 -_		Alias for eval_gettext with newline. Can be used with success both instead of gettext and eval_gettext.
    1.14 -_n		Alias for eval_gettext without newline at end.
    1.15 +_		Alias for gettext function with newline. Can be used with success both instead of gettext and eval_gettext.
    1.16 +_n		Alias for gettext function without newline at end.
    1.17 +_p		Alias for plural gettext function.
    1.18  get_cols	Get width of current terminal emulator or console. Number in columns.
    1.19  status		Output localized short message based on the previous command exit status (0 - OK, other than 0 - error).
    1.20  separator	Line separator for full terminal width.
    1.21 @@ -27,78 +29,102 @@
    1.22  		Note that 'y' and 'N' can be localized and this function knows about that.
    1.23  log		Log activities in /var/log/slitaz/libtaz.log (by default) or in specified log file.
    1.24  optlist		Sophisticated, UTF-8 friendly, function to print two-column list of options with descriptions.
    1.25 -longline	Doesn't break words into two lines of terminal when displaying long messages."
    1.26 -	separator; newline
    1.27 +longline	Doesn't break words into two lines of terminal when displaying long messages.
    1.28 +title		Print localized title.
    1.29 +footer		Print footer.
    1.30 +action		Print action.
    1.31 +itemize		Print long line as list item, check for markers: colon (:), dash (-), and asterisk (*)."
    1.32 +	separator '~'; newline
    1.33  
    1.34  
    1.35 -	echo -n "Checking libtaz.sh: status() 0"
    1.36 +	action 'Checking libtaz.sh: status() 0'
    1.37  	status
    1.38  
    1.39 -	echo -n "Checking libtaz.sh: status() 1"
    1.40 +	action 'Checking libtaz.sh: status() 1'
    1.41  	touch /tmp/1/2/2/4 2>/dev/null
    1.42  	status
    1.43  
    1.44 -	echo -n "Checking libtaz.sh: boldify() "
    1.45 +	action 'Checking libtaz.sh: boldify() '
    1.46  	boldify "Message"
    1.47  
    1.48 -	echo -n "Checking libtaz.sh: colorize() "
    1.49 +	action 'Checking libtaz.sh: colorize() '
    1.50  	echo -n $(colorize 33 "Message ")
    1.51  	echo -n $(colorize 35 "Message ")
    1.52  	colorize 36 "Message"
    1.53  
    1.54 -	echo "Checking libtaz.sh: separator"
    1.55 +	action 'Checking libtaz.sh: separator'; newline
    1.56  	separator
    1.57  
    1.58 -	echo -n "Checking libtaz.sh: emsg() "
    1.59 -	emsg "<b>bold</b> color: <c 31>bold red</c> <c 32>bold green</c> separator:<->newline:<n> message with<i 26>indent"
    1.60 +	action 'Checking libtaz.sh: emsg() '
    1.61 +	emsg '<b>bold</b> color: <c 31>bold red</c> <c 32>bold green</c> separator:<->newline:<n> message with<i 26>indent'
    1.62 +
    1.63 +	itemize "Fish: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed\
    1.64 + do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad mini\
    1.65 +m veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commo\
    1.66 +do consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse ci\
    1.67 +llum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non pro\
    1.68 +ident, sunt in culpa qui officia deserunt mollit anim id est laborum."
    1.69 +
    1.70 +	newline
    1.71 +
    1.72 +	itemize "  * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed d\
    1.73 +o eiusmod tempor incididunt ut labore et dolore magna aliqua."
    1.74 +	itemize "  * Ut enim ad minim veniam, quis nostrud exercitation ullamco lab\
    1.75 +oris nisi ut aliquip ex ea commodo consequat."
    1.76 +	itemize "  * Duis aute irure dolor in reprehenderit in voluptate velit esse\
    1.77 + cillum dolore eu fugiat nulla pariatur."
    1.78 +	itemize "  * Excepteur sint occaecat cupidatat non proident, sunt in culpa \
    1.79 +qui officia deserunt mollit anim id est laborum."
    1.80 +
    1.81 +
    1.82 +	newline; echo 'Using itemize() in the tazpkg:'
    1.83 +	tazpkg info gtk+
    1.84  }
    1.85  
    1.86  # Usage: check_functions path/to/lib.sh
    1.87  check_functions() {
    1.88 -	lib=$1
    1.89 +	lib="$1"
    1.90  	echo -n "$(boldify "Checking: $(basename $lib) functions")"
    1.91 -	indent 34 "$(colorize 32 $(grep "[a-z]() {" $lib | wc -l))"
    1.92 +	indent 34 "$(colorize 32 $(grep "[a-z_]() {" $lib | wc -l))"
    1.93  	separator
    1.94 -	grep "[a-z]() {" $lib | while read line
    1.95 -	do
    1.96 -		func=`echo "$line" | cut -d '(' -f 1`
    1.97 -		count=0
    1.98 -		usage=0
    1.99 -		echo -n "Checking: ${func}()"
   1.100 +	grep "[a-z_]() *{" $lib | while read line; do
   1.101 +		func=`echo "$line" | cut -d'(' -f1`
   1.102 +		count='0'
   1.103 +		usage='0'
   1.104  		for tool in /usr/bin/cook* /usr/bin/taz* /usr/bin/spk* /usr/sbin/spk* \
   1.105  			/sbin/taz* /sbin/hwsetup /var/www/cgi-bin/* /var/www/cooker/*.cgi \
   1.106  			/var/www/tazpanel/*.cgi 
   1.107  		do
   1.108  			[ -x "$tool" ] || continue
   1.109 -			count=$(grep "$func" $tool | wc -l)
   1.110 +			count=$(grep "$func[^a-z]" $tool | wc -l)
   1.111  			usage=$(($usage + $count))
   1.112  		done
   1.113 -		indent 34 "$usage"
   1.114 +		printf '%-34s%4d\n' "Checking: ${func}()" "$usage"
   1.115  	done
   1.116  	separator
   1.117  }
   1.118  
   1.119  #clear
   1.120 -echo -n "Checking libtaz.sh: log()"
   1.121 -activity=/tmp/testsuite.log
   1.122 -log "Message from SliTaz testsuite"
   1.123 +action 'Checking libtaz.sh: log()'
   1.124 +activity='/tmp/testsuite.log'
   1.125 +log 'Message from SliTaz testsuite'
   1.126  status
   1.127  cat $activity
   1.128  rm -f $activity
   1.129  
   1.130  check_libtaz
   1.131 -output="raw"
   1.132 -echo -e "\nChecking libtaz.sh: --output=raw"
   1.133 +output='raw'
   1.134 +title 'Checking libtaz.sh: --output=raw'
   1.135  check_libtaz
   1.136  
   1.137  # Check libtaz.sh functions usage
   1.138 -output="term"
   1.139 +output='term'
   1.140  check_functions 'rootfs/lib/libtaz.sh'
   1.141  
   1.142  # Check libpkg.sh functions usage
   1.143  check_functions 'rootfs/usr/lib/slitaz/libpkg.sh'
   1.144  
   1.145 -[ "$forced" ] && echo "Checking option: forced=$forced"
   1.146 -[ "$root" ] && echo "Checking option: root=$root"
   1.147 -[ ! "$1" ] && echo "Check options: $(basename $0) --forced --root=/dev/null"
   1.148 +[ -n "$forced" ] && echo "Checking option: forced=$forced"
   1.149 +[ -n "$root" ] && echo "Checking option: root=$root"
   1.150 +[ -z "$1" ] && echo "Check options: $(basename $0) --forced --root=/dev/null"
   1.151  exit 0