unittests: Replace two environment variables with one TRACE_LEVEL

This commit is contained in:
ZyX
2017-04-01 20:57:23 +03:00
parent 2d158dde02
commit ac22238b6a
2 changed files with 23 additions and 15 deletions

View File

@@ -27,8 +27,8 @@ groups by the semantic component they are testing.
Test behaviour is affected by environment variables. Currently supported
(Functional, Unit, Benchmarks) (when Defined; when set to _1_; when defined,
treated as Integer; when defined, treated as String; !must be defined to
function properly):
treated as Integer; when defined, treated as String; when defined, treated as
Number; !must be defined to function properly):
`GDB` (F) (D): makes nvim instances to be run under `gdbserver`. It will be
accessible on `localhost:7777`: use `gdb build/bin/nvim`, type `target remote
@@ -103,11 +103,8 @@ defined and this variable is not) cores are checked for after each test.
`NVIM_TEST_RUN_TESTTEST` (U) (1): allows running `test/unit/testtest_spec.lua`
used to check how testing infrastructure works.
`NVIM_TEST_NO_TRACE` (U) (1): omits getting traces from tests. This means that
if tests crashed without core dump you will have no clues regarding where, but
this makes tests run a lot faster. Combine with `NVIM_TEST_MAIN_CDEFS` for
maximal speed.
`NVIM_TEST_TRACE_EVERYTHING` (U) (1): by default unit test only record C calls
which is faster then recording everything. Set this variable to 1 if you want to
see all traces.
`NVIM_TEST_TRACE_LEVEL` (U) (N): specifies unit tests tracing level: `0`
disables tracing (the fastest, but you get no data if tests crash and there was
no core dump generated), `1` or empty/undefined leaves only C function cals and
returns in the trace (faster then recording everything), `2` records all
function calls, returns and lua source lines exuecuted.

View File

@@ -539,10 +539,16 @@ local tracehelp = dedent([[
]])
local function child_sethook(wr)
if os.getenv('NVIM_TEST_NO_TRACE') == '1' then
local trace_level = os.getenv('NVIM_TEST_TRACE_LEVEL')
if not trace_level or trace_level == '' then
trace_level = 1
else
trace_level = tonumber(trace_level)
end
if trace_level <= 0 then
return
end
local trace_only_c = (os.getenv('NVIM_TEST_TRACE_EVERYTHING') ~= '1')
local trace_only_c = trace_level <= 1
local function hook(reason, lnum)
local info = nil
if reason ~= 'tail return' then -- tail return
@@ -651,9 +657,14 @@ local function check_child_err(rd)
end
local res = sc.read(rd, 2)
if #res ~= 2 then
local error = '\nTest crashed, trace:\n' .. tracehelp
for i = 1, #trace do
error = error .. trace[i]
local error
if #trace == 0 then
error = '\nTest crashed, no trace available\n'
else
error = '\nTest crashed, trace:\n' .. tracehelp
for i = 1, #trace do
error = error .. trace[i]
end
end
assert.just_fail(error)
end