diff options
author | Mark Pulford <mark@kyne.com.au> | 2012-01-04 07:57:21 +1030 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2012-03-04 18:54:34 +1030 |
commit | c7fbb8e441b6a62e0d6d016add8ed6b44d90d981 (patch) | |
tree | 945b22e73281a8885ea9ae8953fdb5f200ec57f8 /tests/cjson-misc.lua | |
parent | 9f85048c49caca1d1774c96681546b178cb7ca78 (diff) | |
download | lua-cjson-c7fbb8e441b6a62e0d6d016add8ed6b44d90d981.tar.gz lua-cjson-c7fbb8e441b6a62e0d6d016add8ed6b44d90d981.tar.bz2 lua-cjson-c7fbb8e441b6a62e0d6d016add8ed6b44d90d981.zip |
Update bench.lua to support different JSON modules
- Select via JSON_MODULE environment variable (default "cjson")
- Custom runtime configuration can be stored in bench-MODNAME.lua
- Add run_script() to cjson-misc and update lua2cjson.lua
Diffstat (limited to 'tests/cjson-misc.lua')
-rw-r--r-- | tests/cjson-misc.lua | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/tests/cjson-misc.lua b/tests/cjson-misc.lua index d8bfe5e..c4462ca 100644 --- a/tests/cjson-misc.lua +++ b/tests/cjson-misc.lua | |||
@@ -239,6 +239,29 @@ local function run_test_group(testgroup, tests) | |||
239 | end | 239 | end |
240 | end | 240 | end |
241 | 241 | ||
242 | -- Run a Lua script in a separate environment | ||
243 | local function run_script(script, env) | ||
244 | local env = env or {} | ||
245 | local func | ||
246 | |||
247 | -- Use setfenv() if it exists, otherwise assume Lua 5.2 load() exists | ||
248 | if _G.setfenv then | ||
249 | func = loadstring(script) | ||
250 | if func then | ||
251 | setfenv(func, env) | ||
252 | end | ||
253 | else | ||
254 | func = load(script, nil, nil, env) | ||
255 | end | ||
256 | |||
257 | if func == nil then | ||
258 | error("Invalid syntax.") | ||
259 | end | ||
260 | func() | ||
261 | |||
262 | return env | ||
263 | end | ||
264 | |||
242 | -- Export functions | 265 | -- Export functions |
243 | return { | 266 | return { |
244 | serialise_value = serialise_value, | 267 | serialise_value = serialise_value, |
@@ -247,7 +270,8 @@ return { | |||
247 | compare_values = compare_values, | 270 | compare_values = compare_values, |
248 | run_test_summary = run_test_summary, | 271 | run_test_summary = run_test_summary, |
249 | run_test = run_test, | 272 | run_test = run_test, |
250 | run_test_group = run_test_group | 273 | run_test_group = run_test_group, |
274 | run_script = run_script | ||
251 | } | 275 | } |
252 | 276 | ||
253 | -- vi:ai et sw=4 ts=4: | 277 | -- vi:ai et sw=4 ts=4: |