# All of the files in this directory are Copyright (c) 2000 BitMover, Inc.
# and are not licensed under the terms of the BKL (BitKeeper License).
# Standard copyright law applies.
# 
# Redistribution in modified form is prohibited with one exception:
#    proposed modifications may be sent back to dev@bitmover.com for
#    possible inclusion in future releases.  Sending such modifications
#    constitutes your permission for BitMover, Inc. to distribute  the
#    modifications under any license.

# Setup code for tests
# Copright (c) 1999 Larry McVoy
# wscott@wscott1.homeip.net|src/t/setup|20020308190308|17595

# *IMPORTANT* This file should be kept small, it is called in the main loop
#	      of doit.sh

cores()
{
	OUT="$BK_REGRESSION/cores"
        find "$BK_REGRESSION" -name core -print > "$OUT"
        if [ -s "$OUT" ]
        then    ls -l `cat "$OUT"`
                file `cat "$OUT"`
                exit 10
        fi
}


# [ -w file ] always succeeds when you are root.
writable() {
	[ -f "$1" ] || return 1
	case "`ls -l "$1" | cut -c1-10`" in
	    *w*) return 0;;
	    *) return 1;;
	esac
}

checkLocks() {
	if [ -d BitKeeper/readers ]
	then	if [ `find BitKeeper/readers -type f -print | wc -l` -ne 0 ]
		then	echo Failed to remove read lock in `pwd`
			exit 1
		fi
	fi
	if [ -d BitKeeper/writer ]
	then	if [ `find BitKeeper/writer -type f -print | wc -l` -ne 0 ]
		then	echo Failed to remove write lock in `pwd`
			exit 1
		fi
	fi
}

# We need this because some proxy disallow proxy to localhost
# some of our test do http push/pull/clone to localhost
unsetHttpProxy() {
	unset http_proxy HTTP_PROXY_HOST HTTP_PROXY_PORT
	unset SOCKS_HOST SOCKS_PORT SOCKS_SERVER
	unset HTTP_PROXY # workaround for cygwin
}

# Usage: waitForUnlock <root>
waitForUnlock() {
	bk lock -U $1
}

no_logging() {
	echo "logging: none" > c
	echo "single_user: bk" >> c
	echo "single_host: free.bk" >> c
	echo "description: BitKeeper Test repository" >> c
	echo "email: nobody@nowhere.bk" >> c
	echo "eoln: unix" >> c
	echo "keyword: sccs" >> c
	bk setup -f -cc $1 || { echo "Setup failed!"; exit 1; }
	cd $1
}

echon() {
	echo $NX "$*" $NXL
}

cd "$BK_REGRESSION" || exit 1
HERE=`bk pwd`

# XXX This test should be moved to doit.sh for better test performance
for i in .. ../.. ../../.. ../../..
do	if [ -d ${i}/BitKeeper/etc ]
	then	cat <<EOF

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Found an enclosing BitKeeper repository at ${i}/BitKeeper - this is
probably an error, please check it out and if so, remove it.  Some tests
can not run with that BitKeeper directory there.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

EOF
		exit 1
	fi
done

# We need this because ksh on Solaris override $PATH from .profile
PATH=$BK_PATH
