Diff options
authorBryce Kwon <bryce@brycekwon.com>
committerBryce Kwon <bryce@brycekwon.com>
commit
parent
tree
download
Add the shared config writers and cgit_rc
The helpers are named by kind. cgitrc_repo and cgitrc_copy write the config file named first, and cgit_url, cgit_query and cgit_rc run cgit, each named after what it is handed first. A repository copies its defaults from the globals read before its repo.url, so cgitrc_repo places every setting itself, and a global can no longer land where it silently stops applying. The t00xx and t01xx files move to them here.
Diffstat (limited to '')
-rwxr-xr-xtests/setup.sh61
-rwxr-xr-xtests/t0002-html-validity.sh11
-rwxr-xr-xtests/t0003-cache.sh46
-rwxr-xr-xtests/t0005-markup.sh74
-rwxr-xr-xtests/t0006-nolua.sh7
-rwxr-xr-xtests/t0101-index.sh20
-rwxr-xr-xtests/t0102-summary.sh20
-rwxr-xr-xtests/t0103-log.sh28
-rwxr-xr-xtests/t0104-tree.sh60
-rwxr-xr-xtests/t0105-plain.sh16
-rwxr-xr-xtests/t0107-diff.sh18
-rwxr-xr-xtests/t0109-patch.sh4
-rwxr-xr-xtests/t0110-snapshot.sh38
-rwxr-xr-xtests/t0111-atom.sh10
-rwxr-xr-xtests/t0112-stats.sh50
15 files changed, 188 insertions, 275 deletions
diff --git a/tests/setup.sh b/tests/setup.sh
index 9f17778..92451b7 100755
--- a/tests/setup.sh
+++ b/tests/setup.sh
@@ -1,9 +1,10 @@
# 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 helpers that write a config of a test's own and 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.
LF='
'
@@ -168,12 +169,60 @@ EOF
fi
}
+# Writes a config to the file named first that serves repos/<url> under the
+# url named second, with the cache off and links rooted at /, and takes the
+# rest as settings. A repository copies its defaults from the global settings
+# read before its repo.url, so whatever order they come in, the repo.* ones
+# go after the repository and all others ahead of it. A repo.path setting
+# names a repository kept somewhere else.
+cgitrc_repo() {
+ cgitrc_file=$1
+ cgitrc_url=$2
+ shift 2
+ cgitrc_path="repo.path=$PWD/repos/$cgitrc_url/.git"
+ cgitrc_before=
+ cgitrc_after=
+ for cgitrc_setting
+ do
+ case "$cgitrc_setting" in
+ repo.path=*)
+ cgitrc_path=$cgitrc_setting
+ ;;
+ repo.*)
+ cgitrc_after="$cgitrc_after$cgitrc_setting$LF"
+ ;;
+ *)
+ cgitrc_before="$cgitrc_before$cgitrc_setting$LF"
+ ;;
+ esac
+ done
+ printf '%s' "virtual-root=/$LF" "cache-size=0$LF" "$cgitrc_before" \
+ "repo.url=$cgitrc_url$LF" "$cgitrc_path$LF" "$cgitrc_after" >"$cgitrc_file"
+}
+
+# Writes the global settings named after the file ahead of a copy of the
+# shared cgitrc. The copy turns the cache off, because a page is cached under
+# its request alone and would otherwise come back as the shared config made
+# it.
+cgitrc_copy() {
+ cgitrc_file=$1
+ shift
+ {
+ test $# = 0 || printf '%s\n' "$@"
+ sed "s/^cache-size=.*/cache-size=0/" cgitrc
+ } >"$cgitrc_file"
+}
+
+cgit_rc() {
+ CGIT_CONFIG="$PWD/$1" QUERY_STRING="$2" cgit
+}
+
cgit_query() {
- CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="$1" cgit
+ cgit_rc cgitrc "$1"
}
cgit_url() {
- CGIT_CONFIG="$PWD/cgitrc" QUERY_STRING="url=$1" cgit
+ cgit_rc cgitrc "url=$1"
}
# The response headers run down to the first empty line, and a test comparing
diff --git a/tests/t0002-html-validity.sh b/tests/t0002-html-validity.sh
index b9020d6..bdccaf2 100755
--- a/tests/t0002-html-validity.sh
+++ b/tests/t0002-html-validity.sh
@@ -11,7 +11,7 @@ test_description='Validate html with tidy'
test_url() {
# A second argument names a config of its own, for pages the shared
# config keeps turned off.
- CGIT_CONFIG="$PWD/${2:-cgitrc}" QUERY_STRING="url=$1" cgit >tidy-$test_count.tmp || return
+ cgit_rc "${2:-cgitrc}" "url=$1" >tidy-$test_count.tmp || return
# Tidy reads what it is given as a whole document, so the response
# headers are dropped before it sees the page.
strip_headers <tidy-$test_count.tmp >tidy-$test_count || return
@@ -49,14 +49,7 @@ test_expect_success 'error page' 'test_url "no-such-repo"'
# Stats and blame stay off in the shared config, so their pages validate
# through a config of their own.
test_expect_success 'set up a features config' '
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "max-stats=year" &&
- echo "enable-blame=1" &&
- echo "repo.url=feat" &&
- echo "repo.path=$PWD/repos/foo/.git"
- } >featrc
+ cgitrc_repo featrc feat max-stats=year enable-blame=1 "repo.path=$PWD/repos/foo/.git"
'
test_expect_success 'stats page' 'test_url "feat/stats/" featrc'
diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh
index 17816c3..ec88046 100755
--- a/tests/t0003-cache.sh
+++ b/tests/t0003-cache.sh
@@ -77,9 +77,9 @@ test_expect_success 'set up a repo with a page larger than the output buffer' '
'
test_expect_success 'the first request fills the slot and the second replays it' '
- CGIT_CONFIG="$PWD/bigrc" QUERY_STRING="url=bigpage/tree/big.txt" cgit >big.first &&
+ cgit_rc bigrc "url=bigpage/tree/big.txt" >big.first &&
test $(wc -c <big.first) -gt 65536 &&
- CGIT_CONFIG="$PWD/bigrc" QUERY_STRING="url=bigpage/tree/big.txt" cgit >big.second &&
+ cgit_rc bigrc "url=bigpage/tree/big.txt" >big.second &&
strip_headers <big.first >big.first.body &&
strip_headers <big.second >big.second.body &&
test_cmp big.first.body big.second.body
@@ -87,7 +87,7 @@ test_expect_success 'the first request fills the slot and the second replays it'
test_expect_success 'the cached body matches one generated with the cache off' '
sed -e "s/^cache-size=64$/cache-size=0/" bigrc >bignocache &&
- CGIT_CONFIG="$PWD/bignocache" QUERY_STRING="url=bigpage/tree/big.txt" cgit >big.nocache &&
+ cgit_rc bignocache "url=bigpage/tree/big.txt" >big.nocache &&
strip_headers <big.nocache >big.nocache.body &&
test_cmp big.nocache.body big.second.body
'
@@ -104,14 +104,14 @@ test_expect_success 'an over-long cache key leaves no slot behind' '
rm -rf cache3 && mkdir cache3 &&
sed -e "s|^cache-root=.*|cache-root=$PWD/cache3|" bigrc >bigkeyrc &&
long=$(awk "BEGIN{s=\"\";for(i=0;i<6000;i++)s=s \"k\"; print s}") &&
- CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/&q=$long" cgit >key.out 2>/dev/null &&
+ cgit_rc bigkeyrc "url=bigpage/&q=$long" >key.out 2>/dev/null &&
grep "</html>" key.out &&
test_dir_is_empty cache3
'
test_expect_success 'an ordinary key still fills a slot' '
rm -rf cache3 && mkdir cache3 &&
- CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/" cgit >/dev/null &&
+ cgit_rc bigkeyrc "url=bigpage/" >/dev/null &&
ls cache3 >key.slots &&
test_line_count = 1 key.slots
'
@@ -137,7 +137,7 @@ test_expect_success 'set up a repo missing a parent object' '
'
test_expect_success 'an error after output began ends the page with it and caches nothing' '
- CGIT_CONFIG="$PWD/brokenrc" QUERY_STRING="url=broken/commit/&id=$tip" cgit >broken.out &&
+ cgit_rc brokenrc "url=broken/commit/&id=$tip" >broken.out &&
grep "Not a commit" broken.out &&
test $(grep -c "^Status:" broken.out) = 1 &&
test_dir_is_empty cache4
@@ -159,9 +159,9 @@ test_expect_success 'an error page leaves no slot behind' '
# a slot would only double the disk they take.
test_expect_success 'a clone file leaves no slot behind' '
rm -rf cache3 && mkdir cache3 &&
- CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/info/refs" cgit >clone.out &&
+ cgit_rc bigkeyrc "url=bigpage/info/refs" >clone.out &&
grep "refs/heads/master" clone.out &&
- CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/objects/info/packs" cgit >packs.out &&
+ cgit_rc bigkeyrc "url=bigpage/objects/info/packs" >packs.out &&
grep "^Status: 200" packs.out &&
test_dir_is_empty cache3
'
@@ -176,21 +176,21 @@ test_expect_success 'a response over cache-max-slot-size is served but not kept'
echo "cache-max-slot-size=32" &&
cat bigkeyrc
} >slotsizerc &&
- CGIT_CONFIG="$PWD/slotsizerc" QUERY_STRING="url=bigpage/tree/big.txt" cgit >big.unkept &&
+ cgit_rc slotsizerc "url=bigpage/tree/big.txt" >big.unkept &&
tail -c 200 big.unkept | grep "</html>" &&
test_dir_is_empty cache3 &&
- CGIT_CONFIG="$PWD/slotsizerc" QUERY_STRING="url=bigpage/" cgit >/dev/null &&
+ cgit_rc slotsizerc "url=bigpage/" >/dev/null &&
ls cache3 >kept.slots &&
test_line_count = 1 kept.slots
'
test_expect_success 'an expired slot is dropped when its refill is too large' '
rm -rf cache3 && mkdir cache3 &&
- CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/tree/big.txt" cgit >/dev/null &&
+ cgit_rc bigkeyrc "url=bigpage/tree/big.txt" >/dev/null &&
ls cache3 >filled.slots &&
test_line_count = 1 filled.slots &&
touch -t 200001010000 cache3/* &&
- CGIT_CONFIG="$PWD/slotsizerc" QUERY_STRING="url=bigpage/tree/big.txt" cgit >big.refill &&
+ cgit_rc slotsizerc "url=bigpage/tree/big.txt" >big.refill &&
tail -c 200 big.refill | grep "</html>" &&
test_dir_is_empty cache3
'
@@ -204,11 +204,11 @@ test_expect_success 'pages following a branch take the dynamic ttl' '
echo "cache-dynamic-ttl=0" &&
cat bigkeyrc
} >dynamicrc &&
- CGIT_CONFIG="$PWD/dynamicrc" QUERY_STRING="url=bigpage/log/" cgit >/dev/null &&
- CGIT_CONFIG="$PWD/dynamicrc" QUERY_STRING="url=bigpage/log/&h=master" cgit >/dev/null &&
+ cgit_rc dynamicrc "url=bigpage/log/" >/dev/null &&
+ cgit_rc dynamicrc "url=bigpage/log/&h=master" >/dev/null &&
test_dir_is_empty cache3 &&
- CGIT_CONFIG="$PWD/dynamicrc" QUERY_STRING="url=bigpage/" cgit >/dev/null &&
- CGIT_CONFIG="$PWD/dynamicrc" QUERY_STRING="url=bigpage/summary/" cgit >/dev/null &&
+ cgit_rc dynamicrc "url=bigpage/" >/dev/null &&
+ cgit_rc dynamicrc "url=bigpage/summary/" >/dev/null &&
ls cache3 >summary.slots &&
test_line_count = 2 summary.slots
'
@@ -222,7 +222,7 @@ test_expect_success 'a failed final write still delivers the page' '
(
trap "" XFSZ &&
ulimit -f 2 &&
- CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/" cgit 2>flush.err
+ cgit_rc bigkeyrc "url=bigpage/" 2>flush.err
) | cat >flush.out &&
grep "^Status: 200" flush.out &&
grep "</html>" flush.out &&
@@ -234,13 +234,13 @@ test_expect_success 'a failed final write still delivers the page' '
overlap_requests() {
n=0
rm -f filter-running
- CGIT_CONFIG="$PWD/lockrc" QUERY_STRING="url=bigpage/about/" cgit >first.out 2>first.err &
+ cgit_rc lockrc "url=bigpage/about/" >first.out 2>first.err &
while ! test -f filter-running && test $n -lt 10
do
sleep 1
n=$((n + 1))
done
- CGIT_CONFIG="$PWD/lockrc" QUERY_STRING="url=bigpage/log/" cgit >/dev/null 2>second.err
+ cgit_rc lockrc "url=bigpage/log/" >/dev/null 2>second.err
wait
}
@@ -301,13 +301,13 @@ test_expect_success PERL 'a filter holds the lock file only as its stdout' '
# to the copy shows that it is what was served.
test_expect_success SANITY 'a refresh that cannot lock serves the expired slot and says why' '
rm -rf cache3 && mkdir cache3 &&
- CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/" cgit >/dev/null &&
+ cgit_rc bigkeyrc "url=bigpage/" >/dev/null &&
slot=$(ls cache3) &&
echo "the expired copy" >>"cache3/$slot" &&
touch -t 200001010000 "cache3/$slot" &&
test_when_finished "chmod u+w cache3" &&
chmod a-w cache3 &&
- CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/" cgit >stale.out 2>stale.err &&
+ cgit_rc bigkeyrc "url=bigpage/" >stale.out 2>stale.err &&
grep "the expired copy" stale.out &&
grep "Unable to open .*\.lock: Permission denied" stale.err
'
@@ -320,7 +320,7 @@ test_expect_success 'a slot lock that cannot take its key is let go' '
(
trap "" XFSZ &&
ulimit -f 0 &&
- CGIT_CONFIG="$PWD/bigkeyrc" QUERY_STRING="url=bigpage/" cgit 2>&1
+ cgit_rc bigkeyrc "url=bigpage/" 2>&1
) | cat >nokey.out &&
grep "</html>" nokey.out &&
grep "Unable to write .*\.lock" nokey.out &&
@@ -341,7 +341,7 @@ test_expect_success 'set up a cached scan of two repositories' '
echo "scan-path=$PWD/scanned"
} >scanrc &&
rm -rf cache5 && mkdir cache5 &&
- CGIT_CONFIG="$PWD/scanrc" QUERY_STRING="url=" cgit >/dev/null &&
+ cgit_rc scanrc "url=" >/dev/null &&
scanned_rc=$(ls cache5) &&
test_path_is_file "cache5/$scanned_rc"
'
diff --git a/tests/t0005-markup.sh b/tests/t0005-markup.sh
index 60a9990..a6dd028 100755
--- a/tests/t0005-markup.sh
+++ b/tests/t0005-markup.sh
@@ -17,23 +17,13 @@ test_expect_success 'set up a repository with a file that has an extension' '
git add dir &&
git commit -m sources
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "enable-blame=1" &&
- echo "max-stats=year" &&
- echo "readme=:file-1" &&
- echo "repo.url=hooks" &&
- echo "repo.path=$PWD/repos/hooks/.git"
- } >hooksrc
+ cgitrc_repo hooksrc hooks enable-blame=1 max-stats=year readme=:file-1
'
-hooks() { CGIT_CONFIG="$PWD/hooksrc" QUERY_STRING="url=$1" cgit; }
-
test_expect_success 'the root names the page and the repository' '
- hooks "" >tmp &&
+ cgit_rc hooksrc "url=" >tmp &&
grep "<div id=.cgit. data-page=.repolist.>" tmp &&
- hooks "hooks/log/" >tmp &&
+ cgit_rc hooksrc "url=hooks/log/" >tmp &&
grep "<div id=.cgit. data-page=.log. data-repo=.hooks.>" tmp
'
@@ -46,14 +36,14 @@ test_expect_success 'the landmarks and the search form are in place' '
'
test_expect_success 'the pages name the versions only when asked to' '
- hooks "hooks/" >footer &&
+ cgit_rc hooksrc "url=hooks/" >footer &&
grep "<meta name=.generator. content=.cgit.>" footer &&
grep "<footer class=.footer.>generated by <a href=[^>]*>cgit</a></footer>" footer &&
{
echo "enable-version-info=1" &&
cat hooksrc
} >versionrc &&
- CGIT_CONFIG="$PWD/versionrc" QUERY_STRING="url=hooks/" cgit >footer &&
+ cgit_rc versionrc "url=hooks/" >footer &&
grep "<meta name=.generator. content=.cgit v[0-9][^>]*>" footer &&
grep "<footer class=.footer.>generated by <a href=[^>]*>cgit v[0-9][^<]*</a> (<a href=[^>]*>git [0-9][^<]*</a>)</footer>" footer &&
echo "<footer>our own</footer>" >footer.html &&
@@ -62,7 +52,7 @@ test_expect_success 'the pages name the versions only when asked to' '
echo "footer=$PWD/footer.html" &&
cat hooksrc
} >versionrc &&
- CGIT_CONFIG="$PWD/versionrc" QUERY_STRING="url=hooks/" cgit >footer &&
+ cgit_rc versionrc "url=hooks/" >footer &&
grep "<footer>our own</footer>" footer &&
! grep "git-scm" footer
'
@@ -73,58 +63,58 @@ test_expect_success 'the listings name themselves, their sections and their rows
grep "<tr class=.commit.>" tmp &&
grep "class=.active. aria-current=.page." tmp &&
grep "<th class=.left. scope=.col.>" tmp &&
- hooks "" >tmp &&
+ cgit_rc hooksrc "url=" >tmp &&
grep "<table class=.list repolist. aria-label=.Repositories.>" tmp &&
grep "<tbody class=.repos.>" tmp &&
grep "<tr class=.repo.>" tmp &&
- hooks "hooks/" >tmp &&
+ cgit_rc hooksrc "url=hooks/" >tmp &&
grep "<table class=.list summary. aria-label=.Summary.>" tmp &&
grep "<tbody class=.branches.>" tmp &&
grep "<tr class=.branch.>" tmp &&
- hooks "hooks/tree/" >tmp &&
+ cgit_rc hooksrc "url=hooks/tree/" >tmp &&
grep "<table class=.list tree. aria-label=.Files.>" tmp &&
grep "<tr class=.dir.>" tmp &&
grep "<tr class=.blob.>" tmp &&
- hooks "hooks/tree/dir/" >tmp &&
+ cgit_rc hooksrc "url=hooks/tree/dir/" >tmp &&
grep "class=.ls-blob ext-c." tmp
'
test_expect_success 'the diff pages wrap each file and label their controls' '
- hooks "hooks/commit/" >tmp &&
+ cgit_rc hooksrc "url=hooks/commit/" >tmp &&
grep "<table class=.commit-info.>" tmp &&
grep "<th scope=.row.>author</th>" tmp &&
grep "<div class=.file. data-path=.dir/hello.c.>" tmp &&
grep "<label for=.diff-context.>context</label>" tmp &&
grep "<select id=.diff-context. name=.context.>" tmp &&
grep "<form method=.get. aria-label=.Diff options.>" tmp &&
- hooks "hooks/diff/&ss=1" >tmp &&
+ cgit_rc hooksrc "url=hooks/diff/&ss=1" >tmp &&
grep "<tbody class=.file. data-path=.dir/hello.c.>" tmp &&
- hooks "hooks/stats/" >tmp &&
+ cgit_rc hooksrc "url=hooks/stats/" >tmp &&
grep "<label for=.stats-authors.>authors</label>" tmp
'
test_expect_success 'the blob, blame and about pages open with their own containers' '
- hooks "hooks/tree/dir/hello.c" >tmp &&
+ cgit_rc hooksrc "url=hooks/tree/dir/hello.c" >tmp &&
grep "<div class=.blob-header.>" tmp &&
grep "<a id=.n1." tmp &&
- hooks "hooks/blame/dir/hello.c" >tmp &&
+ cgit_rc hooksrc "url=hooks/blame/dir/hello.c" >tmp &&
grep "<div class=.blob-header.>" tmp &&
- hooks "hooks/about/" >tmp &&
+ cgit_rc hooksrc "url=hooks/about/" >tmp &&
grep "<div id=.about.>" tmp
'
test_expect_success 'each page names itself, then the repository and the site' '
site="Git repository browser" &&
- hooks "hooks/" >tmp &&
+ cgit_rc hooksrc "url=hooks/" >tmp &&
grep "<title>hooks - $site</title>" tmp &&
for page in about log refs tree stats
do
- hooks "hooks/$page/" >tmp &&
+ cgit_rc hooksrc "url=hooks/$page/" >tmp &&
grep "<title>$page - hooks - $site</title>" tmp || return 1
done &&
- hooks "hooks/tree/dir/hello.c" >tmp &&
+ cgit_rc hooksrc "url=hooks/tree/dir/hello.c" >tmp &&
grep "<title>hello.c &lt; dir - hooks - $site</title>" tmp &&
- hooks "hooks/blame/dir/hello.c" >tmp &&
+ cgit_rc hooksrc "url=hooks/blame/dir/hello.c" >tmp &&
grep "<title>blame - hello.c &lt; dir - hooks - $site</title>" tmp
'
@@ -151,7 +141,7 @@ test_expect_success 'the page background is the same everywhere it is set' '
test_line_count = 1 expect &&
sed -n "/^html.cgit-standalone {\$/,/^}/s/^ background: light-dark(\(#[0-9a-f]*\), \(#[0-9a-f]*\));\$/\1 \2/p" "$css" >actual &&
test_cmp expect actual &&
- hooks "hooks/" >tmp &&
+ cgit_rc hooksrc "url=hooks/" >tmp &&
light=$(sed -n "s/.*theme-color. media=.(prefers-color-scheme: light). content=.\(#[0-9a-f]*\).*/\1/p" tmp) &&
dark=$(sed -n "s/.*theme-color. media=.(prefers-color-scheme: dark). content=.\(#[0-9a-f]*\).*/\1/p" tmp) &&
echo "$light $dark" >actual &&
@@ -159,7 +149,7 @@ test_expect_success 'the page background is the same everywhere it is set' '
'
test_expect_success 'the script waits for the page instead of holding it up' '
- hooks "hooks/" >tmp &&
+ cgit_rc hooksrc "url=hooks/" >tmp &&
grep "<script src=./cgit.js. defer></script>" tmp
'
@@ -205,31 +195,29 @@ test_expect_success 'set up the remaining kinds of entry' '
} >morerc
'
-more() { CGIT_CONFIG="$PWD/morerc" QUERY_STRING="url=$1" cgit; }
-
test_expect_success 'the refs, summary and tree name every section and row' '
- more "hooks/refs/" >tmp &&
+ cgit_rc morerc "url=hooks/refs/" >tmp &&
grep "<table class=.list refs. aria-label=.Branches and tags.>" tmp &&
grep "<tbody class=.tags.>" tmp &&
grep "<tr class=.tag.>" tmp &&
- more "hooks/" >tmp &&
+ cgit_rc morerc "url=hooks/" >tmp &&
grep "<tbody class=.clone.>" tmp &&
- more "hooks/tree/" >tmp &&
+ cgit_rc morerc "url=hooks/tree/" >tmp &&
grep "<tbody class=.tree.>" tmp &&
grep "<tr class=.link.>" tmp &&
grep "<tr class=.mod.>" tmp
'
test_expect_success 'the commit page has its trailer table and diffstat' '
- more "hooks/commit/" >tmp &&
+ cgit_rc morerc "url=hooks/commit/" >tmp &&
grep "<table class=.commit-trailers.>" tmp &&
grep "<table class=.diffstat.>" tmp
'
test_expect_success 'the breadcrumb, the pager and the ages carry their hooks' '
- more "hooks/tree/dir/" >tmp &&
+ cgit_rc morerc "url=hooks/tree/dir/" >tmp &&
grep "<nav class=.path. aria-label=.breadcrumb.>" tmp &&
- more "" >tmp &&
+ cgit_rc morerc "url=" >tmp &&
grep "<nav class=.pager. aria-label=.Pager.>" tmp &&
grep "class=.current. aria-current=.page." tmp &&
grep "<time class=.age-[a-z]*. datetime=.[^ ]* data-ut=.[0-9]*." tmp
@@ -240,13 +228,13 @@ test_expect_success 'a date shown in full is a plain time element' '
echo "enable-relative-dates=0" &&
cat morerc
} >fullrc &&
- CGIT_CONFIG="$PWD/fullrc" QUERY_STRING="url=" cgit >tmp &&
+ cgit_rc fullrc "url=" >tmp &&
grep "<time datetime=" tmp &&
! grep "data-ut=" tmp
'
test_expect_success 'an empty repository lists its clone urls as a clone table' '
- more "empty/" >tmp &&
+ cgit_rc morerc "url=empty/" >tmp &&
grep "<table class=.list clone. aria-label=.Clone urls.>" tmp &&
grep "<tbody class=.clone.>" tmp
'
@@ -256,7 +244,7 @@ test_expect_success 'embedded mode marks the root' '
echo "embedded=1" &&
cat hooksrc
} >embeddedrc &&
- CGIT_CONFIG="$PWD/embeddedrc" QUERY_STRING="url=hooks/" cgit >tmp &&
+ cgit_rc embeddedrc "url=hooks/" >tmp &&
grep "<div id=.cgit. class=.cgit-embedded. data-page=.summary." tmp
'
diff --git a/tests/t0006-nolua.sh b/tests/t0006-nolua.sh
index 86ae47d..cd35fca 100755
--- a/tests/t0006-nolua.sh
+++ b/tests/t0006-nolua.sh
@@ -23,12 +23,7 @@ test_expect_success 'the binary reports no Lua' '
'
test_expect_success 'it serves a page' '
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=foo" &&
- echo "repo.path=$PWD/repos/foo/.git"
- } >plainrc &&
+ cgitrc_repo plainrc foo &&
nolua_query plainrc "url=foo/log/" >tmp &&
grep "^Status: 200" tmp &&
grep ">commit 5</a>" tmp
diff --git a/tests/t0101-index.sh b/tests/t0101-index.sh
index e50f0f8..c8b9fb7 100755
--- a/tests/t0101-index.sh
+++ b/tests/t0101-index.sh
@@ -22,23 +22,15 @@ test_expect_success 'no tree-link' '! grep "foo/tree" tmp'
test_expect_success 'no log-link' '! grep "foo/log" tmp'
test_expect_success 'index links lead to the summary, log and tree' '
- echo "enable-index-links=1" >links-cgitrc &&
- sed "s/^cache-size=.*/cache-size=0/" cgitrc >>links-cgitrc &&
- CGIT_CONFIG="$PWD/links-cgitrc" QUERY_STRING="url=" cgit >tmp &&
+ cgitrc_copy links-cgitrc enable-index-links=1 &&
+ cgit_rc links-cgitrc "url=" >tmp &&
grep ">summary</a><a class=.button. href=./foo/log/.>log</a>" tmp &&
grep "href=./foo/log/.>log</a><a class=.button. href=./foo/tree/.>tree<" tmp
'
test_expect_success 'each css and js entry gets a link of its own' '
- {
- echo "css=/a.css" &&
- echo "css=/b.css" &&
- echo "js=/a.js" &&
- echo "js=" &&
- echo "js=/b.js"
- } >headrc &&
- sed "s/^cache-size=.*/cache-size=0/" cgitrc >>headrc &&
- CGIT_CONFIG="$PWD/headrc" QUERY_STRING="url=" cgit >tmp &&
+ cgitrc_copy headrc css=/a.css css=/b.css js=/a.js js= js=/b.js &&
+ cgit_rc headrc "url=" >tmp &&
grep "<link rel=.stylesheet. href=./a.css.>" tmp &&
grep "<link rel=.stylesheet. href=./b.css.>" tmp &&
grep "<script src=" tmp >scripts &&
@@ -48,7 +40,7 @@ test_expect_success 'each css and js entry gets a link of its own' '
'
test_expect_success 'the feed link encodes the repository and the branch' '
- sed "s/^cache-size=.*/cache-size=0/" cgitrc >feedrc &&
+ cgitrc_copy feedrc &&
CGIT_CONFIG="$PWD/feedrc" HTTP_HOST=example.org QUERY_STRING="url=foo%2Bbar/log/&h=1%2B2" cgit >tmp &&
grep "title=.Atom feed. href=.http://example.org/foo%2Bbar/atom/?h=1%2B2." tmp
'
@@ -63,7 +55,7 @@ test_expect_success 'a cut description keeps whole characters' '
echo "repo.path=$PWD/repos/foo/.git" &&
echo "repo.desc=日本語の説明文です"
} >descrc &&
- CGIT_CONFIG="$PWD/descrc" QUERY_STRING="url=" cgit >tmp &&
+ cgit_rc descrc "url=" >tmp &&
grep ">日本語\.\.\.</a>" tmp
'
diff --git a/tests/t0102-summary.sh b/tests/t0102-summary.sh
index 9b47cc2..9e0e14c 100755
--- a/tests/t0102-summary.sh
+++ b/tests/t0102-summary.sh
@@ -33,14 +33,8 @@ test_expect_success 'a git clone url row falls back to the page url' '
'
test_expect_success 'an scp clone url row links to the http url' '
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=foo" &&
- echo "repo.path=$PWD/repos/foo/.git" &&
- echo "repo.clone-url=git@example.org:foo https://example.org/foo"
- } >clonerc &&
- CGIT_CONFIG="$PWD/clonerc" QUERY_STRING="url=foo" cgit >tmp &&
+ cgitrc_repo clonerc foo "repo.clone-url=git@example.org:foo https://example.org/foo" &&
+ cgit_rc clonerc "url=foo" >tmp &&
grep "title=.foo Git repository. href=.https://example.org/foo.>git@example.org:foo</a>" tmp &&
grep "vcs-git. href=.https://example.org/foo." tmp &&
! grep "vcs-git. href=.git@" tmp
@@ -64,13 +58,13 @@ test_expect_success 'an empty clone url draws no clone heading' '
echo "repo.url=cloned" &&
echo "repo.path=$PWD/repos/empty.git"
} >emptyrc &&
- CGIT_CONFIG="$PWD/emptyrc" QUERY_STRING="url=foo" cgit >tmp &&
+ cgit_rc emptyrc "url=foo" >tmp &&
grep "commit 1" tmp &&
! grep "Clone</th>" tmp &&
- CGIT_CONFIG="$PWD/emptyrc" QUERY_STRING="url=empty" cgit >tmp &&
+ cgit_rc emptyrc "url=empty" >tmp &&
grep "Repository seems to be empty" tmp &&
! grep "Clone</th>" tmp &&
- CGIT_CONFIG="$PWD/emptyrc" QUERY_STRING="url=cloned" cgit >tmp &&
+ cgit_rc emptyrc "url=cloned" >tmp &&
grep "Clone</th>" tmp &&
grep "https://example.org/cloned</a>" tmp
'
@@ -98,7 +92,7 @@ row_widths() {
# Fails unless every row of the list table at the url is as many columns wide
# as the second argument says. A third names a config other than colsrc.
test_widths() {
- CGIT_CONFIG="$PWD/${3:-colsrc}" QUERY_STRING="url=$1" cgit >tmp &&
+ cgit_rc "${3:-colsrc}" "url=$1" >tmp &&
row_widths tmp | sort -u >actual &&
echo "$2" >expect &&
test_cmp expect actual
@@ -132,7 +126,7 @@ test_expect_success 'set up a repo cut short in every section' '
echo "repo.enable-log-filecount=1" &&
echo "repo.enable-log-linecount=1"
} >colsrc &&
- CGIT_CONFIG="$PWD/colsrc" QUERY_STRING="url=none" cgit >tmp &&
+ cgit_rc colsrc "url=none" >tmp &&
grep "<tbody class=.tags.>" tmp &&
grep "<tbody class=.clone.>" tmp &&
test $(grep -c ">\[...\]</a>" tmp) = 3
diff --git a/tests/t0103-log.sh b/tests/t0103-log.sh
index 927c814..b789ca4 100755
--- a/tests/t0103-log.sh
+++ b/tests/t0103-log.sh
@@ -68,24 +68,17 @@ test_expect_success 'set up a renamed file to follow' '
git commit -am "edit b $i" || return 1
done
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "enable-follow-links=1" &&
- echo "max-commit-count=3" &&
- echo "repo.url=fol" &&
- echo "repo.path=$PWD/repos/fol/.git"
- } >folrc
+ cgitrc_repo folrc fol enable-follow-links=1 max-commit-count=3
'
test_expect_success 'a followed log reaches the root commit' '
- CGIT_CONFIG="$PWD/folrc" QUERY_STRING="url=fol/log/b.txt&follow=1&ofs=6" cgit >tmp &&
+ cgit_rc folrc "url=fol/log/b.txt&follow=1&ofs=6" >tmp &&
grep ">edit a 2<" tmp &&
grep ">create a<" tmp
'
test_expect_success 'the pager of a followed log keeps the name followed' '
- CGIT_CONFIG="$PWD/folrc" QUERY_STRING="url=fol/log/b.txt&follow=1&ofs=3" cgit >tmp &&
+ cgit_rc folrc "url=fol/log/b.txt&follow=1&ofs=3" >tmp &&
grep ">edit a 3<" tmp &&
grep "href=./fol/log/b.txt?follow=1.>\[prev\]" tmp &&
grep "href=./fol/log/b.txt?ofs=6&amp;follow=1.>\[next\]" tmp
@@ -97,7 +90,7 @@ test_expect_success 'a cut subject keeps whole characters' '
echo "max-message-length=20" &&
sed "s/^cache-size=.*/cache-size=0/" cgitrc
} >subjectrc &&
- CGIT_CONFIG="$PWD/subjectrc" QUERY_STRING="url=foo/log/" cgit >tmp &&
+ cgit_rc subjectrc "url=foo/log/" >tmp &&
grep ">日本語の説\.\.\.</a>" tmp
'
@@ -106,7 +99,7 @@ test_expect_success 'the log draws the commit graph when enabled' '
echo "enable-commit-graph=1" &&
sed "s/^cache-size=.*/cache-size=0/" cgitrc
} >graphrc &&
- CGIT_CONFIG="$PWD/graphrc" QUERY_STRING="url=foo/log/" cgit >tmp &&
+ cgit_rc graphrc "url=foo/log/" >tmp &&
grep "class=.commitgraph." tmp &&
grep "<th scope=.col. aria-label=.Graph.></th>" tmp
'
@@ -118,7 +111,7 @@ test_expect_success 'a followed log heads its age column with the graph on' '
echo "enable-commit-graph=1" &&
cat folrc
} >folgraphrc &&
- CGIT_CONFIG="$PWD/folgraphrc" QUERY_STRING="url=fol/log/b.txt&follow=1" cgit >tmp &&
+ cgit_rc folgraphrc "url=fol/log/b.txt&follow=1" >tmp &&
grep "<th class=.left. scope=.col.>Age</th><th class=.left. scope=.col.>Commit message" tmp &&
! grep "aria-label=.Graph." tmp
'
@@ -139,13 +132,8 @@ test_expect_success 'a walk that cannot start answers one error page' '
old=$(git -C gap rev-parse HEAD~4) &&
parent=$(git -C gap rev-parse HEAD~2) &&
rm gap/.git/objects/$(echo $parent | cut -c1-2)/$(echo $parent | cut -c3-) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=gap" &&
- echo "repo.path=$PWD/gap/.git"
- } >gaprc &&
- CGIT_CONFIG="$PWD/gaprc" QUERY_STRING="url=gap/log/&qt=range&q=$old..master" cgit >tmp 2>err &&
+ cgitrc_repo gaprc gap "repo.path=$PWD/gap/.git" &&
+ cgit_rc gaprc "url=gap/log/&qt=range&q=$old..master" >tmp 2>err &&
test $(grep -c "^Status:" tmp) = 1 &&
grep "^Status: 500" tmp &&
grep "Unable to read the history" tmp
diff --git a/tests/t0104-tree.sh b/tests/t0104-tree.sh
index e6985f9..26a0cb4 100755
--- a/tests/t0104-tree.sh
+++ b/tests/t0104-tree.sh
@@ -44,17 +44,11 @@ test_expect_success 'set up a file holding the characters a browser breaks at' '
git add breaks.txt &&
git commit -m breaks
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "enable-blame=1" &&
- echo "repo.url=breaks" &&
- echo "repo.path=$PWD/repos/breaks/.git"
- } >breaksrc
+ cgitrc_repo breaksrc breaks enable-blame=1
'
test_expect_success 'each of them is shown as an escape in the tree' '
- CGIT_CONFIG="$PWD/breaksrc" QUERY_STRING="url=breaks/tree/breaks.txt" cgit >tmp &&
+ cgit_rc breaksrc "url=breaks/tree/breaks.txt" >tmp &&
grep "<code>a<span class=.escape.>\\\\r</span>b<span class=.escape.>\\\\v</span>c" tmp &&
grep "c<span class=.escape.>\\\\f</span>d<span class=.escape.>\\\\u0085</span>e" tmp &&
grep "e<span class=.escape.>\\\\u2028</span>f<span class=.escape.>\\\\u2029</span>g$" tmp
@@ -73,7 +67,7 @@ test_expect_success 'the numbers count only the lines git counts' '
'
test_expect_success 'the blame page escapes them the same way' '
- CGIT_CONFIG="$PWD/breaksrc" QUERY_STRING="url=breaks/blame/breaks.txt" cgit >tmp &&
+ cgit_rc breaksrc "url=breaks/blame/breaks.txt" >tmp &&
grep "<code>a<span class=.escape.>\\\\r</span>b<span class=.escape.>\\\\v</span>c" tmp &&
grep "e<span class=.escape.>\\\\u2028</span>f<span class=.escape.>\\\\u2029</span>g$" tmp &&
grep "^i<span class=.escape.>\\\\r</span></code>" tmp
@@ -105,17 +99,11 @@ test_expect_success 'set up a repo with a nested submodule' '
git update-index --add --cacheinfo 160000,$sub,vendor/sub &&
git commit -m gitlink
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "enable-blame=1" &&
- echo "repo.url=submodules" &&
- echo "repo.path=$PWD/repos/submodules/.git"
- } >submodrc
+ cgitrc_repo submodrc submodules enable-blame=1
'
test_expect_success 'generate submodules/tree/vendor' '
- CGIT_CONFIG="$PWD/submodrc" QUERY_STRING="url=submodules/tree/vendor" cgit >tmp
+ cgit_rc submodrc "url=submodules/tree/vendor" >tmp
'
test_expect_success 'a submodule row shows the entry name alone' '
@@ -140,7 +128,7 @@ test_expect_success 'a submodule row offers log but not blame or plain' '
'
test_expect_success 'a file row still offers blame' '
- CGIT_CONFIG="$PWD/submodrc" QUERY_STRING="url=submodules/tree/" cgit >tmp &&
+ cgit_rc submodrc "url=submodules/tree/" >tmp &&
grep ">blame</a>" tmp
'
@@ -158,13 +146,8 @@ test_expect_success 'only a link target inside the tree is linked' '
git update-index --add --cacheinfo 120000,$abs,abs &&
git commit -m links
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=links" &&
- echo "repo.path=$PWD/repos/links/.git"
- } >linksrc &&
- CGIT_CONFIG="$PWD/linksrc" QUERY_STRING="url=links/tree/" cgit >tmp &&
+ cgitrc_repo linksrc links &&
+ cgit_rc linksrc "url=links/tree/" >tmp &&
grep " -> <a class=.ls-blob. href=./links/tree/target.txt.>target.txt</a>" tmp &&
grep " -> /etc/passwd</td>" tmp &&
! grep "href=./links/tree/etc/passwd" tmp
@@ -186,13 +169,8 @@ test_expect_success 'a long directory chain ends on a link' '
git add . &&
git commit -m deep
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=deep" &&
- echo "repo.path=$PWD/repos/deep/.git"
- } >deeprc &&
- CGIT_CONFIG="$PWD/deeprc" QUERY_STRING="url=deep/tree/" cgit >tmp &&
+ cgitrc_repo deeprc deep &&
+ cgit_rc deeprc "url=deep/tree/" >tmp &&
grep ">d15</a></td>" tmp &&
! grep " / </td>" tmp
'
@@ -213,13 +191,8 @@ test_expect_success 'a broken chain keeps the row links on the first folder' '
git hash-object -t commit -w --stdin --literally) &&
git update-ref refs/heads/odd $odd
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=cut" &&
- echo "repo.path=$PWD/repos/cut/.git"
- } >cutrc &&
- CGIT_CONFIG="$PWD/cutrc" QUERY_STRING="url=cut/tree/&h=odd" cgit >tmp &&
+ cgitrc_repo cutrc cut &&
+ cgit_rc cutrc "url=cut/tree/&h=odd" >tmp &&
grep ">b</a></td>" tmp &&
grep "href=./cut/log/a?h=odd.>log</a>" tmp
'
@@ -232,13 +205,8 @@ test_expect_success 'a binary file in the tree shows as a hex dump' '
git add blob.bin &&
git commit -m binary
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=bin" &&
- echo "repo.path=$PWD/repos/bin/.git"
- } >binrc &&
- CGIT_CONFIG="$PWD/binrc" QUERY_STRING="url=bin/tree/blob.bin" cgit >tmp &&
+ cgitrc_repo binrc bin &&
+ cgit_rc binrc "url=bin/tree/blob.bin" >tmp &&
grep "<table class=.bin-blob.>" tmp &&
grep "<td class=.right.>0000</td><td class=.hex.> 00 01 02 62 69 6e" tmp
'
diff --git a/tests/t0105-plain.sh b/tests/t0105-plain.sh
index 4615dc5..6a96b61 100755
--- a/tests/t0105-plain.sh
+++ b/tests/t0105-plain.sh
@@ -65,9 +65,9 @@ test_expect_success 'only text and xml types carry a charset' '
echo "mimetype.svg=image/svg+xml" &&
cat cgitrc
} >typesrc &&
- CGIT_CONFIG="$PWD/typesrc" QUERY_STRING="url=foo/plain/doc.docx" cgit >tmp &&
+ cgit_rc typesrc "url=foo/plain/doc.docx" >tmp &&
sed "/^$/q" tmp | grep "^Content-Type: $docx$" &&
- CGIT_CONFIG="$PWD/typesrc" QUERY_STRING="url=foo/plain/pic.svg" cgit >tmp &&
+ cgit_rc typesrc "url=foo/plain/pic.svg" >tmp &&
sed "/^$/q" tmp | grep "^Content-Type: image/svg+xml; charset=UTF-8$"
'
@@ -83,14 +83,8 @@ test_expect_success 'plain answers once for duplicate tree entries' '
c=$(echo dup | git commit-tree $top) &&
git update-ref refs/heads/master $c
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "mimetype.png=image/png" &&
- echo "repo.url=dup" &&
- echo "repo.path=$PWD/repos/dup/.git"
- } >duprc &&
- CGIT_CONFIG="$PWD/duprc" QUERY_STRING="url=dup/plain/x.png" cgit >tmp &&
+ cgitrc_repo duprc dup mimetype.png=image/png &&
+ cgit_rc duprc "url=dup/plain/x.png" >tmp &&
test $(grep -c "^Status:" tmp) = 1 &&
test $(grep -c "^Content-Type:" tmp) = 1 &&
grep "^Content-Type: image/png" tmp
@@ -106,7 +100,7 @@ test_expect_success 'a control character in a file name stays out of the headers
c=$(echo ctl | git commit-tree $top) &&
git update-ref refs/heads/ctl $c
) &&
- CGIT_CONFIG="$PWD/duprc" QUERY_STRING="url=dup/plain/ctl%01name.txt&h=ctl" cgit >tmp &&
+ cgit_rc duprc "url=dup/plain/ctl%01name.txt&h=ctl" >tmp &&
grep "^Content-Disposition: inline; filename=.ctl?name.txt.$" tmp
'
diff --git a/tests/t0107-diff.sh b/tests/t0107-diff.sh
index 96e37f5..6710cec 100755
--- a/tests/t0107-diff.sh
+++ b/tests/t0107-diff.sh
@@ -46,18 +46,13 @@ test_expect_success 'set up a repo with single-line hunks' '
printf "ONLY\n" >one.txt &&
git commit -am "change one.txt"
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=hunk1" &&
- echo "repo.path=$PWD/repos/hunk1/.git"
- } >hunk1rc &&
+ cgitrc_repo hunk1rc hunk1 &&
git -C repos/hunk1 diff HEAD~1 HEAD >raw.diff &&
grep "^@@ -1 +1 @@" raw.diff
'
test_expect_success 'ssdiff numbers a comma-less hunk from its real line' '
- CGIT_CONFIG="$PWD/hunk1rc" QUERY_STRING="url=hunk1/diff/&dt=1" cgit >tmp &&
+ cgit_rc hunk1rc "url=hunk1/diff/&dt=1" >tmp &&
grep "#n1.>1</a>" tmp &&
! grep "#n0.>0</a>" tmp
'
@@ -85,16 +80,11 @@ test_expect_success 'set up a repo with shrinking changed lines' '
s=s sprintf(\"%c\",c)} print s}}" >lines.txt &&
git commit -am "change every line"
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "repo.url=lcs" &&
- echo "repo.path=$PWD/repos/lcs/.git"
- } >lcsrc
+ cgitrc_repo lcsrc lcs
'
test_expect_success 'every changed pair gets both a del and an add span' '
- CGIT_CONFIG="$PWD/lcsrc" QUERY_STRING="url=lcs/diff/&dt=1" cgit >tmp &&
+ cgit_rc lcsrc "url=lcs/diff/&dt=1" >tmp &&
deletions=$(grep -o "<span class=.del.>" tmp | wc -l) &&
additions=$(grep -o "<span class=.add.>" tmp | wc -l) &&
test "$deletions" -gt 0 &&
diff --git a/tests/t0109-patch.sh b/tests/t0109-patch.sh
index 5c528fc..52f2abc 100755
--- a/tests/t0109-patch.sh
+++ b/tests/t0109-patch.sh
@@ -60,7 +60,7 @@ test_expect_success 'max-patch-count bounds a patch range' '
echo "repo.url=foo" &&
echo "repo.path=$PWD/repos/foo/.git"
} >patchcountrc &&
- CGIT_CONFIG="$PWD/patchcountrc" QUERY_STRING="url=foo/patch&id=$id&id2=$root" cgit >tmp &&
+ cgit_rc patchcountrc "url=foo/patch&id=$id&id2=$root" >tmp &&
test $(grep -c "^From " tmp) -eq 2
'
@@ -69,7 +69,7 @@ test_expect_success 'the signature names the version when asked to' '
echo "enable-version-info=1" &&
sed "s/^cache-size=.*/cache-size=0/" cgitrc
} >versionrc &&
- CGIT_CONFIG="$PWD/versionrc" QUERY_STRING="url=foo/patch" cgit >tmp &&
+ cgit_rc versionrc "url=foo/patch" >tmp &&
check_cgit_signature "$CGIT_VERSION"
'
diff --git a/tests/t0110-snapshot.sh b/tests/t0110-snapshot.sh
index 5478114..faebf5e 100755
--- a/tests/t0110-snapshot.sh
+++ b/tests/t0110-snapshot.sh
@@ -105,17 +105,11 @@ test_expect_success UNZIP 'unzip and verify the content' '
test_expect_success 'set up a repo with a versioned tag' '
mkrepo repos/vtags 2 &&
git -C repos/vtags update-ref refs/tags/v1.0 HEAD &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "snapshots=tar.gz" &&
- echo "repo.url=vtags" &&
- echo "repo.path=$PWD/repos/vtags/.git"
- } >vtagsrc
+ cgitrc_repo vtagsrc vtags snapshots=tar.gz
'
test_expect_success 'a loose v tag still sheds its v in the snapshot name' '
- CGIT_CONFIG="$PWD/vtagsrc" QUERY_STRING="url=vtags/refs/" cgit >tmp &&
+ cgit_rc vtagsrc "url=vtags/refs/" >tmp &&
grep "vtags-1.0.tar.gz" tmp &&
! grep "vtags-v1.0.tar.gz" tmp
'
@@ -125,7 +119,7 @@ test_expect_success 'a loose v tag still sheds its v in the snapshot name' '
test_expect_success 'a real case collision keeps the v on both tags' '
git -C repos/vtags pack-refs --all &&
git -C repos/vtags update-ref refs/tags/V1.0 HEAD~1 &&
- CGIT_CONFIG="$PWD/vtagsrc" QUERY_STRING="url=vtags/refs/" cgit >tmp &&
+ cgit_rc vtagsrc "url=vtags/refs/" >tmp &&
grep "vtags-v1.0.tar.gz" tmp &&
grep "vtags-V1.0.tar.gz" tmp &&
! grep "vtags-1.0.tar.gz" tmp
@@ -136,7 +130,7 @@ test_expect_success 'a real case collision keeps the v on both tags' '
test_expect_success 'a snapshot name with nothing before its suffix is refused' '
git -C repos/vtags branch v HEAD &&
sed "s/^snapshots=tar.gz$/snapshots=tar/" vtagsrc >vtagstarrc &&
- CGIT_CONFIG="$PWD/vtagstarrc" QUERY_STRING="url=vtags/snapshot/.tar" cgit >tmp &&
+ cgit_rc vtagstarrc "url=vtags/snapshot/.tar" >tmp &&
grep "^Status: 404" tmp
'
@@ -145,7 +139,7 @@ test_expect_success 'an empty snapshot-prefix puts no slash ahead of the members
cat vtagstarrc &&
echo "repo.snapshot-prefix="
} >noprefixrc &&
- CGIT_CONFIG="$PWD/noprefixrc" QUERY_STRING="url=vtags/snapshot/vtags.tar&id=master" cgit >tmp &&
+ cgit_rc noprefixrc "url=vtags/snapshot/vtags.tar&id=master" >tmp &&
strip_headers <tmp >noprefix.tar &&
tar -tf noprefix.tar >members &&
grep "^file-1$" members &&
@@ -169,23 +163,23 @@ test_expect_success 'set up repositories whose urls end in .git' '
'
test_expect_success 'a url of .git names a snapshot after the ref alone' '
- CGIT_CONFIG="$PWD/dotgitrc" QUERY_STRING="url=.git/refs/" cgit >tmp &&
+ cgit_rc dotgitrc "url=.git/refs/" >tmp &&
grep ">v1.0.tar<" tmp &&
- CGIT_CONFIG="$PWD/dotgitrc" QUERY_STRING="url=.git/snapshot/v1.0.tar" cgit >tmp &&
+ cgit_rc dotgitrc "url=.git/snapshot/v1.0.tar" >tmp &&
strip_headers <tmp >dotgit.tar &&
tar -tf dotgit.tar >members &&
grep "^v1.0/file-1$" members
'
test_expect_success 'a url ending in /.git names a snapshot after its directory' '
- CGIT_CONFIG="$PWD/dotgitrc" QUERY_STRING="url=sub/.git/refs/" cgit >tmp &&
+ cgit_rc dotgitrc "url=sub/.git/refs/" >tmp &&
grep ">sub-1.0.tar<" tmp
'
# A server may run cgit with no PATH at all, and the compressor is then looked
# for on the default path execvp searches.
test_expect_success GZIP 'a compressed snapshot is made without a PATH' '
- sed "s/^cache-size=.*/cache-size=0/" cgitrc >nopathrc &&
+ cgitrc_copy nopathrc &&
cgit_bin=$(command -v cgit) &&
(
unset PATH &&
@@ -200,7 +194,7 @@ test_expect_success GZIP 'a compressed snapshot is made without a PATH' '
# that tag even when a branch is spelled like the tag's stem.
test_expect_success GZIP 'a snapshot name leads to the tag ahead of a branch' '
git -C repos/vtags update-ref refs/heads/1.0 $(git -C repos/vtags commit-tree -m shadow HEAD^{tree}) &&
- CGIT_CONFIG="$PWD/vtagsrc" QUERY_STRING="url=vtags/snapshot/vtags-1.0.tar.gz" cgit >tmp &&
+ cgit_rc vtagsrc "url=vtags/snapshot/vtags-1.0.tar.gz" >tmp &&
strip_headers <tmp >tag.tar.gz &&
test "$(gzip -dc tag.tar.gz | git -C repos/vtags get-tar-commit-id)" = "$(git -C repos/vtags rev-parse refs/tags/v1.0^{commit})"
'
@@ -213,7 +207,7 @@ test_expect_success 'a signature past max-blob-size is refused' '
echo "max-blob-size=1" &&
cat vtagsrc
} >sigrc &&
- CGIT_CONFIG="$PWD/sigrc" QUERY_STRING="url=vtags/snapshot/vtags-1.0.tar.gz.asc" cgit >tmp &&
+ cgit_rc sigrc "url=vtags/snapshot/vtags-1.0.tar.gz.asc" >tmp &&
grep "^Status: 413" tmp
'
@@ -228,14 +222,8 @@ test_expect_success 'a snapshot and its signature are linked as one unit' '
sig=$(echo signature | git hash-object -w --stdin) &&
git notes --ref signatures/tar.gz add -C $sig one
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "snapshots=tar.gz" &&
- echo "repo.url=signed" &&
- echo "repo.path=$PWD/repos/signed/.git"
- } >signedrc &&
- CGIT_CONFIG="$PWD/signedrc" QUERY_STRING="url=signed/refs/" cgit >tmp &&
+ cgitrc_repo signedrc signed snapshots=tar.gz &&
+ cgit_rc signedrc "url=signed/refs/" >tmp &&
grep "<span class=.snapshot.><a href=./signed/snapshot/signed-one.tar.gz.>signed-one.tar.gz</a> (<a href=./signed/snapshot/signed-one.tar.gz.asc.>sig</a>)</span>" tmp
'
diff --git a/tests/t0111-atom.sh b/tests/t0111-atom.sh
index ccc8a2f..443ac77 100755
--- a/tests/t0111-atom.sh
+++ b/tests/t0111-atom.sh
@@ -34,14 +34,8 @@ test_expect_success 'ten entries is the default ceiling' '
'
test_expect_success 'max-atom-items overrides the ceiling' '
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "max-atom-items=3" &&
- echo "repo.url=bar" &&
- echo "repo.path=$PWD/repos/bar/.git"
- } >atomrc &&
- CGIT_CONFIG="$PWD/atomrc" QUERY_STRING="url=bar/atom" cgit >tmp &&
+ cgitrc_repo atomrc bar max-atom-items=3 &&
+ cgit_rc atomrc "url=bar/atom" >tmp &&
strip_headers <tmp >feed &&
test $(grep -c "<entry>" feed) -eq 3
'
diff --git a/tests/t0112-stats.sh b/tests/t0112-stats.sh
index 3728412..5100793 100755
--- a/tests/t0112-stats.sh
+++ b/tests/t0112-stats.sh
@@ -28,31 +28,17 @@ test_expect_success 'set up a stats config' '
git commit --allow-empty -m fresh &&
git commit-graph write --reachable
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "max-stats=year" &&
- echo "repo.url=stat" &&
- echo "repo.path=$PWD/repos/pulse/.git"
- } >statsrc &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "max-stats=month" &&
- echo "repo.url=stat" &&
- echo "repo.path=$PWD/repos/pulse/.git"
- } >statmaxrc
+ cgitrc_repo statsrc stat max-stats=year "repo.path=$PWD/repos/pulse/.git" &&
+ cgitrc_repo statmaxrc stat max-stats=month "repo.path=$PWD/repos/pulse/.git"
'
-statq() { CGIT_CONFIG="$PWD/statsrc" QUERY_STRING="$1" cgit; }
-
test_expect_success 'stats tab appears when enabled' '
- statq "url=stat/" >tmp &&
+ cgit_rc statsrc "url=stat/" >tmp &&
grep ">stats</a>" tmp
'
test_expect_success 'stats page renders the authors table' '
- statq "url=stat/stats/" >tmp &&
+ cgit_rc statsrc "url=stat/stats/" >tmp &&
grep "<h2>Commits per author" tmp
'
@@ -65,13 +51,13 @@ test_expect_success 'stat options sit above the content' '
'
test_expect_success 'stats below a path stay a normal page' '
- statq "url=stat/stats/file-1" >tmp &&
+ cgit_rc statsrc "url=stat/stats/file-1" >tmp &&
grep "Status: 200" tmp &&
grep "<h2>Commits per author" tmp
'
test_expect_success 'max-stats=year offers all four periods' '
- statq "url=stat/stats/" >tmp &&
+ cgit_rc statsrc "url=stat/stats/" >tmp &&
grep "<option value=.w." tmp &&
grep "<option value=.m." tmp &&
grep "<option value=.q." tmp &&
@@ -79,20 +65,20 @@ test_expect_success 'max-stats=year offers all four periods' '
'
test_expect_success 'max-stats bounds the selectable periods' '
- CGIT_CONFIG="$PWD/statmaxrc" QUERY_STRING="url=stat/stats/&period=y" cgit >tmp &&
+ cgit_rc statmaxrc "url=stat/stats/&period=y" >tmp &&
grep "Statistics type disabled" tmp &&
- CGIT_CONFIG="$PWD/statmaxrc" QUERY_STRING="url=stat/stats/" cgit >tmp &&
+ cgit_rc statmaxrc "url=stat/stats/" >tmp &&
! grep "<option value=.q." tmp
'
# Each period buckets commits and labels its columns its own way, so every one
# gets a page of its own here.
test_expect_success 'every period renders its own columns' '
- statq "url=stat/stats/&period=m" >tmp &&
+ cgit_rc statsrc "url=stat/stats/&period=m" >tmp &&
grep -E "<th[^>]*>[A-Z][a-z][a-z] [0-9]{4}</th>" tmp &&
- statq "url=stat/stats/&period=q" >tmp &&
+ cgit_rc statsrc "url=stat/stats/&period=q" >tmp &&
grep -E "<th[^>]*>Q[1-4] [0-9]{4}</th>" tmp &&
- statq "url=stat/stats/&period=y" >tmp &&
+ cgit_rc statsrc "url=stat/stats/&period=y" >tmp &&
grep -E "<th[^>]*>[0-9]{4}</th>" tmp
'
@@ -112,14 +98,8 @@ test_expect_success 'the window opens at midnight on its first day' '
GIT_COMMITTER_DATE="$first-01-01 00:00:00 +0000" \
git commit --allow-empty -m first
) &&
- {
- echo "virtual-root=/" &&
- echo "cache-size=0" &&
- echo "max-stats=year" &&
- echo "repo.url=edge" &&
- echo "repo.path=$PWD/repos/edge/.git"
- } >edgerc &&
- CGIT_CONFIG="$PWD/edgerc" QUERY_STRING="url=edge/stats/&period=y" cgit >tmp &&
+ cgitrc_repo edgerc edge max-stats=year &&
+ cgit_rc edgerc "url=edge/stats/&period=y" >tmp &&
grep ">Early Bird<" tmp &&
! grep ">Too Early<" tmp
'
@@ -127,9 +107,9 @@ test_expect_success 'the window opens at midnight on its first day' '
# A path starting with a colon would reach git as pathspec magic, which the
# log, the feed and the patch page refuse as well.
test_expect_success 'a path with pathspec magic is refused' '
- statq "url=stat/stats/%3A%28icase%29FILE-1" >tmp &&
+ cgit_rc statsrc "url=stat/stats/%3A%28icase%29FILE-1" >tmp &&
grep "^Status: 400" tmp &&
- statq "url=stat/stats/file-1" >tmp &&
+ cgit_rc statsrc "url=stat/stats/file-1" >tmp &&
grep "^Status: 200" tmp
'