# 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. # The Git test library would run every Git command under Valgrind if it saw # --valgrind, and only cgit is worth watching, so the option is taken out # here and acted on further down. LF=' ' # Trash directories are collected under one trash/, which keeps the ignore # and clean rules to a single name. Seeded ahead of the real arguments so # one given on the command line still wins. test_argv="${LF}--root=trash" while test $# != 0 do case "$1" in --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind) cgit_valgrind=t test_argv="$test_argv${LF}--verbose" ;; *) test_argv="$test_argv$LF$1" ;; esac shift done OLDIFS=$IFS IFS=$LF set -- $test_argv 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 # The library spells its results directory test-results and derives these # variables before it can be told otherwise, so they are re-pointed at the # plainer results/. The --tee and --stress raw logs write earlier and keep # the library's name. TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/results" TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME$TEST_STRESS_JOB_SFX" TEST_RESULTS_SAN_DIR="$TEST_RESULTS_BASE.$TEST_RESULTS_SAN_DIR_SFX" # The library has moved into the trash directory by now, so paths outside # it are anchored to TEST_OUTPUT_DIRECTORY. # 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" CGIT_VALGRIND=$(cd "$TEST_OUTPUT_DIRECTORY/valgrind" && pwd) PATH="$CGIT_VALGRIND/bin:$PATH" export GIT_VALGRIND CGIT_VALGRIND else PATH="$TEST_OUTPUT_DIRECTORY/../build:$PATH" fi FILTER_DIRECTORY=$(cd "$TEST_OUTPUT_DIRECTORY/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() { repo=$1 commits=$2 variant=$3 test_create_repo "$repo" ( cd "$repo" n=1 while test $n -le $commits do echo $n >file-$n git add file-$n git commit -m "commit $n" n=$((n + 1)) done case "$variant" in testplus) echo "hello" >a+b git add a+b git commit -m "add a+b" git branch "1+2" ;; commit-graph) git commit-graph write ;; esac ) } setup_repos() { rm -rf cache mkdir -p cache mkrepo repos/foo 5 >/dev/null mkrepo repos/bar 50 commit-graph >/dev/null mkrepo repos/foo+bar 10 testplus >/dev/null mkrepo "repos/with space" 2 >/dev/null mkrepo repos/filter 5 testplus >/dev/null cat >cgitrc <>cgitrc <