Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 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 | |
John Keeping | 1b1974c | 2013-04-08 20:12:38 +0100 | [diff] [blame] | 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 | |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 45 | : ${TEST_DIRECTORY=$(pwd)/../git/t} |
John Keeping | 31f56fc | 2013-04-14 17:59:30 +0100 | [diff] [blame] | 46 | : ${TEST_OUTPUT_DIRECTORY=$(pwd)} |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 47 | TEST_NO_CREATE_REPO=YesPlease |
| 48 | . "$TEST_DIRECTORY"/test-lib.sh |
| 49 | |
| 50 | # Prepend the directory containing cgit to PATH. |
John Keeping | 1b1974c | 2013-04-08 20:12:38 +0100 | [diff] [blame] | 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 |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 60 | |
Lukas Fleischer | ce56d89 | 2014-01-14 12:01:06 +0100 | [diff] [blame] | 61 | FILTER_DIRECTORY=$(cd ../filters && pwd) |
| 62 | |
Jason A. Donenfeld | f759cc0 | 2014-01-20 13:11:10 +0100 | [diff] [blame] | 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 | |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 69 | mkrepo() { |
| 70 | name=$1 |
| 71 | count=$2 |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 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 | if test "$3" = "testplus" |
| 84 | then |
| 85 | echo "hello" >a+b |
| 86 | git add a+b |
| 87 | git commit -m "add a+b" |
| 88 | git branch "1+2" |
| 89 | fi |
| 90 | ) |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | setup_repos() |
| 94 | { |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 95 | rm -rf cache |
| 96 | mkdir -p cache |
| 97 | mkrepo repos/foo 5 >/dev/null |
| 98 | mkrepo repos/bar 50 >/dev/null |
| 99 | mkrepo repos/foo+bar 10 testplus >/dev/null |
| 100 | mkrepo "repos/with space" 2 >/dev/null |
Lukas Fleischer | ce56d89 | 2014-01-14 12:01:06 +0100 | [diff] [blame] | 101 | mkrepo repos/filter 5 testplus >/dev/null |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 102 | cat >cgitrc <<EOF |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 103 | virtual-root=/ |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 104 | cache-root=$PWD/cache |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 105 | |
Lars Hjemli | 939d32f | 2008-04-28 11:32:42 +0200 | [diff] [blame] | 106 | cache-size=1021 |
Christian Hesse | 892ba8c | 2020-02-26 09:12:21 +0100 | [diff] [blame] | 107 | snapshots=tar.gz tar.bz tar.lz tar.xz tar.zst zip |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 108 | enable-log-filecount=1 |
| 109 | enable-log-linecount=1 |
| 110 | summary-log=5 |
| 111 | summary-branches=5 |
| 112 | summary-tags=5 |
Lars Hjemli | a1429db | 2011-06-06 20:49:13 +0000 | [diff] [blame] | 113 | clone-url=git://example.org/\$CGIT_REPO_URL.git |
Lukas Fleischer | ce56d89 | 2014-01-14 12:01:06 +0100 | [diff] [blame] | 114 | enable-filter-overrides=1 |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 115 | |
| 116 | repo.url=foo |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 117 | repo.path=$PWD/repos/foo/.git |
Lars Hjemli | 1913411 | 2008-02-24 15:27:33 +0100 | [diff] [blame] | 118 | # Do not specify a description for this repo, as it then will be assigned |
| 119 | # the constant value "[no description]" (which actually used to cause a |
| 120 | # segfault). |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 121 | |
| 122 | repo.url=bar |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 123 | repo.path=$PWD/repos/bar/.git |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 124 | repo.desc=the bar repo |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 125 | |
| 126 | repo.url=foo+bar |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 127 | repo.path=$PWD/repos/foo+bar/.git |
Lars Hjemli | b575115 | 2008-10-05 12:52:25 +0200 | [diff] [blame] | 128 | repo.desc=the foo+bar repo |
Lars Hjemli | 084ca50 | 2011-05-22 12:22:56 +0200 | [diff] [blame] | 129 | |
| 130 | repo.url=with space |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 131 | repo.path=$PWD/repos/with space/.git |
Lars Hjemli | 084ca50 | 2011-05-22 12:22:56 +0200 | [diff] [blame] | 132 | repo.desc=spaced repo |
Lukas Fleischer | ce56d89 | 2014-01-14 12:01:06 +0100 | [diff] [blame] | 133 | |
Lukas Fleischer | caf557a | 2014-01-14 22:25:45 +0100 | [diff] [blame] | 134 | repo.url=filter-exec |
Lukas Fleischer | ce56d89 | 2014-01-14 12:01:06 +0100 | [diff] [blame] | 135 | repo.path=$PWD/repos/filter/.git |
| 136 | repo.desc=filtered repo |
Lukas Fleischer | 3741254 | 2014-01-15 23:11:19 +0100 | [diff] [blame] | 137 | repo.about-filter=exec:$FILTER_DIRECTORY/dump.sh |
| 138 | repo.commit-filter=exec:$FILTER_DIRECTORY/dump.sh |
| 139 | repo.email-filter=exec:$FILTER_DIRECTORY/dump.sh |
| 140 | repo.source-filter=exec:$FILTER_DIRECTORY/dump.sh |
Lukas Fleischer | ce56d89 | 2014-01-14 12:01:06 +0100 | [diff] [blame] | 141 | repo.readme=master:a+b |
Jason A. Donenfeld | f759cc0 | 2014-01-20 13:11:10 +0100 | [diff] [blame] | 142 | EOF |
Lukas Fleischer | caf557a | 2014-01-14 22:25:45 +0100 | [diff] [blame] | 143 | |
Jason A. Donenfeld | f759cc0 | 2014-01-20 13:11:10 +0100 | [diff] [blame] | 144 | if [ $CGIT_HAS_LUA -eq 1 ]; then |
| 145 | cat >>cgitrc <<EOF |
Lukas Fleischer | caf557a | 2014-01-14 22:25:45 +0100 | [diff] [blame] | 146 | repo.url=filter-lua |
| 147 | repo.path=$PWD/repos/filter/.git |
| 148 | repo.desc=filtered repo |
Lukas Fleischer | 3741254 | 2014-01-15 23:11:19 +0100 | [diff] [blame] | 149 | repo.about-filter=lua:$FILTER_DIRECTORY/dump.lua |
| 150 | repo.commit-filter=lua:$FILTER_DIRECTORY/dump.lua |
| 151 | repo.email-filter=lua:$FILTER_DIRECTORY/dump.lua |
| 152 | repo.source-filter=lua:$FILTER_DIRECTORY/dump.lua |
Lukas Fleischer | caf557a | 2014-01-14 22:25:45 +0100 | [diff] [blame] | 153 | repo.readme=master:a+b |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 154 | EOF |
Jason A. Donenfeld | f759cc0 | 2014-01-20 13:11:10 +0100 | [diff] [blame] | 155 | fi |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 156 | } |
| 157 | |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 158 | cgit_query() |
| 159 | { |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 160 | CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="$1" cgit |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | cgit_url() |
| 164 | { |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 165 | CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit |
Lars Hjemli | b4649fc | 2007-11-11 00:40:58 +0100 | [diff] [blame] | 166 | } |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 167 | |
Jason A. Donenfeld | f759cc0 | 2014-01-20 13:11:10 +0100 | [diff] [blame] | 168 | strip_headers() { |
John Keeping | 75bfec6 | 2013-05-18 18:46:38 +0100 | [diff] [blame] | 169 | while read -r line |
| 170 | do |
| 171 | test -z "$line" && break |
| 172 | done |
| 173 | cat |
| 174 | } |
| 175 | |
John Keeping | c95cc5e | 2013-04-01 15:09:05 +0100 | [diff] [blame] | 176 | test -z "$CGIT_TEST_NO_CREATE_REPOS" && setup_repos |