Commit e1d8c2ed authored by Jamie A. Jennings's avatar Jamie A. Jennings

Little tweaks.

parent 40f54e45
......@@ -140,6 +140,35 @@ local function test_exp(test_engine, pkgname, original_exp, q, should_accept, is
return (should_accept == accepted), res
end
-- Recursively search the given list of submatches for the first one where the
-- type is t. (This is depth-first search returning only a boolean.)
local function search_subs(subs, t)
if not subs then return false; end
for _, s in ipairs(subs) do
if s.type == t then
return true
elseif s.subs then
if search_subs(s.subs, t) then
return true
end
end
end -- for each sub
return false
end
-- Return value:
-- true or false or nil (where nil means failure to match) or "error"
local function test_includes(test_engine, pkgname, exp, q, id, is_local)
local matched, res = test_exp(test_engine, pkgname, exp, q, true, is_local)
if matched == nil then
return "error"
elseif matched == false then
return nil -- failure to match
end
assert(res)
return search_subs(res.subs, id)
end
-- Args to run():
-- rosie, the rosie module (for creating a new engine, and rplx objects for en)
-- en, the engine that has patterns for extracting test cases
......@@ -154,7 +183,8 @@ function unittest.run(rosie, en, args, filename)
-- set it up using whatever rpl strings or files were given on the command line
cli_common.setup_engine(rosie, test_engine, args)
io.stdout:write(filename, '\n')
-- load the rpl code we are going to test (second arg true means "do not search")
-- load the rpl code we are going to test (second arg true means "do not
-- search LIBPATH for file")
local ok, pkgname, errs, actual_path = test_engine:loadfile(filename, true)
if not ok then
local msgs = list.map(violation.tostring, errs)
......@@ -174,33 +204,6 @@ function unittest.run(rosie, en, args, filename)
unittest.write_test_result("No tests found")
return true, 0, 0
end
-- return values: true, false, nil (where nil means failure to match), or "error"
local function test_includes_ident(exp, q, id, is_local)
local function searchForID(tbl, id)
if not tbl then return false; end
-- tbl MUST BE "subs" table from a match
local found = false
for i = 1, #tbl do
if tbl[i].subs ~= nil then
found = searchForID(tbl[i].subs, id)
if found then break end
end
if tbl[i].type == id then
found = true
break
end
end
return found
end
local matched, res = test_exp(test_engine, pkgname, exp, q, true, is_local)
if matched == nil then
return "error"
elseif matched == false then
return nil -- failure to match
end
assert(res)
return searchForID(res.subs, id)
end
local failures, errors, blocked, passed, total = 0, 0, 0, 0, 0
local test_rplx, errs = en:compile("test_line")
if errs then
......@@ -240,10 +243,12 @@ function unittest.run(rosie, en, args, filename)
local includes, teststr, msg
teststr, msg = extract_test_string(m.subs[i])
if teststr then
includes = test_includes_ident(testIdentifier,
teststr,
containedIdentifier,
is_local_identifier)
includes = test_includes(test_engine,
pkgname,
testIdentifier,
teststr,
containedIdentifier,
is_local_identifier)
if includes==nil then
msg = "cannot test if " .. testIdentifier ..
" includes/excludes " .. containedIdentifier ..
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment