#!/bin/sh
# Checks about-render.lua, the shipped about-filter. The unit checks drive
# the script under every suitable standalone Lua through the harness in
# extensions/, once as installed and once with lpeg forced away so the
# plain text fallback is proven everywhere. A repository with a markdown
# readme is then rendered through cgit itself, where the outcome depends on
# whether the Lua inside the binary has lpeg, so a probe decides which of
# the two right answers to expect.
test_description='Check the shipped about-render extension'
CGIT_TEST_NO_CREATE_REPOS=YesPlease
. ./setup.sh
. "$TEST_OUTPUT_DIRECTORY/extensions/lib.sh"
interpreters=$(ext_lua_interpreters 5)
test -z "$interpreters" &&
say 'no standalone lua on the path, unit checks skipped'
for lua in $interpreters
do
test_expect_success "unit checks under $lua" "
'$lua' '$EXT_TEST_DIRECTORY/test-about-render.lua' '$EXTENSIONS_DIRECTORY/about-render.lua'
"
test_expect_success "fallback checks without lpeg under $lua" "
'$lua' '$EXT_TEST_DIRECTORY/test-about-render.lua' '$EXTENSIONS_DIRECTORY/about-render.lua' nolpeg
"
done
test_expect_success 'create a repository with a markdown readme' '
test_create_repo repos/md &&
(
cd repos/md &&
cat >README.md <<-\EOF &&
# The Title
A **bold** claim and a attempt.
See the [roadmap](ROADMAP.md#plan).
EOF
cat >tool.1 <<-\EOF &&
.TH TOOL 1
.SH NAME
tool \- does one thing \(em well
.SH OPTIONS
.TP
.B \-v
Be \fIverbose\fR.
.nf
tool \-v
.fi
EOF
echo "Plain notes & more" >NOTES &&
git add README.md tool.1 NOTES &&
git commit -m "add readme" &&
git branch next
)
'
test_expect_success 'point cgit at it through the about filter' '
cat >cgitrc <<-EOF
virtual-root=/
cache-size=0
repo.url=md
repo.path=$PWD/repos/md/.git
repo.readme=:README.md
repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua
repo.url=man
repo.path=$PWD/repos/md/.git
repo.readme=:tool.1
repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua
repo.url=txt
repo.path=$PWD/repos/md/.git
repo.readme=:NOTES
repo.about-filter=lua:$EXTENSIONS_DIRECTORY/about-render.lua
EOF
'
if test "$CGIT_HAS_LUA" -eq 1
then
test_set_prereq CGIT_LUA
if cgit_lua_probe "$PWD/repos/md/.git" lpeg
then
test_set_prereq CGIT_LUA_LPEG
else
test_set_prereq CGIT_LUA_NOLPEG
say 'cgit lua has no lpeg, expecting the plain text fallback'
fi
else
say 'cgit built without lua, filter checks through cgit skipped'
fi
test_expect_success CGIT_LUA_LPEG 'the about page renders the markdown' '
cgit_url "md/about/" >tmp &&
grep "The Title
" tmp &&
grep "bold" tmp
'
test_expect_success CGIT_LUA_LPEG 'readme markup reaches the page escaped' '
cgit_url "md/about/" >tmp &&
grep "<script>alert(1)</script>" tmp &&
! grep "