tests: add test for various script actions

Closes: #410 [via git-merge-pr]
This commit is contained in:
Duncan Overbruck 2021-06-24 23:59:08 +02:00
parent 59bcbddcdb
commit dc0dda15f6
No known key found for this signature in database
GPG Key ID: 335C1D17EC3D6E35

View File

@ -84,7 +84,83 @@ script_arch_body() {
atf_check_equal $rval 0
}
create_script_stdout() {
cat > "$2" <<_EOF
#!/bin/sh
ACTION="\$1"
PKGNAME="\$2"
VERSION="\$3"
UPDATE="\$4"
CONF_FILE="\$5"
ARCH="\$6"
echo "$1 \$@"
_EOF
chmod +x "$1"
}
atf_test_case script_action
script_action_head() {
atf_set "descr" "Tests for package scripts: different actions"
}
script_action_body() {
mkdir some_repo root
mkdir -p pkg_A/usr/bin
echo "A-1.0_1" > pkg_A/usr/bin/foo
create_script_stdout "install" pkg_A/INSTALL
create_script_stdout "remove" pkg_A/REMOVE
cd some_repo
xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A
atf_check_equal $? 0
xbps-rindex -d -a $PWD/*.xbps
atf_check_equal $? 0
cd ..
xbps-install -C empty.conf -r root --repository=$PWD/some_repo -y A >out
atf_check_equal $? 0
grep "^install pre A 1.0_1 no no" out
atf_check_equal $? 0
grep "^install post A 1.0_1 no no" out
atf_check_equal $? 0
cd some_repo
xbps-create -A noarch -n A-1.1_1 -s "A pkg" ../pkg_A
atf_check_equal $? 0
xbps-rindex -d -a $PWD/*.xbps
atf_check_equal $? 0
cd ..
xbps-install -C empty.conf -r root --repository=$PWD/some_repo -yu >out
atf_check_equal $? 0
grep "^remove pre A 1.0_1 yes no" out
atf_check_equal $? 0
grep "^install pre A 1.1_1 yes no" out
atf_check_equal $? 0
grep "^remove post A 1.0_1 yes no" out
atf_check_equal $? 0
grep "^remove purge A 1.0_1 yes no" out
atf_check_equal $? 0
grep "^install post A 1.1_1 yes no" out
atf_check_equal $? 0
xbps-remove -C empty.conf -r root -y A >out
atf_check_equal $? 0
grep "^remove pre A 1.1_1 no no" out
atf_check_equal $? 0
grep "^remove post A 1.1_1 no no" out
atf_check_equal $? 0
grep "^remove purge A 1.1_1 no no" out
atf_check_equal $? 0
}
atf_init_test_cases() {
atf_add_test_case script_nargs
atf_add_test_case script_arch
atf_add_test_case script_action
}