2007-11-10 23:40:58 +00: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 12:43:54 +00:00
|
|
|
unset CDPATH
|
2007-11-10 23:40:58 +00:00
|
|
|
|
|
|
|
mkrepo() {
|
|
|
|
name=$1
|
|
|
|
count=$2
|
|
|
|
dir=$PWD
|
2011-05-22 10:22:56 +00:00
|
|
|
test -d "$name" && return
|
2007-11-10 23:40:58 +00:00
|
|
|
printf "Creating testrepo %s\n" $name
|
2011-05-22 10:22:56 +00:00
|
|
|
mkdir -p "$name"
|
|
|
|
cd "$name"
|
2007-11-10 23:40:58 +00:00
|
|
|
git init
|
2008-11-04 19:23:41 +00:00
|
|
|
n=1
|
|
|
|
while test $n -le $count
|
2007-11-10 23:40:58 +00:00
|
|
|
do
|
|
|
|
echo $n >file-$n
|
|
|
|
git add file-$n
|
|
|
|
git commit -m "commit $n"
|
2008-11-04 19:23:41 +00:00
|
|
|
n=$(expr $n + 1)
|
2007-11-10 23:40:58 +00:00
|
|
|
done
|
2008-10-05 10:52:25 +00: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
|
2007-11-10 23:40:58 +00:00
|
|
|
cd $dir
|
|
|
|
}
|
|
|
|
|
|
|
|
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 10:52:25 +00:00
|
|
|
mkrepo trash/repos/foo+bar 10 testplus >/dev/null
|
2011-05-22 10:22:56 +00:00
|
|
|
mkrepo "trash/repos/with space" 2 >/dev/null
|
2007-11-10 23:40:58 +00:00
|
|
|
cat >trash/cgitrc <<EOF
|
|
|
|
virtual-root=/
|
|
|
|
cache-root=$PWD/trash/cache
|
|
|
|
|
2008-04-28 09:32:42 +00:00
|
|
|
cache-size=1021
|
2007-11-10 23:40:58 +00: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 14:27:33 +00: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-10 23:40:58 +00:00
|
|
|
|
|
|
|
repo.url=bar
|
|
|
|
repo.path=$PWD/trash/repos/bar/.git
|
|
|
|
repo.desc=the bar repo
|
2008-10-05 10:52:25 +00:00
|
|
|
|
|
|
|
repo.url=foo+bar
|
|
|
|
repo.path=$PWD/trash/repos/foo+bar/.git
|
|
|
|
repo.desc=the foo+bar repo
|
2011-05-22 10:22:56 +00:00
|
|
|
|
|
|
|
repo.url=with space
|
|
|
|
repo.path=$PWD/trash/repos/with space/.git
|
|
|
|
repo.desc=spaced repo
|
2007-11-10 23:40:58 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
prepare_tests()
|
|
|
|
{
|
|
|
|
setup_repos
|
2008-02-24 18:53:51 +00:00
|
|
|
rm -f test-output.log 2>/dev/null
|
2007-11-10 23:40:58 +00:00
|
|
|
test_count=0
|
|
|
|
test_failed=0
|
2008-02-24 18:53:51 +00:00
|
|
|
echo "[$0]" "$@" >test-output.log
|
2007-11-10 23:40:58 +00:00
|
|
|
echo "$@" "($0)"
|
|
|
|
}
|
|
|
|
|
|
|
|
tests_done()
|
|
|
|
{
|
|
|
|
printf "\n"
|
|
|
|
if test $test_failed -gt 0
|
|
|
|
then
|
2008-02-24 18:53:51 +00:00
|
|
|
printf "test: *** %s failure(s), logfile=%s\n" \
|
|
|
|
$test_failed "$(pwd)/test-output.log"
|
2007-11-10 23:40:58 +00:00
|
|
|
false
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
run_test()
|
|
|
|
{
|
2011-05-22 10:21:31 +00:00
|
|
|
bug=0
|
|
|
|
if test "$1" = "BUG"
|
|
|
|
then
|
|
|
|
bug=1
|
|
|
|
shift
|
|
|
|
fi
|
2007-11-10 23:40:58 +00:00
|
|
|
desc=$1
|
|
|
|
script=$2
|
2008-11-04 19:23:41 +00:00
|
|
|
test_count=$(expr $test_count + 1)
|
2008-02-24 18:53:51 +00: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-10 23:40:58 +00:00
|
|
|
res=$?
|
2008-02-24 18:53:51 +00:00
|
|
|
printf "test %d: exitcode=%d\n" $test_count $res >>test-output.log
|
2011-05-22 10:21:31 +00:00
|
|
|
if test $res = 0 -a $bug = 0
|
2007-11-10 23:40:58 +00:00
|
|
|
then
|
2008-02-24 15:05:58 +00:00
|
|
|
printf " %2d) %-60s [ok]\n" $test_count "$desc"
|
2011-05-22 10:21:31 +00: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-10 23:40:58 +00:00
|
|
|
else
|
2008-12-06 11:03:54 +00:00
|
|
|
test_failed=$(expr $test_failed + 1)
|
2008-02-24 15:05:58 +00:00
|
|
|
printf " %2d) %-60s [failed]\n" $test_count "$desc"
|
2007-11-10 23:40:58 +00: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"
|
|
|
|
}
|