all repos — cgit @ 382ecf152e1bd9546f6c84ace71c62ca07f6648b

a hyperfast web frontend for git written in c

tests/setup.sh (view raw)

  1# This file should be sourced by all test-scripts
  2#
  3# Main functions:
  4#   prepare_tests(description) - setup for testing, i.e. create repos+config
  5#   run_test(description, script) - run one test, i.e. eval script
  6#
  7# Helper functions
  8#   cgit_query(querystring) - call cgit with the specified querystring
  9#   cgit_url(url) - call cgit with the specified virtual url
 10#
 11# Example script:
 12#
 13# . setup.sh
 14# prepare_tests "html validation"
 15# run_test 'repo index' 'cgit_url "/" | tidy -e'
 16# run_test 'repo summary' 'cgit_url "/foo" | tidy -e'
 17
 18: ${TEST_DIRECTORY=$(pwd)/../git/t}
 19: ${TEST_OUTPUT_DIRECTORY=$(pwd)}
 20TEST_NO_CREATE_REPO=YesPlease
 21. "$TEST_DIRECTORY"/test-lib.sh
 22
 23# Prepend the directory containing cgit to PATH.
 24PATH="$(pwd)/../..:$PATH"
 25
 26mkrepo() {
 27	name=$1
 28	count=$2
 29	test_create_repo "$name"
 30	(
 31		cd "$name"
 32		n=1
 33		while test $n -le $count
 34		do
 35			echo $n >file-$n
 36			git add file-$n
 37			git commit -m "commit $n"
 38			n=$(expr $n + 1)
 39		done
 40		if test "$3" = "testplus"
 41		then
 42			echo "hello" >a+b
 43			git add a+b
 44			git commit -m "add a+b"
 45			git branch "1+2"
 46		fi
 47	)
 48}
 49
 50setup_repos()
 51{
 52	rm -rf cache
 53	mkdir -p cache
 54	mkrepo repos/foo 5 >/dev/null
 55	mkrepo repos/bar 50 >/dev/null
 56	mkrepo repos/foo+bar 10 testplus >/dev/null
 57	mkrepo "repos/with space" 2 >/dev/null
 58	cat >cgitrc <<EOF
 59virtual-root=/
 60cache-root=$PWD/cache
 61
 62cache-size=1021
 63snapshots=tar.gz tar.bz zip
 64enable-log-filecount=1
 65enable-log-linecount=1
 66summary-log=5
 67summary-branches=5
 68summary-tags=5
 69clone-url=git://example.org/\$CGIT_REPO_URL.git
 70
 71repo.url=foo
 72repo.path=$PWD/repos/foo/.git
 73# Do not specify a description for this repo, as it then will be assigned
 74# the constant value "[no description]" (which actually used to cause a
 75# segfault).
 76
 77repo.url=bar
 78repo.path=$PWD/repos/bar/.git
 79repo.desc=the bar repo
 80
 81repo.url=foo+bar
 82repo.path=$PWD/repos/foo+bar/.git
 83repo.desc=the foo+bar repo
 84
 85repo.url=with space
 86repo.path=$PWD/repos/with space/.git
 87repo.desc=spaced repo
 88EOF
 89}
 90
 91cgit_query()
 92{
 93	CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="$1" cgit
 94}
 95
 96cgit_url()
 97{
 98	CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit
 99}
100
101strip_headers () {
102	while read -r line
103	do
104		test -z "$line" && break
105	done
106	cat
107}
108
109test -z "$CGIT_TEST_NO_CREATE_REPOS" && setup_repos