Diff options
Diffstat (limited to 'tests/extensions/harness.lua')
| -rw-r--r-- | tests/extensions/harness.lua | 19 |
1 file changed, 19 insertions, 0 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. |
