# # # patch "tester.lua" # from [92bd519bdfaca67c77c6db0acd7ea042c59507f8] # to [12fd8a1b610f7db1e60069e9940767b262dc4a7d] # # patch "tests/log_hides_deleted_renamed_files/__driver__.lua" # from [cd5e5d27ca6488b61b6672a762f313c85e1f05c1] # to [8d39a8271a09094ba2cdf4fc26fc031a03b7ae47] # # patch "tests/manifest_restrictions/__driver__.lua" # from [a3aa4b28c821c39e85db8bab4469bb437ded40c5] # to [831e7e7aa9020c666a549cb5a5619e835103cf5a] # # patch "tests/merge_with_add,_rename_file,_and_rename_dir/__driver__.lua" # from [66db7642587c0226a690e745d3cafcc44293c4e5] # to [705e5c74ebaf2d8e9f0be9bf247821c96d079818] # # patch "tests/netsync_transfers_public_keys/__driver__.lua" # from [1e4004a3d09ba2223ccace79a66d1c8bdcaed5c0] # to [04c76345f824f1a784fc848e2bf6c3ce00b6bc46] # # patch "tests/rename_dir_to_non-sibling/__driver__.lua" # from [f8dc21e12ae8f3b34d21cd9aa35a0b963fb9f9a4] # to [4c5001e4672b8074bb5f4cb031657ed220908950] # # patch "tests/tags_and_tagging_of_revisions/__driver__.lua" # from [dc29bb0db25ad55d49d44c7923eb57c3c6e37a2b] # to [8060d31138276d062042cd56a25d7a3947cf3b05] # # patch "testsuite.lua" # from [6c68826f2da27424628a0ce5be843955a443b258] # to [49e9abcd6630b351684304699ffa16ea87b0f993] # ============================================================ --- tester.lua 92bd519bdfaca67c77c6db0acd7ea042c59507f8 +++ tester.lua 12fd8a1b610f7db1e60069e9940767b262dc4a7d @@ -7,6 +7,15 @@ wanted_fail = false partial_skip = false -- set this to true if you skip part of the test +-- This is for redirected output from local implementations +-- of shellutils type stuff (ie, grep). +-- Reason: {set,clear}_redirect don't seem to (always?) work +-- for this (at least on Windows). +files = {} +files.stdout = nil +files.stdin = nil +files.stderr = nil + errfile = "" errline = -1 @@ -53,9 +62,18 @@ end end -function err(...) - errfile,errline = getsrcline() - error(unpack(arg)) +function err(what, level) + if level == nil then level = 2 end + errfile,errline = getsrcline() + local e + if type(what) == "table" then + e = what + if e.bt == nil then e.bt = {} end + table.insert(e.bt, debug.traceback()) + else + e = {e = what, bt = {debug.traceback()}} + end + error(e, level) end old_mkdir = mkdir @@ -195,57 +213,59 @@ return ret end -function background(path, ...) - local ret = {} - local pid = spawn(path, unpack(arg)) - if (pid == -1) then return false end - ret.pid = pid - local mt = {} - mt.__index = mt - mt.finish = function (obj, timeout) - if timeout == nil then timeout = 0 end - local ret, res = timed_wait(obj.pid, timeout) - if (res == -1) then - kill(obj.pid, 15) -- TERM - ret, res = timed_wait(obj.pid, 2) - if (res == -1) then - kill(obj.pid, 9) -- KILL - ret, res = timed_wait(obj.pid, 2) - end - end - return ret - end - mt.wait = function (obj) - local ret,_ = wait(obj.pid) - return ret - end - return setmetatable(ret, mt) -end - -function cmd(first, ...) - local args = arg - if type(first) == "table" then - args = first - first = args[1] - table.remove(args, 1) +function runcmd(cmd, prefix, bgnd) + if prefix == nil then prefix = "ts-" end + if type(cmd) ~= "table" then err("runcmd called with bad argument") end + local local_redir = cmd.local_redirect + if cmd.local_redirect == nil then + if type(cmd[1]) == "function" then + local_redir = true + else + local_redir = false + end end + if bgnd == true and type(cmd[1]) == "string" then local_redir = false end + L("runcmd: ", tostring(cmd[1]), ", local_redir = ", tostring(local_redir), ", requested = ", tostring(cmd.local_redirect), "\n") + local redir + if local_redir then + files.stdin = io.open(prefix.."stdin") + files.stdout = io.open(prefix.."stdout", "w") + files.stderr = io.open(prefix.."stderr", "w") + else + redir = set_redirect(prefix.."stdin", prefix.."stdout", prefix.."stderr") + end - if type(first) == "string" then - L(locheader(), first, " ", table.concat(args, " "), "\n") - return function () return execute(first, unpack(args)) end - elseif type(first) == "function" then - local info = debug.getinfo(first) - local name - if info.name ~= nil then - name = info.name + local result + if type(cmd[1]) == "function" then + L(locheader(), " ") + for i,x in ipairs(cmd) do + if i ~= 1 then L(" ", tostring(x)) end + end + L("\n") + result = {pcall(unpack(cmd))} + elseif type(cmd[1]) == "string" then + L(locheader()) + for i,x in ipairs(cmd) do + L(" ", tostring(x)) + end + L("\n") + if bgnd then + result = {pcall(spawn, unpack(cmd))} else - name = "" + result = {pcall(execute, unpack(cmd))} end - L(locheader(), name, " ", table.concat(args, " "), "\n") - return function () return first(unpack(args)) end else - error("cmd() called with argument of unknown type " .. type(first), 2) + err("runcmd called with bad command table") end + + if local_redir then + files.stdin:close() + files.stdout:close() + files.stderr:close() + else + redir:restore() + end + return unpack(result) end function samefile(left, right) @@ -277,15 +297,19 @@ end local quiet = string.find(flags, "q") ~= nil local reverse = string.find(flags, "v") ~= nil + if not quiet and files.stdout == nil then err("non-quiet grep not redirected") end local out = 1 + local infile = files.stdin + if where ~= nil then infile = io.open(where) end for line in io.lines(where) do local matched = regex.search(what, line) if reverse then matched = not matched end if matched then - if not quiet then print(line) end + if not quiet then files.stdout:write(line, "\n") end out = 0 end end + if where ~= nil then infile:close() end return out end return {dogrep, unpack(arg)} @@ -308,7 +332,6 @@ os.rename("stdin", ident .. "stdin") L("stdin:\n") log_file_contents(ident .. "stdin") - return set_redirect(ident .. "stdin", ident .. "stdout", ident .. "stderr") end function post_cmd(result, ret, stdout, stderr, ident) @@ -368,12 +391,11 @@ bgid = bgid + 1 local out = {} out.prefix = "ts-" .. bgid .. "-" - local redir = pre_cmd(stdin, out.prefix) - out.process = background(unpack(torun)) - redir:restore() - if out.process == false then - err("Failed to start background process\n", 2) - end + pre_cmd(stdin, out.prefix) + L("Starting background command...") + local _,pid = runcmd(torun, out.prefix, true) + if pid == -1 then err("Failed to start background process\n", 2) end + out.pid = pid bglist[bgid] = out out.id = bgid out.retval = nil @@ -382,12 +404,23 @@ out.expret = ret out.expout = stdout out.experr = stderr - L(out.locstr, "starting background command: ", table.concat(out.cmd, " "), "\n") local mt = {} mt.__index = mt mt.finish = function(obj, timeout) if obj.retval ~= nil then return end - obj.retval = obj.process:finish(timeout) + + if timeout == nil then timeout = 0 end + local res + obj.retval, res = timed_wait(obj.pid, timeout) + if (res == -1) then + kill(obj.pid, 15) -- TERM + obj.retval, res = timed_wait(obj.pid, 2) + if (res == -1) then + kill(obj.pid, 9) -- KILL + obj.retval, res = timed_wait(obj.pid, 2) + end + end + table.remove(bglist, obj.id) L(locheader(), "checking background command from ", out.locstr, table.concat(out.cmd, " ")) @@ -395,7 +428,7 @@ end mt.wait = function(obj) if obj.retval ~= nil then return end - obj.retval = obj.process:wait() + obj.retval = wait(obj.pid) table.remove(bglist, obj.id) L(locheader(), "checking background command from ", out.locstr, table.concat(out.cmd, " "), "\n") @@ -404,11 +437,10 @@ return setmetatable(out, mt) end -function check_func(func, ret, stdout, stderr, stdin) +function runcheck(cmd, ret, stdout, stderr, stdin) if ret == nil then ret = 0 end - local redir = pre_cmd(stdin) - local ok, result = pcall(func) - redir:restore() + pre_cmd(stdin) + local ok, result = runcmd(cmd) if ok == false then err(result, 2) end @@ -417,25 +449,29 @@ end function indir(dir, what) + if type(what) ~= "table" then + err("bad argument of type "..type(what).." to indir()") + end local function do_indir() - if type(what) == "table" then what = cmd(what) end - if type(what) ~= "function" then - err("bad argument of type "..type(what).." to indir()") + local savedir = chdir(dir) + local ok, res + if type(what[1]) == "function" then + ok, res = pcall(unpack(what)) + elseif type(what[1]) == "string" then + ok, res = pcall(execute, unpack(what)) + else + err("bad argument to indir(): cannot execute a "..type(what[1])) end - local savedir = chdir(dir) - local ok, res = pcall(what) chdir(savedir) if not ok then err(res) end return res end - return do_indir + return {do_indir, local_redirect = (type(what[1]) == "function")} end function check(first, ...) if type(first) == "table" then - return check_func(cmd(first), unpack(arg)) - elseif type(first) == "function" then - return check_func(first, unpack(arg)) + return runcheck(first, unpack(arg)) elseif type(first) == "boolean" then if not first then err("Check failed: false", 2) end elseif type(first) == "number" then @@ -466,6 +502,18 @@ end end +function log_error(e) + if type(e) == "table" then + test_log:write("\n", tostring(e.e), "\n") + for i,bt in ipairs(e.bt) do + if i ~= 1 then test_log:write("Rethrown from:") end + test_log:write(bt) + end + else + test_log:write("\n", tostring(e), "\n") + end +end + function run_tests(args) local torun = {} local run_all = true @@ -568,19 +616,23 @@ counts.success = counts.success + 1 end else - if e == true then + if type(e) ~= "table" then + local tbl = {e = e, bt = {"no backtrace; type(err) = "..type(e)}} + e = tbl + end + if e.e == true then P(string.format("skipped (line %i)\n", errline)) test_log:close() if not debugging then clean_test_dir(testname) end counts.skip = counts.skip + 1 - elseif e == false then + elseif e.e == false then P(string.format("expected failure (line %i)\n", errline)) test_log:close() leave_test_dir() counts.xfail = counts.xfail + 1 else P(string.format("FAIL (line %i)\n", errline)) - test_log:write("\n", e, "\n") + log_error(e) table.insert(failed_testlogs, tlog) test_log:close() leave_test_dir() ============================================================ --- tests/log_hides_deleted_renamed_files/__driver__.lua cd5e5d27ca6488b61b6672a762f313c85e1f05c1 +++ tests/log_hides_deleted_renamed_files/__driver__.lua 8d39a8271a09094ba2cdf4fc26fc031a03b7ae47 @@ -30,10 +30,14 @@ rename("stdout", "log") check(grep("^Addition of [a-z][a-z][a-z].$", "log"), 0, true) getfile("first") +canonicalize("first") +canonicalize("stdout") check(samefile("stdout", "first")) check(mtn("log"), 0, true, false) -rename("stdout", "log") +rename_over("stdout", "log") check(grep("^Addition of [a-z][a-z][a-z].$", "log"), 0, true) getfile("second") +canonicalize("second") +canonicalize("stdout") check(samefile("stdout", "second")) ============================================================ --- tests/manifest_restrictions/__driver__.lua a3aa4b28c821c39e85db8bab4469bb437ded40c5 +++ tests/manifest_restrictions/__driver__.lua 831e7e7aa9020c666a549cb5a5619e835103cf5a @@ -191,8 +191,8 @@ -- include rename source and target -check(cmd(mtn("commit", "--message=move fileX to file1", - "work/fileX", "work/file1")), 0, false, false) +check(mtn("commit", "--message=move fileX to file1", + "work/fileX", "work/file1"), 0, false, false) check(mtn("status"), 0, true, false) check(included(2, 3, 4)) ============================================================ --- tests/merge_with_add,_rename_file,_and_rename_dir/__driver__.lua 66db7642587c0226a690e745d3cafcc44293c4e5 +++ tests/merge_with_add,_rename_file,_and_rename_dir/__driver__.lua 705e5c74ebaf2d8e9f0be9bf247821c96d079818 @@ -51,7 +51,7 @@ check(mtn("checkout", "--revision", revs.base, "test_dir"), 0, false, false) check(indir("test_dir", mtn("update", "--branch=testbranch")), 0, false, false) -revs.test = indir("test_dir", base_revision)() +revs.test = indir("test_dir", {base_revision})[1]() for _,x in pairs{"base", "rename_dir", "added", "rename_file"} do check(revs.test ~= revs[x]) ============================================================ --- tests/netsync_transfers_public_keys/__driver__.lua 1e4004a3d09ba2223ccace79a66d1c8bdcaed5c0 +++ tests/netsync_transfers_public_keys/__driver__.lua 04c76345f824f1a784fc848e2bf6c3ce00b6bc46 @@ -21,8 +21,8 @@ -- Now check that --key-to-push works. srv = netsync.start("testbranch", 2) -check(cmd(mtn("--rcfile=netsync.lua", "push", srv.address, - "testbranch", "address@hidden")), +check(mtn("--rcfile=netsync.lua", "push", srv.address, + "testbranch", "address@hidden"), 0, false, false) srv:finish() check(mtn2("dropkey", "address@hidden"), 0, false, false) @@ -30,8 +30,8 @@ -- Now commit a version that does use the new key, and make sure that -- now it does get transferred. writefile("testfile", "version 1 of test file") -check(cmd(mtn("--branch=testbranch", "--message=blah-blah", - "address@hidden", "commit")), 0, false, false) +check(mtn("--branch=testbranch", "--message=blah-blah", + "address@hidden", "commit"), 0, false, false) netsync.pull("testbranch") ============================================================ --- tests/rename_dir_to_non-sibling/__driver__.lua f8dc21e12ae8f3b34d21cd9aa35a0b963fb9f9a4 +++ tests/rename_dir_to_non-sibling/__driver__.lua 4c5001e4672b8074bb5f4cb031657ed220908950 @@ -49,7 +49,7 @@ check(mtn("checkout", "--revision", base, "test_dir"), 0, false, false) check(indir("test_dir", mtn("--branch=testbranch", "update")), 0, false, false) -merged = indir("test_dir", base_revision)() +merged = indir("test_dir", {base_revision})[1]() check(base ~= merged) check(left ~= merged) check(right ~= merged) ============================================================ --- tests/tags_and_tagging_of_revisions/__driver__.lua dc29bb0db25ad55d49d44c7923eb57c3c6e37a2b +++ tests/tags_and_tagging_of_revisions/__driver__.lua 8060d31138276d062042cd56a25d7a3947cf3b05 @@ -43,7 +43,7 @@ canonicalize("stdout") copyfile("stdout", "stdin") rename("stdout", "stdout-orig") - check(cmd("sort"), 0, readfile("stdout-orig"), false, true) + check({"sort"}, 0, readfile("stdout-orig"), false, true) end for i,x in {{true, false, false}, ============================================================ --- testsuite.lua 6c68826f2da27424628a0ce5be843955a443b258 +++ testsuite.lua 49e9abcd6630b351684304699ffa16ea87b0f993 @@ -149,7 +149,9 @@ end function qgrep(what, where) - return cmd(grep("-q", what, where))() == 0 + local ok,res = pcall(unpack(grep("-q", what, where))) + if not ok then err(res) end + return res == 0 end function addfile(filename, contents) @@ -191,7 +193,7 @@ mtn("--db", db2, "ls", "keys")) check(mtn("--db", db1, "complete", "revision", ""), 0, true, false) - rename("stdout", "revs") + rename_over("stdout", "revs") check(mtn("--db", db2, "complete", "revision", ""), 0, true, false) check(samefile("stdout", "revs")) for rev in io.lines("revs") do @@ -205,7 +207,7 @@ end check(mtn("--db", db1, "complete", "file", ""), 0, true, false) - rename("stdout", "files") + rename_over("stdout", "files") check(mtn("--db", db2, "complete", "file", ""), 0, true, false) check(samefile("stdout", "files")) for file in io.lines("files") do