slitaz-base-files annotate 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
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@271 11
al@271 12 title 'Available functions list:'
al@271 13
al@221 14 optlist "\
al@271 15 _ Alias for gettext function with newline. Can be used with success both instead of gettext and eval_gettext.
al@271 16 _n Alias for gettext function without newline at end.
al@271 17 _p Alias for plural gettext function.
al@221 18 get_cols Get width of current terminal emulator or console. Number in columns.
al@221 19 status Output localized short message based on the previous command exit status (0 - OK, other than 0 - error).
al@221 20 separator Line separator for full terminal width.
al@221 21 newline Produces empty line.
al@221 22 boldify Display a bold message.
al@221 23 colorize Color messages for terminal.
al@221 24 indent Jump to specified column, useful for simple tabulated lists (tables).
al@221 25 emsg All-in-one tool that contains: boldify, colorize, newline, separator and indent.
paul@224 26 check_root Check if user has root permissions (logged as root or used su for becoming root) for executing something.
al@221 27 debug Display debug info when --debug is used.
paul@224 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.
paul@224 29 Note that 'y' and 'N' can be localized and this function knows about that.
paul@224 30 log Log activities in /var/log/slitaz/libtaz.log (by default) or in specified log file.
al@221 31 optlist Sophisticated, UTF-8 friendly, function to print two-column list of options with descriptions.
al@271 32 longline Doesn't break words into two lines of terminal when displaying long messages.
al@271 33 title Print localized title.
al@271 34 footer Print footer.
al@271 35 action Print action.
al@271 36 itemize Print long line as list item, check for markers: colon (:), dash (-), and asterisk (*)."
al@271 37 separator '~'; newline
al@221 38
al@221 39
al@271 40 action 'Checking libtaz.sh: status() 0'
pankso@136 41 status
pankso@164 42
al@271 43 action 'Checking libtaz.sh: status() 1'
pankso@136 44 touch /tmp/1/2/2/4 2>/dev/null
pankso@136 45 status
pankso@164 46
al@271 47 action 'Checking libtaz.sh: boldify() '
pankso@136 48 boldify "Message"
pankso@164 49
al@271 50 action 'Checking libtaz.sh: colorize() '
meshca@175 51 echo -n $(colorize 33 "Message ")
meshca@175 52 echo -n $(colorize 35 "Message ")
meshca@175 53 colorize 36 "Message"
pankso@167 54
al@271 55 action 'Checking libtaz.sh: separator'; newline
pankso@136 56 separator
al@193 57
al@271 58 action 'Checking libtaz.sh: emsg() '
al@271 59 emsg '<b>bold</b> color: <c 31>bold red</c> <c 32>bold green</c> separator:<->newline:<n> message with<i 26>indent'
al@271 60
al@271 61 itemize "Fish: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed\
al@271 62 do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad mini\
al@271 63 m veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commo\
al@271 64 do consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse ci\
al@271 65 llum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non pro\
al@271 66 ident, sunt in culpa qui officia deserunt mollit anim id est laborum."
al@271 67
al@271 68 newline
al@271 69
al@271 70 itemize " * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed d\
al@271 71 o eiusmod tempor incididunt ut labore et dolore magna aliqua."
al@271 72 itemize " * Ut enim ad minim veniam, quis nostrud exercitation ullamco lab\
al@271 73 oris nisi ut aliquip ex ea commodo consequat."
al@271 74 itemize " * Duis aute irure dolor in reprehenderit in voluptate velit esse\
al@271 75 cillum dolore eu fugiat nulla pariatur."
al@271 76 itemize " * Excepteur sint occaecat cupidatat non proident, sunt in culpa \
al@271 77 qui officia deserunt mollit anim id est laborum."
al@271 78
al@271 79
al@271 80 newline; echo 'Using itemize() in the tazpkg:'
al@271 81 tazpkg info gtk+
pankso@136 82 }
pankso@125 83
pankso@170 84 # Usage: check_functions path/to/lib.sh
pankso@170 85 check_functions() {
al@271 86 lib="$1"
pankso@170 87 echo -n "$(boldify "Checking: $(basename $lib) functions")"
al@271 88 indent 34 "$(colorize 32 $(grep "[a-z_]() {" $lib | wc -l))"
pankso@170 89 separator
al@271 90 grep "[a-z_]() *{" $lib | while read line; do
al@271 91 func=`echo "$line" | cut -d'(' -f1`
al@271 92 count='0'
al@271 93 usage='0'
pankso@170 94 for tool in /usr/bin/cook* /usr/bin/taz* /usr/bin/spk* /usr/sbin/spk* \
al@221 95 /sbin/taz* /sbin/hwsetup /var/www/cgi-bin/* /var/www/cooker/*.cgi \
al@221 96 /var/www/tazpanel/*.cgi
pankso@170 97 do
pankso@170 98 [ -x "$tool" ] || continue
al@271 99 count=$(grep "$func[^a-z]" $tool | wc -l)
pankso@170 100 usage=$(($usage + $count))
pankso@170 101 done
al@271 102 printf '%-34s%4d\n' "Checking: ${func}()" "$usage"
pankso@170 103 done
pankso@170 104 separator
pankso@170 105 }
pankso@170 106
pankso@170 107 #clear
al@271 108 action 'Checking libtaz.sh: log()'
al@271 109 activity='/tmp/testsuite.log'
al@271 110 log 'Message from SliTaz testsuite'
pankso@164 111 status
pankso@164 112 cat $activity
pankso@164 113 rm -f $activity
pankso@164 114
pankso@136 115 check_libtaz
al@271 116 output='raw'
al@271 117 title 'Checking libtaz.sh: --output=raw'
pankso@136 118 check_libtaz
pankso@125 119
pankso@170 120 # Check libtaz.sh functions usage
al@271 121 output='term'
pankso@170 122 check_functions 'rootfs/lib/libtaz.sh'
pankso@170 123
pankso@170 124 # Check libpkg.sh functions usage
pankso@170 125 check_functions 'rootfs/usr/lib/slitaz/libpkg.sh'
pankso@170 126
al@271 127 [ -n "$forced" ] && echo "Checking option: forced=$forced"
al@271 128 [ -n "$root" ] && echo "Checking option: root=$root"
al@271 129 [ -z "$1" ] && echo "Check options: $(basename $0) --forced --root=/dev/null"
pankso@125 130 exit 0