Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Check the log line for lexers that are not found
Every check set CGIT_SCINTILLUA_PATH, which the filter takes as given,
so the line for a server with no Scintillua at all never ran and
deleting it passed. The harness can now clear a variable and hide the
directories the filter probes. A lexer.lua anywhere on LUA_PATH also
loaded in place of the missing one, so the fallback runs now keep
every Lua module out of reach.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/extensions/harness.lua | 19 | |
| -rw-r--r-- | tests/extensions/test-syntax-highlight.lua | 29 | |
| -rwxr-xr-x | tests/t0502-syntax-highlight.sh | 30 |
3 files changed, 60 insertions, 18 deletions
diff --git a/tests/extensions/harness.lua b/tests/extensions/harness.lua index 1e2fe08..78e491e 100644 --- a/tests/extensions/harness.lua +++ b/tests/extensions/harness.lua @@ -160,6 +160,25 @@ function harness.redirect_file(from, to) path_map[from] = to end +-- Set or clear an environment variable as a script sees it, for a check +-- that needs the environment to differ from the one the shell gave this +-- run. A variable set to nil reads as unset. +local env_map = nil + +function harness.setenv(name, value) + if env_map == nil then + env_map = {} + local real_getenv = os.getenv + os.getenv = function(key) + if env_map[key] == nil then + return real_getenv(key) + end + return env_map[key] or nil + end + end + env_map[name] = value or false +end + -- Deterministic bytes standing in for a digest, built from djb2 style lanes -- in plain arithmetic so they compute the same on every Lua version. Not -- cryptographic, just stable and collision-shy enough for the checks. diff --git a/tests/extensions/test-syntax-highlight.lua b/tests/extensions/test-syntax-highlight.lua index 08cc72d..d8e5224 100644 --- a/tests/extensions/test-syntax-highlight.lua +++ b/tests/extensions/test-syntax-highlight.lua @@ -4,8 +4,10 @@ -- life of the interpreter, so the two sides of that split are two runs of -- this file. In highlight mode the shell points CGIT_SCINTILLUA_PATH at the -- fake-lexers directory beside this file and every path through a working --- lexer is checked, and in nolexers mode it points at an empty directory so --- the escaped fallback is what everything renders through. +-- lexer is checked. In nolexers mode it points at an empty directory, so +-- the escaped fallback is what everything renders through, and the run ends +-- with every directory the filter probes hidden, for a server with no +-- Scintillua at all. local test_directory = arg[0]:match("^(.*)/") or "." local h = dofile(test_directory .. "/harness.lua") @@ -21,10 +23,10 @@ end if mode == "nolexers" then local out, ret = render("hello.fake", "if 42") - h.equals("without lexers source is served escaped", out, "if 42") + h.equals("without lexers the source passes through uncoloured", out, "if 42") h.equals("close answers zero", ret, 0) - h.contains("and the error log says the lexers would not load", h.error_log(), - "Unable to load the Scintillua lexers") + h.equals("and the error log says the lexers would not load", h.error_log(), + "[cgit] Unable to load the Scintillua lexers: module 'lexer' not found:\n") out = render("hello.fake", "a <b> & c") h.equals("the fallback escapes markup", out, "a <b> & c") @@ -47,6 +49,23 @@ if mode == "nolexers" then h.equals("a separator across a slice boundary is still escaped", out, string.rep("x", 64 * 1024 - 1) .. "<span class='escape'>\\u2028</span>y") + -- With the variable unset and no lexers beside cgitrc or in any directory + -- the filter probes, it finds nothing to load, the usual case on a server + -- without Scintillua. + local file = assert(io.open(script, "rb")) + local source = file:read("*a") + file:close() + for dir in source:match("local scintillua_dirs = (%b{})"):gmatch('"([^"]+)"') do + h.redirect_file(dir .. "/lexer.lua", "/nonexistent/lexer.lua") + end + h.setenv("CGIT_SCINTILLUA_PATH", nil) + h.setenv("CGIT_CONFIG", nil) + h.load(script) + out = render("hello.fake", "a <b>") + h.equals("with no lexers found the source is served escaped", out, "a <b>") + h.equals("and the error log says none were found", h.error_log(), + "[cgit] Unable to find the Scintillua lexers, so source is shown uncoloured\n") + h.finish() end diff --git a/tests/t0502-syntax-highlight.sh b/tests/t0502-syntax-highlight.sh index 3e32e3b..c0b4480 100755 --- a/tests/t0502-syntax-highlight.sh +++ b/tests/t0502-syntax-highlight.sh @@ -1,14 +1,15 @@ #!/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, and then points the lexer path -# at nothing to see the page fall back to escaped text. +# collection is not assumed anywhere. The fake lexer module under +# extensions/fake-lexers stands in for a working one, and the fallback +# checks keep every lexer the filter could find out of its reach. The unit +# checks run twice per interpreter, once with the fake lexers found and once +# without any, 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, and then points the lexer path at nothing to see the page fall back +# to escaped text. test_description='Check the shipped syntax-highlight extension' CGIT_TEST_NO_CREATE_REPOS=YesPlease @@ -25,7 +26,7 @@ do test_expect_success STANDALONE_LUA "fallback checks without lexers under $(lua_version "$lua")" ' mkdir -p empty-lexers && - CGIT_SCINTILLUA_PATH="$PWD/empty-lexers" \ + without_lua_modules env CGIT_SCINTILLUA_PATH="$PWD/empty-lexers" \ "$lua" "$EXT_TEST_DIRECTORY/test-syntax-highlight.lua" \ "$EXTENSIONS_DIRECTORY/syntax-highlight.lua" nolexers ' @@ -69,11 +70,14 @@ test_expect_success CGIT_LUA 'bytes between tokens reach the page escaped' ' # a filter that failed there would take the whole page down with it, so it # has to hand the source back escaped instead. test_expect_success CGIT_LUA 'without scintillua the source is served escaped' ' - CGIT_SCINTILLUA_PATH=/nonexistent CGIT_CONFIG="$PWD/cgitrc" \ + echo "[cgit] Unable to load the Scintillua lexers: module ${SQ}lexer${SQ} not found:" >expect && + without_lua_modules env CGIT_SCINTILLUA_PATH=/nonexistent CGIT_CONFIG="$PWD/cgitrc" \ QUERY_STRING="url=fake/tree/hello.fake" cgit >tmp 2>err && - grep "if 42 & zz" tmp && - ! grep "hl-keyword" tmp && - grep "Unable to load the Scintillua lexers" err + test_cmp expect err && + test_grep "^Status: 200" tmp && + test_grep "</html>" tmp && + test_grep "if 42 & zz" tmp && + test_grep ! "hl-keyword" tmp ' test_expect_success CGIT_LUA 'a lone carriage return reaches the page as an escape' ' |
