Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
test: add a unit test about autoremove order
Baptiste Daroussin committed 2 months ago
commit cf6876e2ee76f3501c13f37c41546ff81f86e324
parent cafd07a
1 file changed +60 -1
modified tests/frontend/autoremove.sh
@@ -5,7 +5,8 @@
tests_init \
	autoremove \
	autoremove_quiet \
-
	autoremove_dryrun
+
	autoremove_dryrun \
+
	autoremove_order

autoremove_prep() {
	touch file1
@@ -106,6 +107,64 @@ autoremove_quiet_body() {
	test ! -f ${TMPDIR}/file1 -o ! -f ${TMPDIR}/file2 || atf_fail "Files are still present"
}

+
autoremove_order_body() {
+
	# Create a dependency chain: top -> libc -> libb -> liba
+
	# liba, libb, libc are automatic; top is manual.
+
	# After removing top, autoremove should remove in dependency
+
	# order: libc first (leaf), then libb, then liba (base).
+

+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg liba liba 1
+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg libb libb 1
+
	cat << EOF >> libb.ucl
+
deps: {
+
	liba {
+
		origin: liba,
+
		version: 1
+
	}
+
}
+
EOF
+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg libc libc 1
+
	cat << EOF >> libc.ucl
+
deps: {
+
	libb {
+
		origin: libb,
+
		version: 1
+
	}
+
}
+
EOF
+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg top top 1
+
	cat << EOF >> top.ucl
+
deps: {
+
	libc {
+
		origin: libc,
+
		version: 1
+
	}
+
}
+
EOF
+

+
	atf_check -o ignore -s exit:0 pkg register -A -M liba.ucl
+
	atf_check -o ignore -s exit:0 pkg register -A -M libb.ucl
+
	atf_check -o ignore -s exit:0 pkg register -A -M libc.ucl
+
	atf_check -o ignore -s exit:0 pkg register -M top.ucl
+

+
	atf_check -o ignore -s exit:0 pkg delete -y top
+

+
	# Run autoremove and capture output
+
	pkg autoremove -y > output.txt 2>/dev/null || atf_fail "pkg autoremove failed"
+

+
	# Verify removal order: dependents before their dependencies
+
	grep "Deinstalling" output.txt | sed 's/.*Deinstalling //;s/\.\.\.//' > order.txt
+
	printf "libc-1\nlibb-1\nliba-1\n" > expected.txt
+
	diff -u expected.txt order.txt || atf_fail "Wrong autoremove order"
+

+
	# All packages should be gone
+
	atf_check \
+
	    -o empty \
+
	    -e empty \
+
	    -s exit:0 \
+
	    pkg info
+
}
+

autoremove_dryrun_body() {
	autoremove_prep