Diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/extensions/harness.lua | 16 | |
| -rw-r--r-- | tests/extensions/lib.sh | 18 | |
| -rw-r--r-- | tests/extensions/test-about-render.lua | 23 | |
| -rw-r--r-- | tests/extensions/test-email-avatar.lua | 2 | |
| -rw-r--r-- | tests/extensions/test-link-commits.lua | 8 | |
| -rw-r--r-- | tests/extensions/test-link-trailers.lua | 8 | |
| -rw-r--r-- | tests/extensions/test-syntax-highlight.lua | 2 | |
| -rwxr-xr-x | tests/t0501-about-render.sh | 15 | |
| -rwxr-xr-x | tests/t0504-email-avatar.sh | 10 |
9 files changed, 64 insertions, 38 deletions
diff --git a/tests/extensions/harness.lua b/tests/extensions/harness.lua index 8c1ba6c..b54f727 100644 --- a/tests/extensions/harness.lua +++ b/tests/extensions/harness.lua @@ -82,6 +82,22 @@ function harness.load(script) dofile(script) end +-- The mode a t05xx script names after the script path, which has to be one +-- of those given, so a misspelt mode fails instead of quietly running +-- another one. Lua 5.1 gives a function taking ... a local arg of its own, +-- nil here, so the script's arguments are read from the global table. +function harness.mode(...) + local known = { ... } + local wanted = _G.arg[2] + for _, mode in ipairs(known) do + if wanted == mode then + return mode + end + end + error("unknown mode " .. tostring(wanted) .. ", wanted one of " .. + table.concat(known, ", ")) +end + -- Load a script with some of its own text replaced first, for checks that -- need the commented-out examples of its configuration switched on. Each -- replacement has to match exactly once, so a reworded example fails here diff --git a/tests/extensions/lib.sh b/tests/extensions/lib.sh index 8584446..56098d0 100644 --- a/tests/extensions/lib.sh +++ b/tests/extensions/lib.sh @@ -49,6 +49,24 @@ done # the count, as skipped, rather than vanishing from it. test -z "$interpreters" || test_set_prereq STANDALONE_LUA +# Leaves in lua_prereq the name of a prerequisite that holds when the +# interpreter given first can load every module named after it, so a check +# needing a module shows as skipped under an interpreter that lacks it. +lua_module_prereq() { + lua_prereq=$(printf '%s' "$*" | tr -c 'A-Za-z0-9' '_' | tr 'a-z' 'A-Z') + lua_prereq_bin=$1 + shift + lua_prereq_code= + for lua_prereq_module + do + lua_prereq_code="$lua_prereq_code require('$lua_prereq_module')" + done + if "$lua_prereq_bin" -e "$lua_prereq_code" >/dev/null 2>&1 + then + test_set_prereq "$lua_prereq" + fi +} + # Asks whether cgit's own Lua can require every module named, by pointing a # throwaway commit-filter at the given repository and reading its answer off # the rendered commit page. Filters need a page to run on, which is why a diff --git a/tests/extensions/test-about-render.lua b/tests/extensions/test-about-render.lua index 98b84b8..e6813ef 100644 --- a/tests/extensions/test-about-render.lua +++ b/tests/extensions/test-about-render.lua @@ -1,25 +1,18 @@ -- Unit checks for custom/extensions/about-render.lua, run under a standalone -- Lua by t0501-about-render.sh with the script path as the first argument. --- The second argument may be nolpeg, which makes the lpeg module fail to --- load so the escaped plain text fallback is proven even on a machine where --- lpeg is installed. Without it the markdown and man checks run when lpeg is --- present and are skipped with a note when it is not, the same way the --- filter itself degrades. +-- The second argument is the mode. In lpeg mode, which t0501 asks for only +-- where the interpreter has lpeg, the markdown and man checks run. In nolpeg +-- mode the lpeg module fails to load, so the escaped plain text fallback is +-- proven even on a machine where lpeg is installed. local test_directory = arg[0]:match("^(.*)/") or "." local h = dofile(test_directory .. "/harness.lua") local script = arg[1] -local mode = arg[2] or "" +local mode = h.mode("lpeg", "nolpeg") -local has_lpeg = false if mode == "nolpeg" then h.preload_failure("lpeg") -else - has_lpeg = pcall(require, "lpeg") - if not has_lpeg then - io.write("lpeg not installed, markdown and man checks skipped\n") - end end h.load(script) @@ -27,7 +20,7 @@ h.load(script) -- A missing lpeg is written to the error log as the script loads. if mode == "nolpeg" then h.contains("a missing lpeg is named in the error log", h.error_log(), "Unable to load lpeg") -elseif has_lpeg then +else h.equals("with lpeg the error log stays empty", h.error_log(), "") end @@ -72,10 +65,6 @@ if mode == "nolpeg" then h.finish() end -if not has_lpeg then - h.finish() -end - -- Markdown. out = render("README.md", "# Title") diff --git a/tests/extensions/test-email-avatar.lua b/tests/extensions/test-email-avatar.lua index 65c4ce9..199b4ac 100644 --- a/tests/extensions/test-email-avatar.lua +++ b/tests/extensions/test-email-avatar.lua @@ -11,7 +11,7 @@ local test_directory = arg[0]:match("^(.*)/") or "." local h = dofile(test_directory .. "/harness.lua") local script = arg[1] -local mode = arg[2] or "stub" +local mode = h.mode("stub", "missing", "real") local base_url = "https://gravatar.com/avatar/" if script:find("libravatar", 1, true) then diff --git a/tests/extensions/test-link-commits.lua b/tests/extensions/test-link-commits.lua index ea342bf..45a3f60 100644 --- a/tests/extensions/test-link-commits.lua +++ b/tests/extensions/test-link-commits.lua @@ -9,7 +9,9 @@ local test_directory = arg[0]:match("^(.*)/") or "." local h = dofile(test_directory .. "/harness.lua") -h.load(arg[1]) +local script = arg[1] + +h.load(script) local function render(text) return h.run({}, { text }) @@ -19,7 +21,7 @@ local out, ret = render("see #123 near deadbee") h.equals("an unedited copy leaves issue marks as text", out, "see #123 near <a href='./?id=deadbee'>deadbee</a>") -h.load_with(arg[1], { { "-- { pattern = \"#(%d+)\"", "{ pattern = \"#(%d+)\"" } }) +h.load_with(script, { { "-- { pattern = \"#(%d+)\"", "{ pattern = \"#(%d+)\"" } }) out, ret = render("see #123 for details") h.contains("issue mark becomes a link", out, "<a href='https://bugs.example.com/?bug=123'>#123</a>") @@ -78,7 +80,7 @@ h.equals("a message with no matches passes through", out, "plain words only") -- A rule broad enough to capture a quote or a percent sign still has to -- leave a url that stays inside its attribute and means what it says. -h.load_with(arg[1], { { "local rules = {", "local rules = { { pattern = \"T:(%S+)\", url = \"https://t/%s\" }," } }) +h.load_with(script, { { "local rules = {", "local rules = { { pattern = \"T:(%S+)\", url = \"https://t/%s\" }," } }) out = render("T:a'b%c") h.equals("a captured value is percent-encoded into the url", out, "<a href='https://t/a%27b%25c'>T:a'b%c</a>") diff --git a/tests/extensions/test-link-trailers.lua b/tests/extensions/test-link-trailers.lua index 9c3b264..01854a0 100644 --- a/tests/extensions/test-link-trailers.lua +++ b/tests/extensions/test-link-trailers.lua @@ -9,7 +9,9 @@ local test_directory = arg[0]:match("^(.*)/") or "." local h = dofile(test_directory .. "/harness.lua") -h.load(arg[1]) +local script = arg[1] + +h.load(script) local function render(key, text) return h.run({ key, "commit" }, { text }) @@ -17,7 +19,7 @@ end h.equals("an unedited copy leaves a Closes mark as text", render("Closes", "#45"), "#45") -h.load_with(arg[1], { +h.load_with(script, { { "-- { key = \"Closes\"", "{ key = \"Closes\"" }, { "-- { key = \"Bug\"", "{ key = \"Bug\"" }, }) @@ -73,7 +75,7 @@ h.equals("an empty value still answers zero", ret, 0) -- A rule broad enough to capture a quote or a percent sign still has to -- leave a url that stays inside its attribute and means what it says. -h.load_with(arg[1], { { "local rules = {", "local rules = { { key = \"Ref\", pattern = \"^(%S+)$\", url = \"https://t/%s\" }," } }) +h.load_with(script, { { "local rules = {", "local rules = { { key = \"Ref\", pattern = \"^(%S+)$\", url = \"https://t/%s\" }," } }) out = render("Ref", "a'b%c") h.equals("a captured value is percent-encoded into the url", out, "<a href='https://t/a%27b%25c'>a'b%c</a>") diff --git a/tests/extensions/test-syntax-highlight.lua b/tests/extensions/test-syntax-highlight.lua index b54dc84..08cc72d 100644 --- a/tests/extensions/test-syntax-highlight.lua +++ b/tests/extensions/test-syntax-highlight.lua @@ -11,7 +11,7 @@ local test_directory = arg[0]:match("^(.*)/") or "." local h = dofile(test_directory .. "/harness.lua") local script = arg[1] -local mode = arg[2] or "highlight" +local mode = h.mode("highlight", "nolexers") h.load(script) diff --git a/tests/t0501-about-render.sh b/tests/t0501-about-render.sh index 95028f0..af68260 100755 --- a/tests/t0501-about-render.sh +++ b/tests/t0501-about-render.sh @@ -2,11 +2,11 @@ # 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. +# extensions/, once with lpeg wherever that interpreter has it 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 @@ -15,8 +15,9 @@ CGIT_TEST_NO_CREATE_REPOS=YesPlease for lua in ${interpreters:-lua} do - test_expect_success STANDALONE_LUA "unit checks under $(lua_version "$lua")" ' - "$lua" "$EXT_TEST_DIRECTORY/test-about-render.lua" "$EXTENSIONS_DIRECTORY/about-render.lua" + lua_module_prereq "$lua" lpeg + test_expect_success "STANDALONE_LUA,$lua_prereq" "unit checks under $(lua_version "$lua")" ' + "$lua" "$EXT_TEST_DIRECTORY/test-about-render.lua" "$EXTENSIONS_DIRECTORY/about-render.lua" lpeg ' test_expect_success STANDALONE_LUA "fallback checks without lpeg under $(lua_version "$lua")" ' diff --git a/tests/t0504-email-avatar.sh b/tests/t0504-email-avatar.sh index 1b82a41..342daee 100755 --- a/tests/t0504-email-avatar.sh +++ b/tests/t0504-email-avatar.sh @@ -16,6 +16,7 @@ CGIT_TEST_NO_CREATE_REPOS=YesPlease for lua in ${interpreters:-lua} do + lua_module_prereq "$lua" openssl.digest for script in email-gravatar email-libravatar do test_expect_success STANDALONE_LUA "$script checks under $(lua_version "$lua")" ' @@ -25,12 +26,9 @@ do "$lua" "$EXT_TEST_DIRECTORY/test-email-avatar.lua" "$EXTENSIONS_DIRECTORY/$script.lua" missing ' - if "$lua" -e "require([[openssl.digest]])" >/dev/null 2>&1 - then - test_expect_success STANDALONE_LUA "$script checks with real luaossl under $(lua_version "$lua")" ' - "$lua" "$EXT_TEST_DIRECTORY/test-email-avatar.lua" "$EXTENSIONS_DIRECTORY/$script.lua" real - ' - fi + test_expect_success "STANDALONE_LUA,$lua_prereq" "$script checks with real luaossl under $(lua_version "$lua")" ' + "$lua" "$EXT_TEST_DIRECTORY/test-email-avatar.lua" "$EXTENSIONS_DIRECTORY/$script.lua" real + ' done done |
