tazpkg rev 884

Module 'check': fix to work with $root; start to add tests
author Aleksej Bobylev <al.bobylev@gmail.com>
date Sat Dec 05 16:14:14 2015 +0200 (2015-12-05)
parents f9b5a4545fff
children 2f3f84cea56f
files modules/check tests/test01 tests/test02 tests/test03 tests/test04 tests/test05 tests/testsuite
line diff
     1.1 --- a/modules/check	Fri Dec 04 13:19:16 2015 +0100
     1.2 +++ b/modules/check	Sat Dec 05 16:14:14 2015 +0200
     1.3 @@ -107,8 +107,8 @@
     1.4  
     1.5  	MSG="$(_n 'Files lost from package:')\n"
     1.6  	while read file; do
     1.7 -		[ -e "$file" ] && continue
     1.8 -		if [ -L "$file" ]; then
     1.9 +		[ -e "$root$file" ] && continue
    1.10 +		if [ -L "$root$file" ]; then
    1.11  			MSG="$MSG  $(_n 'target of symlink')"
    1.12  		fi
    1.13  		print_pkgname
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tests/test01	Sat Dec 05 16:14:14 2015 +0200
     2.3 @@ -0,0 +1,68 @@
     2.4 +#!/bin/sh
     2.5 +#
     2.6 +. /lib/libtaz.sh
     2.7 +check_root
     2.8 +ROOT='/tmp/test'
     2.9 +
    2.10 +title 'Test #01'
    2.11 +colorize 033 "$(longline "Check that tazpkg created all the base files and folders needed from \
    2.12 +scratch. Working in the folder $ROOT")"
    2.13 +newline
    2.14 +
    2.15 +[ -d "$ROOT" ] && rm -rf "$ROOT"
    2.16 +
    2.17 +########
    2.18 +tazpkg --root=$ROOT
    2.19 +########
    2.20 +
    2.21 +dirnum=$(find "$ROOT" -type d | wc -l)
    2.22 +if [ "$dirnum" -ne 11 ]; then
    2.23 +	colorize 35 "WARNING. Expected 11 folders; found $dirnum"
    2.24 +	WARNING=1
    2.25 +fi
    2.26 +
    2.27 +filenum=$(find "$ROOT" -type f | wc -l)
    2.28 +if [ "$filenum" -ne 21 ]; then
    2.29 +	colorize 35 "WARNING. Expected 21 files; found $filenum"
    2.30 +	WARNING=1
    2.31 +fi
    2.32 +
    2.33 +for dir in /etc/slitaz /var/cache/tazpkg /var/lib/tazpkg/installed /var/log/slitaz; do
    2.34 +	if [ ! -d "$ROOT$dir" ]; then
    2.35 +		colorize 31 "ERROR. Folder $dir absent. Exit test"
    2.36 +		exit 1
    2.37 +	fi
    2.38 +done
    2.39 +
    2.40 +for file in \
    2.41 +	/etc/slitaz-release \
    2.42 +	/etc/slitaz/slitaz.conf \
    2.43 +	/etc/slitaz/tazpkg.conf \
    2.44 +	/var/lib/tazpkg/mirrors \
    2.45 +	/var/lib/tazpkg/packages.info \
    2.46 +	/var/lib/tazpkg/descriptions.txt \
    2.47 +	/var/lib/tazpkg/packages.equiv \
    2.48 +	/var/lib/tazpkg/extra.list \
    2.49 +	/var/lib/tazpkg/packages.list \
    2.50 +	/var/lib/tazpkg/ID \
    2.51 +	/var/lib/tazpkg/files.list.lzma \
    2.52 +	/var/lib/tazpkg/files-list.md5 \
    2.53 +	/var/lib/tazpkg/packages.up \
    2.54 +	/var/lib/tazpkg/packages.txt \
    2.55 +	/var/lib/tazpkg/packages.md5 \
    2.56 +	/var/lib/tazpkg/mirror \
    2.57 +	/var/lib/tazpkg/blocked-packages.list \
    2.58 +	/var/lib/tazpkg/packages.desc \
    2.59 +	/var/lib/tazpkg/installed.info \
    2.60 +	/var/lib/tazpkg/IDs \
    2.61 +	/var/log/slitaz/tazpkg.log
    2.62 +do
    2.63 +	if [ ! -f "$ROOT$file" ]; then
    2.64 +		colorize 31 "ERROR. File $file absent. Exit test"
    2.65 +		exit 1
    2.66 +	fi
    2.67 +done
    2.68 +
    2.69 +[ -n "$WARNING" ] && warning='(with warnings)'
    2.70 +footer "$(colorize 32 "Test #01 passed $warning")"
    2.71 +exit 0
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tests/test02	Sat Dec 05 16:14:14 2015 +0200
     3.3 @@ -0,0 +1,22 @@
     3.4 +#!/bin/sh
     3.5 +#
     3.6 +. /lib/libtaz.sh
     3.7 +check_root
     3.8 +ROOT='/tmp/test'
     3.9 +
    3.10 +title 'Test #02'
    3.11 +colorize 033 "$(longline "Install package without dependencies.")"
    3.12 +newline
    3.13 +
    3.14 +########
    3.15 +tazpkg --root=$ROOT --nodeps -gi nano
    3.16 +########
    3.17 +
    3.18 +installed="$(ls $ROOT/var/lib/tazpkg/installed)"
    3.19 +if [ "$installed" != 'nano' ]; then
    3.20 +	colorize 31 "ERROR. Expected package 'nano' installed. Given: '$installed' Exit test"
    3.21 +	exit 1
    3.22 +fi
    3.23 +
    3.24 +footer "$(colorize 32 'Test #02 passed')"
    3.25 +exit 0
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tests/test03	Sat Dec 05 16:14:14 2015 +0200
     4.3 @@ -0,0 +1,23 @@
     4.4 +#!/bin/sh
     4.5 +#
     4.6 +. /lib/libtaz.sh
     4.7 +check_root
     4.8 +ROOT='/tmp/test'
     4.9 +
    4.10 +title 'Test #03'
    4.11 +colorize 033 "$(longline "Don't install already installed package without --forced option.")"
    4.12 +newline
    4.13 +
    4.14 +########
    4.15 +tazpkg --root=$ROOT --nodeps -gi nano 2>&1 | tee /tmp/test1
    4.16 +########
    4.17 +
    4.18 +if ! fgrep -q -e '--forced' /tmp/test1; then
    4.19 +	colorize 31 "ERROR. TazPkg should write warning. Exit test"
    4.20 +	rm /tmp/test1
    4.21 +	exit 1
    4.22 +fi
    4.23 +rm /tmp/test1
    4.24 +
    4.25 +footer "$(colorize 32 'Test #03 passed')"
    4.26 +exit 0
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tests/test04	Sat Dec 05 16:14:14 2015 +0200
     5.3 @@ -0,0 +1,22 @@
     5.4 +#!/bin/sh
     5.5 +#
     5.6 +. /lib/libtaz.sh
     5.7 +check_root
     5.8 +ROOT='/tmp/test'
     5.9 +
    5.10 +title 'Test #04'
    5.11 +colorize 033 "$(longline "Remove package.")"
    5.12 +newline
    5.13 +
    5.14 +########
    5.15 +echo y | tazpkg --root=$ROOT -r nano
    5.16 +########
    5.17 +
    5.18 +installed="$(ls $ROOT/var/lib/tazpkg/installed)"
    5.19 +if [ -n "$installed" ]; then
    5.20 +	colorize 31 "ERROR. Expected package 'nano' removed. Given: '$installed' Exit test"
    5.21 +	exit 1
    5.22 +fi
    5.23 +
    5.24 +footer "$(colorize 32 'Test #04 passed')"
    5.25 +exit 0
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tests/test05	Sat Dec 05 16:14:14 2015 +0200
     6.3 @@ -0,0 +1,25 @@
     6.4 +#!/bin/sh
     6.5 +#
     6.6 +. /lib/libtaz.sh
     6.7 +check_root
     6.8 +ROOT='/tmp/test'
     6.9 +
    6.10 +title 'Test #05'
    6.11 +colorize 033 "$(longline "Test equivalent package rule")"
    6.12 +newline
    6.13 +
    6.14 +########
    6.15 +tazpkg --root=$ROOT --nodeps -gi pam
    6.16 +tazpkg --root=$ROOT --nodeps -gi dropbear
    6.17 +tazpkg --root=$ROOT -l
    6.18 +########
    6.19 +
    6.20 +installeddropbear="$(ls $ROOT/var/lib/tazpkg/installed | fgrep dropbear)"
    6.21 +
    6.22 +if [ "$installeddropbear" != 'dropbear-pam' ]; then
    6.23 +	colorize 31 "ERROR. Expected package 'dropbear-pam' installed. Given: '$installeddropbear' Exit test"
    6.24 +	exit 1
    6.25 +fi
    6.26 +
    6.27 +footer "$(colorize 32 'Test #05 passed')"
    6.28 +exit 0
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tests/testsuite	Sat Dec 05 16:14:14 2015 +0200
     7.3 @@ -0,0 +1,12 @@
     7.4 +#!/bin/sh
     7.5 +#
     7.6 +. /lib/libtaz.sh
     7.7 +check_root
     7.8 +
     7.9 +for test in $(find . -name 'test[0-9]*' | sort); do
    7.10 +	$test
    7.11 +done
    7.12 +
    7.13 +footer "$(colorize 32 'All tests passed')"
    7.14 +rm -rf /tmp/test
    7.15 +exit 0