]> gitweb.ps.run Git - ps-cgit/blob - tests/setup.sh
authors: specify maintainers
[ps-cgit] / tests / setup.sh
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 # 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.
22 LF='
23 '
24 test_argv=
25
26 while test $# != 0
27 do
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
38 done
39
40 OLDIFS=$IFS
41 IFS=$LF
42 set -- $test_argv
43 IFS=$OLDIFS
44
45 : ${TEST_DIRECTORY=$(pwd)/../git/t}
46 : ${TEST_OUTPUT_DIRECTORY=$(pwd)}
47 TEST_NO_CREATE_REPO=YesPlease
48 . "$TEST_DIRECTORY"/test-lib.sh
49
50 # Prepend the directory containing cgit to PATH.
51 if test -n "$cgit_valgrind"
52 then
53         GIT_VALGRIND="$TEST_DIRECTORY/valgrind"
54         CGIT_VALGRIND=$(cd ../valgrind && pwd)
55         PATH="$CGIT_VALGRIND/bin:$PATH"
56         export GIT_VALGRIND CGIT_VALGRIND
57 else
58         PATH="$(pwd)/../..:$PATH"
59 fi
60
61 mkrepo() {
62         name=$1
63         count=$2
64         test_create_repo "$name"
65         (
66                 cd "$name"
67                 n=1
68                 while test $n -le $count
69                 do
70                         echo $n >file-$n
71                         git add file-$n
72                         git commit -m "commit $n"
73                         n=$(expr $n + 1)
74                 done
75                 if test "$3" = "testplus"
76                 then
77                         echo "hello" >a+b
78                         git add a+b
79                         git commit -m "add a+b"
80                         git branch "1+2"
81                 fi
82         )
83 }
84
85 setup_repos()
86 {
87         rm -rf cache
88         mkdir -p cache
89         mkrepo repos/foo 5 >/dev/null
90         mkrepo repos/bar 50 >/dev/null
91         mkrepo repos/foo+bar 10 testplus >/dev/null
92         mkrepo "repos/with space" 2 >/dev/null
93         cat >cgitrc <<EOF
94 virtual-root=/
95 cache-root=$PWD/cache
96
97 cache-size=1021
98 snapshots=tar.gz tar.bz zip
99 enable-log-filecount=1
100 enable-log-linecount=1
101 summary-log=5
102 summary-branches=5
103 summary-tags=5
104 clone-url=git://example.org/\$CGIT_REPO_URL.git
105
106 repo.url=foo
107 repo.path=$PWD/repos/foo/.git
108 # Do not specify a description for this repo, as it then will be assigned
109 # the constant value "[no description]" (which actually used to cause a
110 # segfault).
111
112 repo.url=bar
113 repo.path=$PWD/repos/bar/.git
114 repo.desc=the bar repo
115
116 repo.url=foo+bar
117 repo.path=$PWD/repos/foo+bar/.git
118 repo.desc=the foo+bar repo
119
120 repo.url=with space
121 repo.path=$PWD/repos/with space/.git
122 repo.desc=spaced repo
123 EOF
124 }
125
126 cgit_query()
127 {
128         CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="$1" cgit
129 }
130
131 cgit_url()
132 {
133         CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit
134 }
135
136 strip_headers () {
137         while read -r line
138         do
139                 test -z "$line" && break
140         done
141         cat
142 }
143
144 test -z "$CGIT_TEST_NO_CREATE_REPOS" && setup_repos