From c88f15c8fa0e0ea9cdf6d07d150a15f951657b2b Mon Sep 17 00:00:00 2001
From: Duncan Overbruck <mail@duncano.de>
Date: Mon, 5 Aug 2019 14:45:19 +0200
Subject: [PATCH] tests: add two new test cases for keep and removal of
 modified files

---
 tests/xbps/libxbps/shell/remove_test.sh | 65 +++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/tests/xbps/libxbps/shell/remove_test.sh b/tests/xbps/libxbps/shell/remove_test.sh
index a9d97151..148722ab 100644
--- a/tests/xbps/libxbps/shell/remove_test.sh
+++ b/tests/xbps/libxbps/shell/remove_test.sh
@@ -489,6 +489,69 @@ remove_directory_body() {
 	atf_check_equal $? 1
 }
 
+atf_test_case keep_modified_files
+
+keep_modified_files_head() {
+	atf_set "descr" "Tests for package removal: keep modified files in rootdir"
+}
+
+keep_modified_files_body() {
+	mkdir some_repo
+	mkdir -p pkg_A/bin
+	echo "1234" >pkg_A/bin/ash
+	echo "1234" >pkg_A/bin/sh
+
+	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 -r root -C null.conf --repository=$PWD/some_repo -y A
+	atf_check_equal $? 0
+	echo "keep" >root/bin/sh
+	echo "keep" >root/bin/ash
+
+	xbps-remove -r root -yvd A
+	atf_check_equal $? 0
+	rv=1
+	if [ -e root/bin/sh -a -e root/bin/ash ]; then
+	        rv=0
+	fi
+	atf_check_equal $rv 0
+}
+
+atf_test_case remove_modified_files
+
+remove_modified_files_head() {
+	atf_set "descr" "Tests for package removal: force remove modified files in rootdir"
+}
+
+remove_modified_files_body() {
+	mkdir some_repo
+	mkdir -p pkg_A/bin
+	echo "1234" >pkg_A/bin/ash
+	echo "1234" >pkg_A/bin/sh
+
+	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 -r root -C null.conf --repository=$PWD/some_repo -y A
+	atf_check_equal $? 0
+	echo "don't keep" >root/bin/sh
+	echo "don't keep" > root/bin/ash
+
+	xbps-remove -r root -yvdf A
+	atf_check_equal $? 0
+	rv=0
+	[ -e root/bin/sh ] && rv=1
+	[ -e root/bin/ash ] && rv=1
+	atf_check_equal $rv 0
+}
+
 atf_init_test_cases() {
 	atf_add_test_case keep_base_symlinks
 	atf_add_test_case keep_modified_symlinks
@@ -507,4 +570,6 @@ atf_init_test_cases() {
 	atf_add_test_case remove_with_revdeps_in_trans_inverted
 	atf_add_test_case remove_with_revdeps_in_trans_recursive
 	atf_add_test_case remove_directory
+	atf_add_test_case keep_modified_files
+	atf_add_test_case remove_modified_files
 }