2010-06-12 07:33:53 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2011-10-11 06:34:22 +02:00
|
|
|
# some defines
|
|
|
|
export ADC_PATH="$HOME/glt-adc"
|
|
|
|
|
2011-10-11 03:09:28 +02:00
|
|
|
# are we in the right place
|
|
|
|
cd ${0%/*}
|
|
|
|
git rev-parse --show-toplevel || die should run t/test-driver.sh from a clone of gitolite
|
|
|
|
export TESTDIR=$PWD
|
|
|
|
|
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
|
|
|
# see some sample tests for how to use these functions; there is no
|
2010-06-12 07:33:53 +02:00
|
|
|
# documentation
|
|
|
|
|
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
|
|
|
# REPO_BASE has 2 manifestations in the output of various commands
|
2011-10-11 03:09:28 +02:00
|
|
|
export TEST_BASE=$(gl-query-rc REPO_BASE)
|
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
|
|
|
[ -z "$TEST_BASE" ] && { echo TEST_BASE not set >&2; exit 1; }
|
|
|
|
TEST_BASE_FULL=$TEST_BASE
|
2011-10-11 05:12:41 +02:00
|
|
|
[ "$TEST_BASE" = "repositories" ] && TEST_BASE_FULL=/home/$USER/repositories
|
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
|
|
|
|
2010-06-12 07:33:53 +02:00
|
|
|
testnum=0
|
|
|
|
|
|
|
|
# remote local command
|
|
|
|
runlocal() { "$@" > ~/1 2> ~/2; }
|
|
|
|
# remote run command
|
2011-10-11 05:12:41 +02:00
|
|
|
runremote() ( cd $HOME; "$@" > ~/1 2> ~/2; )
|
2010-06-12 07:33:53 +02:00
|
|
|
# remote list repositories
|
2011-10-11 05:12:41 +02:00
|
|
|
listrepos() ( cd $HOME; cd $TEST_BASE; find . -type d -name '*.git' | sort > ~/1 2> ~/2; )
|
2010-06-12 07:33:53 +02:00
|
|
|
# remote cat compiled pm
|
2011-10-11 05:12:41 +02:00
|
|
|
catconf() ( cat ~/.gitolite/conf/gitolite.conf-compiled.pm > ~/1 2> ~/2; )
|
2011-01-01 10:44:54 +01:00
|
|
|
catconfs() {
|
|
|
|
(
|
2011-10-11 05:12:41 +02:00
|
|
|
cd $HOME
|
|
|
|
cat .gitolite/conf/gitolite.conf-compiled.pm
|
|
|
|
cd $TEST_BASE; find . -name gl-conf | sort
|
|
|
|
cd $TEST_BASE; find . -name gl-conf | sort | xargs cat
|
2011-01-01 10:44:54 +01:00
|
|
|
) > ~/1 2> ~/2
|
|
|
|
}
|
2010-06-12 07:33:53 +02:00
|
|
|
# remote cat ~/.gitolite.rc
|
2011-10-11 05:12:41 +02:00
|
|
|
catrc() ( cat ~/.gitolite.rc > ~/1 2> ~/2; )
|
2010-06-12 07:33:53 +02:00
|
|
|
# tail gitolite logfile
|
2011-10-11 05:12:41 +02:00
|
|
|
taillog() ( cd $HOME; tail $1 .gitolite/logs/gitolite-????-??.log > ~/1 2> ~/2; )
|
2010-06-12 07:33:53 +02:00
|
|
|
hl() { # highlight function
|
|
|
|
normal=`tput sgr0`
|
|
|
|
red=`tput sgr0; tput setaf 1; tput bold`
|
2011-01-15 16:39:56 +01:00
|
|
|
echo >&2
|
2010-06-12 07:33:53 +02:00
|
|
|
if [[ -n $1 ]]
|
|
|
|
then
|
2011-01-15 16:39:56 +01:00
|
|
|
echo $red"$@"$normal >&2
|
2010-06-12 07:33:53 +02:00
|
|
|
else
|
2011-01-15 16:39:56 +01:00
|
|
|
echo $red >&2
|
2010-06-12 07:33:53 +02:00
|
|
|
cat
|
2011-01-15 16:39:56 +01:00
|
|
|
echo $normal >&2
|
2010-06-12 07:33:53 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
capture() { cf=$1; shift; "$@" >& $TESTDIR/$cf; }
|
|
|
|
|
|
|
|
editrc() {
|
2011-10-11 05:12:41 +02:00
|
|
|
perl -pi -e "print STDERR if not /^#/ and /$1\b/ and s/=.*/= $2;/" ~/.gitolite.rc 2> >(sed -e 's/^/# /')
|
2010-06-12 07:33:53 +02:00
|
|
|
}
|
|
|
|
|
2010-06-26 02:00:15 +02:00
|
|
|
addrc() {
|
2011-10-11 05:12:41 +02:00
|
|
|
tee -a ~/.gitolite.rc
|
|
|
|
echo '1;' >> ~/.gitolite.rc
|
2010-06-26 02:00:15 +02:00
|
|
|
}
|
|
|
|
|
2010-06-12 07:33:53 +02:00
|
|
|
ugc ()
|
|
|
|
{
|
|
|
|
(
|
|
|
|
cd ~/gitolite-admin;
|
|
|
|
[[ $1 == -r ]] && {
|
|
|
|
shift
|
|
|
|
cat $TESTDIR/basic.conf > conf/gitolite.conf
|
|
|
|
}
|
|
|
|
cat >> conf/gitolite.conf
|
|
|
|
git add conf keydir;
|
|
|
|
git commit --allow-empty -m "$TESTNAME";
|
|
|
|
git push ${1:-gitolite}:gitolite-admin master
|
|
|
|
git fetch origin >/dev/null 2>&1
|
|
|
|
) >~/1 2>~/2
|
2010-07-20 09:09:06 +02:00
|
|
|
grep DBG: ~/2 >/dev/null && grep . ~/1 ~/2
|
2010-06-12 07:33:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mdc()
|
|
|
|
{
|
|
|
|
(
|
|
|
|
echo $RANDOM > ${1:-$RANDOM}
|
|
|
|
git add .
|
|
|
|
git commit -m "$TESTNAME"
|
|
|
|
) >~/1 2>~/2
|
|
|
|
}
|
|
|
|
|
|
|
|
# set test name/desc
|
|
|
|
name() {
|
2011-01-15 16:39:56 +01:00
|
|
|
export TESTNAME="$*"
|
|
|
|
if [[ $TESTNAME != INTERNAL ]]
|
2010-06-12 07:33:53 +02:00
|
|
|
then
|
2011-01-15 16:39:56 +01:00
|
|
|
echo '#' "$*"
|
2010-06-12 07:33:53 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-01-15 16:39:56 +01:00
|
|
|
ok() {
|
|
|
|
(( testnum++ ))
|
|
|
|
echo 'ok' "($testnum) $*"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-12 07:33:53 +02:00
|
|
|
notok() {
|
2011-01-15 16:39:56 +01:00
|
|
|
(( testnum++ ))
|
|
|
|
echo 'not ok' "($testnum) $*"
|
2010-06-12 07:33:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
expect_filesame() {
|
|
|
|
if cmp ~/1 "$1"
|
|
|
|
then
|
2011-01-15 16:39:56 +01:00
|
|
|
ok
|
2010-06-12 07:33:53 +02:00
|
|
|
else
|
2011-01-15 16:39:56 +01:00
|
|
|
notok files ~/1 and "$1" are different
|
2010-06-12 07:33:53 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
die() {
|
2011-01-15 16:39:56 +01:00
|
|
|
echo '***** AAAAARRRGGH! *****' >&2
|
|
|
|
echo ${BASH_LINENO[1]} ${BASH_SOURCE[2]} >&2
|
|
|
|
echo "vim +${BASH_LINENO[1]} \'+r !head ~/1 ~/2 /dev/null\' ${BASH_SOURCE[2]}" >&2
|
2010-06-12 07:33:53 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
expect() {
|
|
|
|
if cat ~/1 ~/2 | grep "$1" >/dev/null
|
|
|
|
then
|
2011-01-15 16:39:56 +01:00
|
|
|
ok
|
2010-06-12 07:33:53 +02:00
|
|
|
else
|
2011-01-15 16:39:56 +01:00
|
|
|
notok "expecting: $1, got:"
|
|
|
|
cat ~/1 ~/2|sed -e 's/^/# /'
|
2010-06-12 07:33:53 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
notexpect() {
|
|
|
|
if cat ~/1 ~/2 | grep "$1" >/dev/null
|
|
|
|
then
|
2011-01-15 16:39:56 +01:00
|
|
|
notok "NOT expecting: $1, got:"
|
|
|
|
cat ~/1 ~/2|sed -e 's/^/# /'
|
2010-06-12 07:33:53 +02:00
|
|
|
else
|
2011-01-15 16:39:56 +01:00
|
|
|
ok
|
2010-06-12 07:33:53 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
expect_push_ok() {
|
|
|
|
expect "$1"
|
|
|
|
notexpect "DENIED"
|
|
|
|
notexpect "failed to push"
|
|
|
|
}
|
|
|
|
|
|
|
|
export TESTDIR=$PWD
|
|
|
|
arg1=$1; shift
|
|
|
|
for testfile in ${arg1:-t??-}*
|
|
|
|
do
|
|
|
|
hl $testfile
|
2010-06-18 18:13:53 +02:00
|
|
|
. $testfile "$@" || die "$testfile failed"
|
2010-06-12 07:33:53 +02:00
|
|
|
cd $TESTDIR
|
|
|
|
done
|
|
|
|
|
2012-01-16 05:09:04 +01:00
|
|
|
# this keeps changing as we add tests
|
2012-01-26 01:42:15 +01:00
|
|
|
echo 1..3163
|