]> git.cameronkatri.com Git - cgit.git/blob - tests/setup.sh
tests: use Git's test framework
[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_NO_CREATE_REPO=YesPlease
20 . "$TEST_DIRECTORY"/test-lib.sh
21
22 # Prepend the directory containing cgit to PATH.
23 PATH="$(pwd)/../..:$PATH"
24
25 mkrepo() {
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
49 setup_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
58 virtual-root=/
59 cache-root=$PWD/cache
60
61 cache-size=1021
62 snapshots=tar.gz tar.bz zip
63 enable-log-filecount=1
64 enable-log-linecount=1
65 summary-log=5
66 summary-branches=5
67 summary-tags=5
68 clone-url=git://example.org/\$CGIT_REPO_URL.git
69
70 repo.url=foo
71 repo.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
76 repo.url=bar
77 repo.path=$PWD/repos/bar/.git
78 repo.desc=the bar repo
79
80 repo.url=foo+bar
81 repo.path=$PWD/repos/foo+bar/.git
82 repo.desc=the foo+bar repo
83
84 repo.url=with space
85 repo.path=$PWD/repos/with space/.git
86 repo.desc=spaced repo
87 EOF
88 }
89
90 cgit_query()
91 {
92 CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="$1" cgit
93 }
94
95 cgit_url()
96 {
97 CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit
98 }
99
100 test -z "$CGIT_TEST_NO_CREATE_REPOS" && setup_repos