]> git.cameronkatri.com Git - cgit.git/blob - tests/setup.sh
tests: introduce strip_header() helper function
[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 : ${TEST_DIRECTORY=$(pwd)/../git/t}
19 : ${TEST_OUTPUT_DIRECTORY=$(pwd)}
20 TEST_NO_CREATE_REPO=YesPlease
21 . "$TEST_DIRECTORY"/test-lib.sh
22
23 # Prepend the directory containing cgit to PATH.
24 PATH="$(pwd)/../..:$PATH"
25
26 mkrepo() {
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
50 setup_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
59 virtual-root=/
60 cache-root=$PWD/cache
61
62 cache-size=1021
63 snapshots=tar.gz tar.bz zip
64 enable-log-filecount=1
65 enable-log-linecount=1
66 summary-log=5
67 summary-branches=5
68 summary-tags=5
69 clone-url=git://example.org/\$CGIT_REPO_URL.git
70
71 repo.url=foo
72 repo.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
77 repo.url=bar
78 repo.path=$PWD/repos/bar/.git
79 repo.desc=the bar repo
80
81 repo.url=foo+bar
82 repo.path=$PWD/repos/foo+bar/.git
83 repo.desc=the foo+bar repo
84
85 repo.url=with space
86 repo.path=$PWD/repos/with space/.git
87 repo.desc=spaced repo
88 EOF
89 }
90
91 cgit_query()
92 {
93 CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="$1" cgit
94 }
95
96 cgit_url()
97 {
98 CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit
99 }
100
101 strip_headers () {
102 while read -r line
103 do
104 test -z "$line" && break
105 done
106 cat
107 }
108
109 test -z "$CGIT_TEST_NO_CREATE_REPOS" && setup_repos