diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Add a test suite for the shipped extensions
Diffstat (limited to '')
| -rwxr-xr-x | tests/t0502-syntax-highlight.sh | 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 74 insertions, 0 deletions
diff --git a/tests/t0502-syntax-highlight.sh b/tests/t0502-syntax-highlight.sh new file mode 100755 index 0000000..c7cbf89 --- /dev/null +++ b/tests/t0502-syntax-highlight.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +# Checks syntax-highlight.lua, the shipped source-filter. The real +# Scintillua collection is not assumed anywhere, because the fake lexer +# module under extensions/fake-lexers drives every path through the +# filter deterministically. The unit checks run twice per interpreter, once +# with the fake lexers found and once with an empty directory so the escaped +# fallback is what everything renders through. The run through cgit itself +# places the fake lexers beside the config file, which is the probe the +# filter documents for a scintillua directory next to cgitrc. + +test_description='Check the shipped syntax-highlight 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 "highlighting checks under $lua" " + CGIT_SCINTILLUA_PATH='$EXT_TEST_DIRECTORY/fake-lexers' \ + '$lua' '$EXT_TEST_DIRECTORY/test-syntax-highlight.lua' \ + '$EXTENSIONS_DIRECTORY/syntax-highlight.lua' highlight + " + + test_expect_success "fallback checks without lexers under $lua" " + mkdir -p empty-lexers && + CGIT_SCINTILLUA_PATH=\"\$PWD/empty-lexers\" \ + '$lua' '$EXT_TEST_DIRECTORY/test-syntax-highlight.lua' \ + '$EXTENSIONS_DIRECTORY/syntax-highlight.lua' nolexers + " +done + +test "$CGIT_HAS_LUA" -eq 1 && test_set_prereq CGIT_LUA +test "$CGIT_HAS_LUA" -eq 1 || + say 'cgit built without lua, filter checks through cgit skipped' + +test_expect_success 'create a repository holding a lexable file' ' + test_create_repo repos/fake && + ( + cd repos/fake && + echo "if 42 & zz" >hello.fake && + git add hello.fake && + git commit -m "add hello" + ) +' + +test_expect_success 'place the fake lexers beside a config naming the filter' ' + mkdir -p scintillua && + cp -R "$EXT_TEST_DIRECTORY/fake-lexers" scintillua/lexers && + cat >cgitrc <<-EOF + virtual-root=/ + cache-size=0 + enable-filter-overrides=1 + repo.url=fake + repo.path=$PWD/repos/fake/.git + repo.source-filter=lua:$EXTENSIONS_DIRECTORY/syntax-highlight.lua + EOF +' + +test_expect_success CGIT_LUA 'the tree view is highlighted' ' + cgit_url "fake/tree/hello.fake" >tmp && + grep "<span class=.hl-keyword.>if</span>" tmp && + grep "<span class=.hl-number.>42</span>" tmp +' + +test_expect_success CGIT_LUA 'bytes between tokens reach the page escaped' ' + grep "<span class=.hl-number.>42</span> & " tmp +' + +test_done |
