diff options
Diffstat (limited to 'tests/setup.sh')
| -rwxr-xr-x | tests/setup.sh | 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 29 insertions, 27 deletions
diff --git a/tests/setup.sh b/tests/setup.sh index 39819e4..93a663a 100755 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -1,24 +1,15 @@ -# This file should be sourced by all test-scripts -# -# Main functions: -# prepare_tests(description) - setup for testing, i.e. create repos+config -# run_test(description, script) - run one test, i.e. eval script -# -# Helper functions -# cgit_query(querystring) - call cgit with the specified querystring -# cgit_url(url) - call cgit with the specified virtual url -# -# Example script: -# -# . setup.sh -# prepare_tests "html validation" -# run_test 'repo index' 'cgit_url "/" | tidy -e' -# run_test 'repo summary' 'cgit_url "/foo" | tidy -e' +# Shared groundwork sourced by every test script. It builds a handful of small +# repositories under repos/ and writes a cgitrc pointing at them, then offers +# the helpers that ask cgit for a page so a test only has to look at what comes +# back. Sourcing it also brings in the test library from the bundled Git tree, +# which is where test_expect_success and the trash directory come from. Set +# CGIT_TEST_NO_CREATE_REPOS to get the helpers without paying for the fixtures. -# We don't want to run Git commands through Valgrind, so we filter out the -# --valgrind option here and handle it ourselves. We copy the arguments -# assuming that none contain a newline, although other whitespace is -# preserved. +# The Git test library would run every Git command under Valgrind if it saw +# --valgrind, and only cgit itself is worth watching, so the option is taken out +# here and acted on further down. The arguments are carried across as a newline +# separated list, which keeps any other whitespace in them intact but assumes +# that none holds a newline of its own. LF=' ' test_argv= @@ -44,10 +35,13 @@ IFS=$OLDIFS : ${TEST_DIRECTORY=$(pwd)/../vendor/git/t} : ${TEST_OUTPUT_DIRECTORY=$(pwd)} +# The library would otherwise leave a repository of its own in the trash +# directory, and every repository these tests want is built by mkrepo below. TEST_NO_CREATE_REPO=YesPlease . "$TEST_DIRECTORY"/test-lib.sh -# Prepend the directory containing cgit to PATH. +# The tests run cgit by name, so the binary just built has to come ahead of any +# copy already installed. Under Valgrind the wrappers take that place instead. if test -n "$cgit_valgrind" then GIT_VALGRIND="$TEST_DIRECTORY/valgrind" @@ -60,27 +54,33 @@ fi FILTER_DIRECTORY=$(cd ../filters && pwd) +# Lua filters only work when cgit was compiled with Lua, so the tests that use +# them have to ask the binary rather than assume. if cgit --version | grep -F -q "[+] Lua scripting"; then export CGIT_HAS_LUA=1 else export CGIT_HAS_LUA=0 fi +# Creates a repository holding the given number of one file commits. A third +# argument asks for a variant, either testplus for a file and a branch whose +# names have to be escaped in a URL, or commit-graph for a written commit graph. mkrepo() { - name=$1 - count=$2 - test_create_repo "$name" + repo=$1 + commits=$2 + variant=$3 + test_create_repo "$repo" ( - cd "$name" + cd "$repo" n=1 - while test $n -le $count + while test $n -le $commits do echo $n >file-$n git add file-$n git commit -m "commit $n" n=$(expr $n + 1) done - case "$3" in + case "$variant" in testplus) echo "hello" >a+b git add a+b @@ -170,6 +170,8 @@ cgit_url() CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit } +# The response headers run down to the first empty line, and a test comparing +# two pages wants to see the bodies alone. strip_headers() { while read -r line do |
