2007-11-11 00:40:58 +01:00
|
|
|
# This file should be sourced by all test-scripts
|
|
|
|
#
|
|
|
|
# Main functions:
|
|
|
|
# prepare_tests(description) - setup for testing, i.e. create repos+config
|
|
|
|
# run_test(description, script) - run one test, i.e. eval script
|
|
|
|
#
|
|
|
|
# Helper functions
|
|
|
|
# cgit_query(querystring) - call cgit with the specified querystring
|
|
|
|
# cgit_url(url) - call cgit with the specified virtual url
|
|
|
|
#
|
|
|
|
# Example script:
|
|
|
|
#
|
|
|
|
# . setup.sh
|
|
|
|
# prepare_tests "html validation"
|
|
|
|
# run_test 'repo index' 'cgit_url "/" | tidy -e'
|
|
|
|
# run_test 'repo summary' 'cgit_url "/foo" | tidy -e'
|
|
|
|
|
2011-07-21 14:43:54 +02:00
|
|
|
unset CDPATH
|
2007-11-11 00:40:58 +01:00
|
|
|
|
|
|
|
mkrepo() {
|
|
|
|
name=$1
|
|
|
|
count=$2
|
|
|
|
dir=$PWD
|
2011-05-22 12:22:56 +02:00
|
|
|
test -d "$name" && return
|
2007-11-11 00:40:58 +01:00
|
|
|
printf "Creating testrepo %s\n" $name
|
2011-05-22 12:22:56 +02:00
|
|
|
mkdir -p "$name"
|
|
|
|
cd "$name"
|
2007-11-11 00:40:58 +01:00
|
|
|
git init
|
2008-11-04 20:23:41 +01:00
|
|
|
n=1
|
|
|
|
while test $n -le $count
|
2007-11-11 00:40:58 +01:00
|
|
|
do
|
|
|
|
echo $n >file-$n
|
|
|
|
git add file-$n
|
|
|
|
git commit -m "commit $n"
|
2008-11-04 20:23:41 +01:00
|
|
|
n=$(expr $n + 1)
|
2007-11-11 00:40:58 +01:00
|
|
|
done
|
2008-10-05 12:52:25 +02:00
|
|
|
if test "$3" = "testplus"
|
|
|
|
then
|
|
|
|
echo "hello" >a+b
|
|
|
|
git add a+b
|
|
|
|
git commit -m "add a+b"
|
|
|
|
git branch "1+2"
|
|
|
|
fi
|
2012-03-18 11:43:49 +01:00
|
|
|
cd "$dir"
|
2007-11-11 00:40:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setup_repos()
|
|
|
|
{
|
|
|
|
rm -rf trash/cache
|
|
|
|
mkdir -p trash/cache
|
|
|
|
mkrepo trash/repos/foo 5 >/dev/null
|
|
|
|
mkrepo trash/repos/bar 50 >/dev/null
|
2008-10-05 12:52:25 +02:00
|
|
|
mkrepo trash/repos/foo+bar 10 testplus >/dev/null
|
2011-05-22 12:22:56 +02:00
|
|
|
mkrepo "trash/repos/with space" 2 >/dev/null
|
2007-11-11 00:40:58 +01:00
|
|
|
cat >trash/cgitrc <<EOF
|
|
|
|
virtual-root=/
|
|
|
|
cache-root=$PWD/trash/cache
|
|
|
|
|
2008-04-28 11:32:42 +02:00
|
|
|
cache-size=1021
|
2007-11-11 00:40:58 +01:00
|
|
|
snapshots=tar.gz tar.bz zip
|
|
|
|
enable-log-filecount=1
|
|
|
|
enable-log-linecount=1
|
|
|
|
summary-log=5
|
|
|
|
summary-branches=5
|
|
|
|
summary-tags=5
|
|
|
|
|
|
|
|
repo.url=foo
|
|
|
|
repo.path=$PWD/trash/repos/foo/.git
|
2008-02-24 15:27:33 +01:00
|
|
|
# Do not specify a description for this repo, as it then will be assigned
|
|
|
|
# the constant value "[no description]" (which actually used to cause a
|
|
|
|
# segfault).
|
2007-11-11 00:40:58 +01:00
|
|
|
|
|
|
|
repo.url=bar
|
|
|
|
repo.path=$PWD/trash/repos/bar/.git
|
|
|
|
repo.desc=the bar repo
|
2008-10-05 12:52:25 +02:00
|
|
|
|
|
|
|
repo.url=foo+bar
|
|
|
|
repo.path=$PWD/trash/repos/foo+bar/.git
|
|
|
|
repo.desc=the foo+bar repo
|
2011-05-22 12:22:56 +02:00
|
|
|
|
|
|
|
repo.url=with space
|
|
|
|
repo.path=$PWD/trash/repos/with space/.git
|
|
|
|
repo.desc=spaced repo
|
2007-11-11 00:40:58 +01:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
prepare_tests()
|
|
|
|
{
|
|
|
|
setup_repos
|
2008-02-24 19:53:51 +01:00
|
|
|
rm -f test-output.log 2>/dev/null
|
2007-11-11 00:40:58 +01:00
|
|
|
test_count=0
|
|
|
|
test_failed=0
|
2008-02-24 19:53:51 +01:00
|
|
|
echo "[$0]" "$@" >test-output.log
|
2007-11-11 00:40:58 +01:00
|
|
|
echo "$@" "($0)"
|
|
|
|
}
|
|
|
|
|
|
|
|
tests_done()
|
|
|
|
{
|
|
|
|
printf "\n"
|
|
|
|
if test $test_failed -gt 0
|
|
|
|
then
|
2008-02-24 19:53:51 +01:00
|
|
|
printf "test: *** %s failure(s), logfile=%s\n" \
|
|
|
|
$test_failed "$(pwd)/test-output.log"
|
2007-11-11 00:40:58 +01:00
|
|
|
false
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
run_test()
|
|
|
|
{
|
2011-05-22 12:21:31 +02:00
|
|
|
bug=0
|
|
|
|
if test "$1" = "BUG"
|
|
|
|
then
|
|
|
|
bug=1
|
|
|
|
shift
|
|
|
|
fi
|
2007-11-11 00:40:58 +01:00
|
|
|
desc=$1
|
|
|
|
script=$2
|
2008-11-04 20:23:41 +01:00
|
|
|
test_count=$(expr $test_count + 1)
|
2008-02-24 19:53:51 +01:00
|
|
|
printf "\ntest %d: name='%s'\n" $test_count "$desc" >>test-output.log
|
|
|
|
printf "test %d: eval='%s'\n" $test_count "$2" >>test-output.log
|
|
|
|
eval "$2" >>test-output.log 2>>test-output.log
|
2007-11-11 00:40:58 +01:00
|
|
|
res=$?
|
2008-02-24 19:53:51 +01:00
|
|
|
printf "test %d: exitcode=%d\n" $test_count $res >>test-output.log
|
2011-05-22 12:21:31 +02:00
|
|
|
if test $res = 0 -a $bug = 0
|
2007-11-11 00:40:58 +01:00
|
|
|
then
|
2008-02-24 16:05:58 +01:00
|
|
|
printf " %2d) %-60s [ok]\n" $test_count "$desc"
|
2011-05-22 12:21:31 +02:00
|
|
|
elif test $res = 0 -a $bug = 1
|
|
|
|
then
|
|
|
|
printf " %2d) %-60s [BUG FIXED]\n" $test_count "$desc"
|
|
|
|
elif test $bug = 1
|
|
|
|
then
|
|
|
|
printf " %2d) %-60s [KNOWN BUG]\n" $test_count "$desc"
|
2007-11-11 00:40:58 +01:00
|
|
|
else
|
2008-12-06 12:03:54 +01:00
|
|
|
test_failed=$(expr $test_failed + 1)
|
2008-02-24 16:05:58 +01:00
|
|
|
printf " %2d) %-60s [failed]\n" $test_count "$desc"
|
2007-11-11 00:40:58 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
cgit_query()
|
|
|
|
{
|
|
|
|
CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="$1" "$PWD/../cgit"
|
|
|
|
}
|
|
|
|
|
|
|
|
cgit_url()
|
|
|
|
{
|
|
|
|
CGIT_CONFIG="$PWD/trash/cgitrc" QUERY_STRING="url=$1" "$PWD/../cgit"
|
|
|
|
}
|