]> git.cameronkatri.com Git - cgit.git/blob - tests/setup.sh
git: update to v2.32.0
[cgit.git] / 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 FILTER_DIRECTORY=$(cd ../filters && pwd)
62
63 if cgit --version | grep -F -q "[+] Lua scripting"; then
64 export CGIT_HAS_LUA=1
65 else
66 export CGIT_HAS_LUA=0
67 fi
68
69 mkrepo() {
70 name=$1
71 count=$2
72 test_create_repo "$name"
73 (
74 cd "$name"
75 n=1
76 while test $n -le $count
77 do
78 echo $n >file-$n
79 git add file-$n
80 git commit -m "commit $n"
81 n=$(expr $n + 1)
82 done
83 case "$3" in
84 testplus)
85 echo "hello" >a+b
86 git add a+b
87 git commit -m "add a+b"
88 git branch "1+2"
89 ;;
90 commit-graph)
91 git commit-graph write
92 ;;
93 esac
94 )
95 }
96
97 setup_repos()
98 {
99 rm -rf cache
100 mkdir -p cache
101 mkrepo repos/foo 5 >/dev/null
102 mkrepo repos/bar 50 commit-graph >/dev/null
103 mkrepo repos/foo+bar 10 testplus >/dev/null
104 mkrepo "repos/with space" 2 >/dev/null
105 mkrepo repos/filter 5 testplus >/dev/null
106 cat >cgitrc <<EOF
107 virtual-root=/
108 cache-root=$PWD/cache
109
110 cache-size=1021
111 snapshots=tar.gz tar.bz tar.lz tar.xz tar.zst zip
112 enable-log-filecount=1
113 enable-log-linecount=1
114 summary-log=5
115 summary-branches=5
116 summary-tags=5
117 clone-url=git://example.org/\$CGIT_REPO_URL.git
118 enable-filter-overrides=1
119
120 repo.url=foo
121 repo.path=$PWD/repos/foo/.git
122 # Do not specify a description for this repo, as it then will be assigned
123 # the constant value "[no description]" (which actually used to cause a
124 # segfault).
125
126 repo.url=bar
127 repo.path=$PWD/repos/bar/.git
128 repo.desc=the bar repo
129
130 repo.url=foo+bar
131 repo.path=$PWD/repos/foo+bar/.git
132 repo.desc=the foo+bar repo
133
134 repo.url=with space
135 repo.path=$PWD/repos/with space/.git
136 repo.desc=spaced repo
137
138 repo.url=filter-exec
139 repo.path=$PWD/repos/filter/.git
140 repo.desc=filtered repo
141 repo.about-filter=exec:$FILTER_DIRECTORY/dump.sh
142 repo.commit-filter=exec:$FILTER_DIRECTORY/dump.sh
143 repo.email-filter=exec:$FILTER_DIRECTORY/dump.sh
144 repo.source-filter=exec:$FILTER_DIRECTORY/dump.sh
145 repo.readme=master:a+b
146 EOF
147
148 if [ $CGIT_HAS_LUA -eq 1 ]; then
149 cat >>cgitrc <<EOF
150 repo.url=filter-lua
151 repo.path=$PWD/repos/filter/.git
152 repo.desc=filtered repo
153 repo.about-filter=lua:$FILTER_DIRECTORY/dump.lua
154 repo.commit-filter=lua:$FILTER_DIRECTORY/dump.lua
155 repo.email-filter=lua:$FILTER_DIRECTORY/dump.lua
156 repo.source-filter=lua:$FILTER_DIRECTORY/dump.lua
157 repo.readme=master:a+b
158 EOF
159 fi
160 }
161
162 cgit_query()
163 {
164 CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="$1" cgit
165 }
166
167 cgit_url()
168 {
169 CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit
170 }
171
172 strip_headers() {
173 while read -r line
174 do
175 test -z "$line" && break
176 done
177 cat
178 }
179
180 test -z "$CGIT_TEST_NO_CREATE_REPOS" && setup_repos