blob: 861f48aa55758956531abce28205cf39c3dd9fb5 [file] [log] [blame]
Lars Hjemlib4649fc2007-11-11 00:40:58 +01001# 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
John Keeping1b1974c2013-04-08 20:12:38 +010018# We don't want to run Git commands through Valgrind, so we filter out the
19# --valgrind option here and handle it ourselves. We copy the arguments
20# assuming that none contain a newline, although other whitespace is
21# preserved.
22LF='
23'
24test_argv=
25
26while test $# != 0
27do
28 case "$1" in
29 --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
30 cgit_valgrind=t
31 test_argv="$test_argv${LF}--verbose"
32 ;;
33 *)
34 test_argv="$test_argv$LF$1"
35 ;;
36 esac
37 shift
38done
39
40OLDIFS=$IFS
41IFS=$LF
42set -- $test_argv
43IFS=$OLDIFS
44
John Keepingc95cc5e2013-04-01 15:09:05 +010045: ${TEST_DIRECTORY=$(pwd)/../git/t}
John Keeping31f56fc2013-04-14 17:59:30 +010046: ${TEST_OUTPUT_DIRECTORY=$(pwd)}
John Keepingc95cc5e2013-04-01 15:09:05 +010047TEST_NO_CREATE_REPO=YesPlease
48. "$TEST_DIRECTORY"/test-lib.sh
49
50# Prepend the directory containing cgit to PATH.
John Keeping1b1974c2013-04-08 20:12:38 +010051if test -n "$cgit_valgrind"
52then
53 GIT_VALGRIND="$TEST_DIRECTORY/valgrind"
54 CGIT_VALGRIND=$(cd ../valgrind && pwd)
55 PATH="$CGIT_VALGRIND/bin:$PATH"
56 export GIT_VALGRIND CGIT_VALGRIND
57else
58 PATH="$(pwd)/../..:$PATH"
59fi
Lars Hjemlib4649fc2007-11-11 00:40:58 +010060
Lukas Fleischerce56d892014-01-14 12:01:06 +010061FILTER_DIRECTORY=$(cd ../filters && pwd)
62
Lars Hjemlib4649fc2007-11-11 00:40:58 +010063mkrepo() {
64 name=$1
65 count=$2
John Keepingc95cc5e2013-04-01 15:09:05 +010066 test_create_repo "$name"
67 (
68 cd "$name"
69 n=1
70 while test $n -le $count
71 do
72 echo $n >file-$n
73 git add file-$n
74 git commit -m "commit $n"
75 n=$(expr $n + 1)
76 done
77 if test "$3" = "testplus"
78 then
79 echo "hello" >a+b
80 git add a+b
81 git commit -m "add a+b"
82 git branch "1+2"
83 fi
84 )
Lars Hjemlib4649fc2007-11-11 00:40:58 +010085}
86
87setup_repos()
88{
John Keepingc95cc5e2013-04-01 15:09:05 +010089 rm -rf cache
90 mkdir -p cache
91 mkrepo repos/foo 5 >/dev/null
92 mkrepo repos/bar 50 >/dev/null
93 mkrepo repos/foo+bar 10 testplus >/dev/null
94 mkrepo "repos/with space" 2 >/dev/null
Lukas Fleischerce56d892014-01-14 12:01:06 +010095 mkrepo repos/filter 5 testplus >/dev/null
John Keepingc95cc5e2013-04-01 15:09:05 +010096 cat >cgitrc <<EOF
Lars Hjemlib4649fc2007-11-11 00:40:58 +010097virtual-root=/
John Keepingc95cc5e2013-04-01 15:09:05 +010098cache-root=$PWD/cache
Lars Hjemlib4649fc2007-11-11 00:40:58 +010099
Lars Hjemli939d32f2008-04-28 11:32:42 +0200100cache-size=1021
Lars Hjemlib4649fc2007-11-11 00:40:58 +0100101snapshots=tar.gz tar.bz zip
102enable-log-filecount=1
103enable-log-linecount=1
104summary-log=5
105summary-branches=5
106summary-tags=5
Lars Hjemlia1429db2011-06-06 20:49:13 +0000107clone-url=git://example.org/\$CGIT_REPO_URL.git
Lukas Fleischerce56d892014-01-14 12:01:06 +0100108enable-filter-overrides=1
Lars Hjemlib4649fc2007-11-11 00:40:58 +0100109
110repo.url=foo
John Keepingc95cc5e2013-04-01 15:09:05 +0100111repo.path=$PWD/repos/foo/.git
Lars Hjemli19134112008-02-24 15:27:33 +0100112# Do not specify a description for this repo, as it then will be assigned
113# the constant value "[no description]" (which actually used to cause a
114# segfault).
Lars Hjemlib4649fc2007-11-11 00:40:58 +0100115
116repo.url=bar
John Keepingc95cc5e2013-04-01 15:09:05 +0100117repo.path=$PWD/repos/bar/.git
Lars Hjemlib4649fc2007-11-11 00:40:58 +0100118repo.desc=the bar repo
Lars Hjemlib5751152008-10-05 12:52:25 +0200119
120repo.url=foo+bar
John Keepingc95cc5e2013-04-01 15:09:05 +0100121repo.path=$PWD/repos/foo+bar/.git
Lars Hjemlib5751152008-10-05 12:52:25 +0200122repo.desc=the foo+bar repo
Lars Hjemli084ca502011-05-22 12:22:56 +0200123
124repo.url=with space
John Keepingc95cc5e2013-04-01 15:09:05 +0100125repo.path=$PWD/repos/with space/.git
Lars Hjemli084ca502011-05-22 12:22:56 +0200126repo.desc=spaced repo
Lukas Fleischerce56d892014-01-14 12:01:06 +0100127
128repo.url=filter
129repo.path=$PWD/repos/filter/.git
130repo.desc=filtered repo
131repo.about-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
132repo.commit-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
133repo.email-filter=exec:$FILTER_DIRECTORY/capitalize-argv1.sh
134repo.source-filter=exec:$FILTER_DIRECTORY/capitalize-stdin.sh
135repo.readme=master:a+b
Lars Hjemlib4649fc2007-11-11 00:40:58 +0100136EOF
137}
138
Lars Hjemlib4649fc2007-11-11 00:40:58 +0100139cgit_query()
140{
John Keepingc95cc5e2013-04-01 15:09:05 +0100141 CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="$1" cgit
Lars Hjemlib4649fc2007-11-11 00:40:58 +0100142}
143
144cgit_url()
145{
John Keepingc95cc5e2013-04-01 15:09:05 +0100146 CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit
Lars Hjemlib4649fc2007-11-11 00:40:58 +0100147}
John Keepingc95cc5e2013-04-01 15:09:05 +0100148
John Keeping75bfec62013-05-18 18:46:38 +0100149strip_headers () {
150 while read -r line
151 do
152 test -z "$line" && break
153 done
154 cat
155}
156
John Keepingc95cc5e2013-04-01 15:09:05 +0100157test -z "$CGIT_TEST_NO_CREATE_REPOS" && setup_repos