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}
19TEST_NO_CREATE_REPO=YesPlease
20. "$TEST_DIRECTORY"/test-lib.sh
21
22# Prepend the directory containing cgit to PATH.
23PATH="$(pwd)/../..:$PATH"
24
25mkrepo() {
26 name=$1
27 count=$2
28 test_create_repo "$name"
29 (
30 cd "$name"
31 n=1
32 while test $n -le $count
33 do
34 echo $n >file-$n
35 git add file-$n
36 git commit -m "commit $n"
37 n=$(expr $n + 1)
38 done
39 if test "$3" = "testplus"
40 then
41 echo "hello" >a+b
42 git add a+b
43 git commit -m "add a+b"
44 git branch "1+2"
45 fi
46 )
47}
48
49setup_repos()
50{
51 rm -rf cache
52 mkdir -p cache
53 mkrepo repos/foo 5 >/dev/null
54 mkrepo repos/bar 50 >/dev/null
55 mkrepo repos/foo+bar 10 testplus >/dev/null
56 mkrepo "repos/with space" 2 >/dev/null
57 cat >cgitrc <<EOF
58virtual-root=/
59cache-root=$PWD/cache
60
61cache-size=1021
62snapshots=tar.gz tar.bz zip
63enable-log-filecount=1
64enable-log-linecount=1
65summary-log=5
66summary-branches=5
67summary-tags=5
68clone-url=git://example.org/\$CGIT_REPO_URL.git
69
70repo.url=foo
71repo.path=$PWD/repos/foo/.git
72# Do not specify a description for this repo, as it then will be assigned
73# the constant value "[no description]" (which actually used to cause a
74# segfault).
75
76repo.url=bar
77repo.path=$PWD/repos/bar/.git
78repo.desc=the bar repo
79
80repo.url=foo+bar
81repo.path=$PWD/repos/foo+bar/.git
82repo.desc=the foo+bar repo
83
84repo.url=with space
85repo.path=$PWD/repos/with space/.git
86repo.desc=spaced repo
87EOF
88}
89
90cgit_query()
91{
92 CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="$1" cgit
93}
94
95cgit_url()
96{
97 CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit
98}
99
100test -z "$CGIT_TEST_NO_CREATE_REPOS" && setup_repos