Commit 11f4fa81f7f7aabf7d522a63257765a89926f3e0

Stefan Sperling 2020-10-01T20:52:11

allow regress test data to be stored in locations other than /tmp

diff --git a/README b/README
index 6fbe310..6f504d1 100644
--- a/README
+++ b/README
@@ -39,6 +39,14 @@ To test with packed repositories, run:
 
  $ make regress GOT_TEST_PACK=1
 
+Because got unveils the /tmp directory by default using the /tmp directory
+for test data can hide bugs. However, /tmp remains the default because
+there is no better alternative that works out of the box. In order to
+store test data in a directory other than /tmp, such as ~/got-test, run:
+
+ $ mkdir ~/got-test
+ $ make regress GOT_TEST_ROOT=~/got-test
+
 Man page files in the Got source tree can be viewed with 'man -l':
 
  $ man -l got/got.1
diff --git a/regress/cmdline/Makefile b/regress/cmdline/Makefile
index 81d463f..081593c 100644
--- a/regress/cmdline/Makefile
+++ b/regress/cmdline/Makefile
@@ -3,79 +3,81 @@ REGRESS_TARGETS=checkout update status log add rm diff blame branch tag \
 	integrate stage unstage cat clone fetch tree
 NOOBJ=Yes
 
+GOT_TEST_ROOT=/tmp
+
 checkout:
-	./checkout.sh -q
+	./checkout.sh -q -r $(GOT_TEST_ROOT)
 
 update:
-	./update.sh -q
+	./update.sh -q -r $(GOT_TEST_ROOT)
 
 status:
-	./status.sh -q
+	./status.sh -q -r $(GOT_TEST_ROOT)
 
 log:
-	./log.sh -q
+	./log.sh -q -r $(GOT_TEST_ROOT)
 
 add:
-	./add.sh -q
+	./add.sh -q -r $(GOT_TEST_ROOT)
 
 rm:
-	./rm.sh -q
+	./rm.sh -q -r $(GOT_TEST_ROOT)
 
 diff:
-	./diff.sh -q
+	./diff.sh -q -r $(GOT_TEST_ROOT)
 
 blame:
-	./blame.sh -q
+	./blame.sh -q -r $(GOT_TEST_ROOT)
 
 branch:
-	./branch.sh -q
+	./branch.sh -q -r $(GOT_TEST_ROOT)
 
 tag:
-	./tag.sh -q
+	./tag.sh -q -r $(GOT_TEST_ROOT)
 
 ref:
-	./ref.sh -q
+	./ref.sh -q -r $(GOT_TEST_ROOT)
 
 commit:
-	./commit.sh -q
+	./commit.sh -q -r $(GOT_TEST_ROOT)
 
 revert:
-	./revert.sh -q
+	./revert.sh -q -r $(GOT_TEST_ROOT)
 
 cherrypick:
-	./cherrypick.sh -q
+	./cherrypick.sh -q -r $(GOT_TEST_ROOT)
 
 backout:
-	./backout.sh -q
+	./backout.sh -q -r $(GOT_TEST_ROOT)
 
 rebase:
-	./rebase.sh -q
+	./rebase.sh -q -r $(GOT_TEST_ROOT)
 
 import:
-	./import.sh -q
+	./import.sh -q -r $(GOT_TEST_ROOT)
 
 histedit:
-	./histedit.sh -q
+	./histedit.sh -q -r $(GOT_TEST_ROOT)
 
 integrate:
-	./integrate.sh -q
+	./integrate.sh -q -r $(GOT_TEST_ROOT)
 
 stage:
-	./stage.sh -q
+	./stage.sh -q -r $(GOT_TEST_ROOT)
 
 unstage:
-	./unstage.sh -q
+	./unstage.sh -q -r $(GOT_TEST_ROOT)
 
 cat:
-	./cat.sh -q
+	./cat.sh -q -r $(GOT_TEST_ROOT)
 
 clone:
-	./clone.sh -q
+	./clone.sh -q -r $(GOT_TEST_ROOT)
 
 fetch:
-	./fetch.sh -q
+	./fetch.sh -q -r $(GOT_TEST_ROOT)
 
 tree:
-	./tree.sh -q
+	./tree.sh -q -r $(GOT_TEST_ROOT)
 
 .include <bsd.regress.mk>
diff --git a/regress/cmdline/common.sh b/regress/cmdline/common.sh
index aa03589..d022c28 100644
--- a/regress/cmdline/common.sh
+++ b/regress/cmdline/common.sh
@@ -21,6 +21,7 @@ export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
 export GOT_AUTHOR="$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
 export GOT_AUTHOR_8="flan_hac"
 export GOT_LOG_DEFAULT_LIMIT=0
+export GOT_TEST_ROOT="/tmp"
 
 export MALLOC_OPTIONS=S
 
@@ -168,7 +169,7 @@ test_init()
 		echo "No test name provided" >&2
 		return 1
 	fi
-	local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
+	local testroot=`mktemp -p $GOT_TEST_ROOT -d got-test-$testname-XXXXXXXX`
 	mkdir $testroot/repo
 	git_init $testroot/repo
 	if [ -z "$no_tree" ]; then
@@ -199,10 +200,11 @@ test_cleanup()
 
 test_parseargs()
 {
-	args=`getopt q $*`
+	args=`getopt qr: $*`
 	if [ $? -ne 0 ]; then
 		echo "Supported options:"
 		echo "  -q: quiet mode"
+		echo "  -r PATH: use PATH as test data root directory"
 		exit 2
 	fi
 	set -- $args
@@ -211,6 +213,8 @@ test_parseargs()
 		in
 			-q)
 			   export GOT_TEST_QUIET=1; shift;;
+			-r)
+			   export GOT_TEST_ROOT="$2"; shift; shift;;
 			--)
 			   shift; break;;
 		esac
diff --git a/regress/cmdline/import.sh b/regress/cmdline/import.sh
index 6d8e522..8678e99 100755
--- a/regress/cmdline/import.sh
+++ b/regress/cmdline/import.sh
@@ -18,7 +18,7 @@
 
 test_import_basic() {
 	local testname=import_basic
-	local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
+	local testroot=`mktemp -p $GOT_TEST_ROOT -d got-test-$testname-XXXXXXXX`
 
 	got init $testroot/repo
 
@@ -170,7 +170,7 @@ test_import_requires_new_branch() {
 
 test_import_ignores() {
 	local testname=import_ignores
-	local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
+	local testroot=`mktemp -p $GOT_TEST_ROOT -d got-test-$testname-XXXXXXXX`
 
 	got init $testroot/repo
 
@@ -200,7 +200,7 @@ test_import_ignores() {
 
 test_import_empty_dir() {
 	local testname=import_empty_dir
-	local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
+	local testroot=`mktemp -p $GOT_TEST_ROOT -d got-test-$testname-XXXXXXXX`
 
 	got init $testroot/repo
 
@@ -243,7 +243,7 @@ test_import_empty_dir() {
 
 test_import_symlink() {
 	local testname=import_symlink
-	local testroot=`mktemp -p /tmp -d got-test-$testname-XXXXXXXX`
+	local testroot=`mktemp -p $GOT_TEST_ROOT -d got-test-$testname-XXXXXXXX`
 
 	got init $testroot/repo