do not edit — generated by btf.
git.druid.rocksindexdruid520mptest/suites/removal.sh

test/suites/removal.sh


# suite: mp remove's manifest-driven cleanup sweep -- after a port's own
# remove: (or del.sh) has had its chance to run, mp deletes whatever that
# port's manifest still lists that's still on disk (clean_manifest_files
# in mplib::resolve), so remove: only needs to handle what genuinely
# needs its own logic, not hand-mirror every file install: touched. a
# port opts out with pkg_manifest_cleanup="no".
 
# remove: here deliberately "forgets" one of the two files install:
# created -- the sweep should catch it anyway, once remove.sh has
# already run (its own rm of the OTHER file must still take effect,
# proving the sweep runs after, not instead of, the real remove phase).
test_manifest_cleanup_catches_leftover() {
	t_begin "manifest_cleanup_catches_leftover"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	mkport rm1incomplete <<'EOF'
pkg_name="rm1incomplete"
pkg_ver="1.0"
install:
	mkdir -p $MP_PREFIX/rm1sub
	touch $MP_PREFIX/rm1incomplete-main $MP_PREFIX/rm1sub/rm1incomplete-extra
remove:
	rm -f $MP_PREFIX/rm1incomplete-main
EOF
	mp install rm1incomplete >/tmp/rm1.out 2>&1
	assert_exit0 "$?" "$CUR_TEST" || return
	assert_file_exists "$MP_PREFIX/rm1sub/rm1incomplete-extra" "$CUR_TEST" || return
 
	mp remove rm1incomplete >>/tmp/rm1.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	assert_file_absent "$MP_PREFIX/rm1incomplete-main" "$CUR_TEST" || return
	assert_file_absent "$MP_PREFIX/rm1sub/rm1incomplete-extra" "$CUR_TEST" || return
	out=$(cat /tmp/rm1.out)
	assert_contains "$out" "manifest cleanup removed" "$CUR_TEST" || return
	t_pass
}
 
# identical port, but opted out -- the same leftover file must survive
# "mp remove" untouched, proving pkg_manifest_cleanup="no" genuinely
# disables the sweep rather than just suppressing its own note.
test_manifest_cleanup_opt_out() {
	t_begin "manifest_cleanup_opt_out"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	mkport rm2optout <<'EOF'
pkg_name="rm2optout"
pkg_ver="1.0"
pkg_manifest_cleanup="no"
install:
	touch $MP_PREFIX/rm2optout-main $MP_PREFIX/rm2optout-extra
remove:
	rm -f $MP_PREFIX/rm2optout-main
EOF
	mp install rm2optout >/tmp/rm2.out 2>&1
	assert_exit0 "$?" "$CUR_TEST" || return
 
	mp remove rm2optout >>/tmp/rm2.out 2>&1
	assert_exit0 "$?" "$CUR_TEST" || return
	assert_file_absent "$MP_PREFIX/rm2optout-main" "$CUR_TEST" || return
	assert_file_exists "$MP_PREFIX/rm2optout-extra" "$CUR_TEST" || return
	rm -f "$MP_PREFIX/rm2optout-extra"
	t_pass
}
 
# a remove: that already deletes everything install: created -- the
# sweep must be a true no-op (no "manifest cleanup removed" note, no
# error re-deleting something already gone).
test_manifest_cleanup_noop_when_complete() {
	t_begin "manifest_cleanup_noop_when_complete"
	reset_state
	printf 'GLOBAL_DEPS=" "\n' >> "$CONF"
	mkport rm3complete <<'EOF'
pkg_name="rm3complete"
pkg_ver="1.0"
install:
	touch $MP_PREFIX/rm3complete-main
remove:
	rm -f $MP_PREFIX/rm3complete-main
EOF
	mp install rm3complete >/tmp/rm3.out 2>&1
	assert_exit0 "$?" "$CUR_TEST" || return
 
	mp remove rm3complete >/tmp/rm3.out 2>&1
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	assert_file_absent "$MP_PREFIX/rm3complete-main" "$CUR_TEST" || return
	out=$(cat /tmp/rm3.out)
	assert_not_contains "$out" "manifest cleanup removed" "$CUR_TEST" || return
	t_pass
}
 
# a remove: that fails outright (a "make uninstall" with no such target
# is the real-world case -- mplib::portlint's own check_uninstall_
# target_risk exists for exactly this) must not strand the package:
# the manifest sweep still runs and mp remove still succeeds, since
# nothing here opted out of it.
test_manifest_cleanup_survives_remove_failure() {
	t_begin "manifest_cleanup_survives_remove_failure"
	reset_state
	mkport rm4failing <<'EOF'
pkg_name="rm4failing"
pkg_ver="1.0"
install:
	touch $MP_PREFIX/rm4failing-main
remove:
	false
EOF
	mp install rm4failing >/tmp/rm4.out 2>&1
	assert_exit0 "$?" "$CUR_TEST" || return
 
	out=$(mp remove rm4failing 2>&1)
	rc=$?
	assert_exit0 "$rc" "$CUR_TEST" || return
	assert_file_absent "$MP_PREFIX/rm4failing-main" "$CUR_TEST" || return
	assert_contains "$out" "remove phase failed" "$CUR_TEST" || return
	assert_contains "$out" "manifest cleanup removed" "$CUR_TEST" || return
	db=$(cat "$WD/db")
	assert_not_contains "$db" "rm4failing" "$CUR_TEST (db entry actually cleared)" || return
	t_pass
}
 
# the identical failing remove:, but opted out -- there's no sweep to
# fall back on, so this must stay a real, immediately-reported failure,
# same as it always was, not a silently-tolerated one.
test_manifest_cleanup_opt_out_remove_failure_stays_hard() {
	t_begin "manifest_cleanup_opt_out_remove_failure_stays_hard"
	reset_state
	mkport rm5failing <<'EOF'
pkg_name="rm5failing"
pkg_ver="1.0"
pkg_manifest_cleanup="no"
install:
	touch $MP_PREFIX/rm5failing-main
remove:
	false
EOF
	mp install rm5failing >/tmp/rm5.out 2>&1
	assert_exit0 "$?" "$CUR_TEST" || return
 
	mp remove rm5failing >/tmp/rm5.out 2>&1
	rc=$?
	assert_exit_nonzero "$rc" "$CUR_TEST" || return
	assert_file_exists "$MP_PREFIX/rm5failing-main" "$CUR_TEST" || return
	db=$(cat "$WD/db")
	assert_contains "$db" "rm5failing" "$CUR_TEST (db entry NOT cleared -- still genuinely installed)" || return
	t_pass
}
 
run_removal_suite() {
	test_manifest_cleanup_catches_leftover
	test_manifest_cleanup_opt_out
	test_manifest_cleanup_noop_when_complete
	test_manifest_cleanup_survives_remove_failure
	test_manifest_cleanup_opt_out_remove_failure_stays_hard
}
powered by btf.