Commit 0d2d108a authored by Jamie A. Jennings's avatar Jamie A. Jennings

Refactoring unit test code, step 1: that code is now in its own module; the...

Refactoring unit test code, step 1: that code is now in its own module; the interface is the same; no changes to cli.lua except to import the new package.
parent 8843c965
......@@ -126,8 +126,8 @@ local function run(args)
-- get a fresh engine and load any rpl files or rpl strings
-- load the file being tested
-- call the test procedure
cli_test = assert(rosie.import("cli-test-command"), "failed to open cli test package")
cli_test.setup(en)
cli_test = assert(rosie.import("unittest"), "failed to open unittest package")
cli_test.setup(en, rosie.attributes.ROSIE_LIBDIR)
local total_failures, total_tests = 0, 0
local total_files, total_compiled = 0, 0
for _, fn in ipairs(args.filenames) do
......
......@@ -118,7 +118,7 @@ local function load_all()
engine = engine_module.engine
ui = import("ui")
expr = import("expr")
unittest = import("unittest")
end
---------------------------------------------------------------------------------------------------
......
-- -*- Mode: Lua; -*-
--
-- cli-test-command.lua Implements the 'test' command of the cli
-- unittest.lua Implements the 'test' command of the cli
--
-- © Copyright IBM Corporation 2017.
-- © Copyright IBM Corporation 2017, 2018, 2019.
-- LICENSE: MIT License (https://opensource.org/licenses/mit-license.html)
-- AUTHORS: Jamie A. Jennings, Kevin Zander
-- NOTE: This code badly needs to be refactored.
local unittest = {}
local rosie = import("rosie")
local p = {}
local cli_common = import("cli-common")
local io = import("io")
local common = import("common")
......@@ -38,7 +35,7 @@ local function find_test_lines(str)
end
-- setup the engine that will parse the test lines in the rpl file
function p.setup(en)
function unittest.setup(en, libdir)
local test_patterns =
[==[
includesKeyword = ("includes" / "excludes")
......@@ -51,7 +48,6 @@ function p.setup(en)
(testKeyword / includesClause)
(rpl_1_2.quoted_string ("," rpl_1_2.quoted_string)*)?
]==]
local libdir = rosie.attributes.ROSIE_LIBDIR
local ok, errs = en:loadfile(libdir .. "/rosie/rpl_1_2.rpl")
if not ok then
for _,v in ipairs(errs or {}) do
......@@ -74,7 +70,7 @@ local function indent(str, col)
return str:gsub('\n', '\n' .. string.rep(" ", col))
end
function p.run(rosie, en, args, filename)
function unittest.run(rosie, en, args, filename)
local right_column = 4
-- fresh engine for testing this file
local test_engine = rosie.engine.new()
......@@ -320,4 +316,5 @@ function p.run(rosie, en, args, filename)
return true, failures, total
end
return p
return unittest
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