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

The previous commit did not run the unit tests properly. This one does. ...

The previous commit did not run the unit tests properly.  This one does.  Also, now printing the speedup in loading from old to new.
parent 742f8f99
......@@ -438,14 +438,9 @@ end
right_column = 4
function run_unittests(rosie, test_rplx, args, filename)
function run_unittests(test_engine, test_rplx, filename, pkgname)
io.stdout:write(filename, '\n')
local test_engine, pkgname = unittest.make_test_engine(rosie, args, filename)
if not test_engine then
io.write(indent(pkgname, right_column), "\n") -- error message
return false
end
unittest.write_test_result("File compiled successfully")
local test_lines = unittest.extract_tests_from_file(filename)
if #test_lines == 0 then
unittest.write_test_result("No tests found")
......@@ -473,53 +468,50 @@ function run_unittests(rosie, test_rplx, args, filename)
return true, errors, failures, blocked, passed, total
end
function test1(filename)
-- NOTE: Using globals here, for ease of debugging
assert(test_rplx, "no test_rplx. maybe setup() not run?")
io.stdout:write("Testing " .. filename .. " ... ")
io.stdout:write("Testing ", filename, "\n")
io.stdout:flush()
-- NOTE: using globals here, for ease of debugging
src = slurp(filename)
orig = rosie.engine.new()
cli_common.setup_engine(rosie, orig, {norcfile=true})
collectgarbage('collect'); collectgarbage('collect')
t0 = os.clock()
ok, pkgname, err = orig:load(src)
assert(ok and pkgname)
t1 = os.clock()
old_time = t1 - t0
unittest.write_test_result(string.format("OLD load time %2.4f seconds", old_time))
e = new_engine()
cli_common.setup_engine(rosie, e, {norcfile=true})
collectgarbage('collect'); collectgarbage('collect')
t0 = os.clock()
ok, pkgname, err = e:load(src)
t1 = os.clock()
new_time = t1 - t0
unittest.write_test_result(
string.format("New load time %2.4f seconds, %3.0f%% change",
new_time,
((new_time - old_time) * 100) / old_time))
if ok then
if pkgname then
print("OK (loaded " .. pkgname .. ")")
unittest.write_test_result("OK (loaded " .. pkgname .. ")")
else
print("OK")
unittest.write_test_result("OK")
end
else
error("load failed. inspect 'err' for details.")
end
-- print("(not testing match() yet).")
ok, ee, ff, bb, pp, tt = run_unittests(rosie, test_rplx, {norcfile=true}, filename)
ok, ee, ff, bb, pp, tt =
run_unittests(e, test_rplx, filename, pkgname)
assert(ok)
end
-- -- Parse
-- local messages = {}
-- source = rosie.env.common.source.new{text=src}
-- a = parse_block(source, messages) -- stmt:match()
-- if a then
-- io.stdout:write("parsed with parse_block, ")
-- else
-- error("parse/prefix failed:\n" .. util.table_to_pretty_string(messages))
-- end
-- messages = {}
-- ok = rosie.env.loadpkg.validate_block(a, messages)
-- if ok then
-- io.stdout:write("validated/reorganized, ")
-- else
-- error("validate_block failed: " .. util.table_to_pretty_string(messages))
-- end
-- ok = e.compiler.expand_block(a, e.env, messages)
-- if ok then io.stdout:write("expanded, ") else error("Unknown error!", 1); end
-- if #messages ~= 0 then table.print(messages, 60) end
-- ok, err = pcall(e.compiler.compile_block, a, e.env, nil, messages)
-- if ok then io.stdout:write("loaded, ") else error("Unknown error!", 1); end
-- if #messages ~= 0 then table.print(messages, 60) end
-- -- rplx = e:compile('x')
-- -- if ok then io.stdout:write("compiled, ") else print("ERROR:"); error(err, 1); end
-- print("(not testing match() yet).")
-- end
function test()
test1("/Users/jennings/Projects/rosie-pattern-language/dev/rpl/all.rpl")
......@@ -553,6 +545,16 @@ function test()
end
function new_engine()
local e = rosie.engine.new()
parse_block = rosie.env.compile.make_parse_block(preparse, stmt, e.compiler.version, infix.to_prefix)
parse_expression = rosie.env.compile.make_parse_expression(exp, infix.to_prefix)
e.compiler.parse_block = parse_block
e.compiler.parse_expression = parse_expression
e.compiler.version = common.rpl_version.new(1,3)
return e
end
function setup()
rpl_definition_file = "rosie/rpl_1_3"
oe = rosie.engine.new()
......@@ -561,12 +563,6 @@ function setup()
stmt = assert((oe:compile('rpl_statements')))
preparse = assert((oe:compile('preparse')))
e = rosie.engine.new()
parse_block = rosie.env.compile.make_parse_block(preparse, stmt, e.compiler.version, infix.to_prefix)
parse_expression = rosie.env.compile.make_parse_expression(exp, infix.to_prefix)
e.compiler.parse_block = parse_block
e.compiler.parse_expression = parse_expression
unittest = import('unittest')
test_rplx = unittest.setup(oe, rpl_definition_file)
assert(test_rplx)
......
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