# # # rename "tests/calculation_of_unififfs" # to "tests/calculation_of_unidiffs" # # patch "tester.cc" # from [d825b9f0306391410f8e06c7a1c1b9ccf8c179fc] # to [1cf081fca281581e3743b72e6f7495d99fe6e513] # # patch "tester.lua" # from [ff82901f188d30f8137afda046617769d2df5715] # to [a9561fbc79a231e66cc31da72274d23b23c77e11] # # patch "testsuite.lua" # from [d9cf07cfc76b9ab7ac28f2584e363918ec566449] # to [c04000a84ded45f0920c2fee726b5ac6f4831ab4] # ============================================================ --- tester.cc d825b9f0306391410f8e06c7a1c1b9ccf8c179fc +++ tester.cc 1cf081fca281581e3743b72e6f7495d99fe6e513 @@ -11,6 +11,8 @@ #include +#include + #include #include #include @@ -49,7 +51,13 @@ fs::path source_dir; fs::path run_dir; -struct oops {}; +struct oops : public std::exception +{ + oops(string const &s = "") throw() : err(s) {} + ~oops() throw() {} + string err; + char const * what() {return err.c_str();} +}; static int panic_thrower(lua_State * st) { @@ -136,9 +144,9 @@ static int clear_redirect(lua_State * L) { - int infd = luaL_checknumber(L, -3); - int outfd = luaL_checknumber(L, -2); - int errfd = luaL_checknumber(L, -1); + int infd = (int)luaL_checknumber(L, -3); + int outfd = (int)luaL_checknumber(L, -2); + int errfd = (int)luaL_checknumber(L, -1); clear_redirect(0, infd); clear_redirect(1, outfd); @@ -151,7 +159,11 @@ int main(int argc, char **argv) { string testfile; - if (argc > 1) + bool needhelp = false; + for (int i = 1; i < argc; ++i) + if (string(argv[i]) == "--help" || string(argv[i]) == "-h") + needhelp = true; + if (argc > 1 && !needhelp) { fs::path file(argv[1], fs::native); testfile = fs::complete(file).native_file_string(); @@ -163,7 +175,13 @@ } else { - fprintf(stderr, "Usage: %s test-file [arguments]", argv[0]); + fprintf(stderr, "Usage: %s test-file [arguments]\n", argv[0]); + fprintf(stderr, "\t-h print this message\n"); + fprintf(stderr, "\t-d don't clean the scratch directories\n"); + fprintf(stderr, "\tnum run a specific test\n"); + fprintf(stderr, "\tnum..num run tests in a range\n"); + fprintf(stderr, "\t if num is negative, count back from the end"); + fprintf(stderr, "\tregex run tests with matching names\n"); return 1; } lua_State *st = lua_open(); @@ -179,7 +197,7 @@ lua_register(st, "get_source_dir", get_source_dir); lua_register(st, "set_redirect", set_redirect); lua_register(st, "clear_redirect", clear_redirect); - lua_register(st, "clean_test_dir", go_to_test_dir); + lua_register(st, "clean_test_dir", clean_test_dir); lua_register(st, "leave_test_dir", leave_test_dir); lua_register(st, "mkdir", make_dir); lua_register(st, "remove_recursive", remove_recursive); @@ -202,7 +220,7 @@ ll.call(1,1) .extract_int(ret); } - catch (oops &e) + catch (std::exception &e) { } ============================================================ --- tester.lua ff82901f188d30f8137afda046617769d2df5715 +++ tester.lua a9561fbc79a231e66cc31da72274d23b23c77e11 @@ -215,16 +215,51 @@ end function run_tests(args) - print("Args:") + local torun = {} + local run_all = true + local debugging = false for i,a in pairs(args) do - print ("\t", i, a) + local _1,_2,l,r = string.find(a, "^(-?%d+)%.%.(-?%d+)$") + if _1 then + l = l + 0 + r = r + 0 + if l < 1 then l = table.getn(tests) + l + 1 end + if r < 1 then r = table.getn(tests) + r + 1 end + if l > r then l,r = r,l end + for j = l,r do + torun[j]=j + end + run_all = false + elseif string.find(a, "^-?%d+$") then + r = a + 0 + if r < 1 then r = table.getn(tests) + r + 1 end + torun[r] = r + run_all = false + elseif a == "-d" then + debugging = true + else + -- pattern + local matched = false + for i,t in pairs(tests) do + if regex.search(a, t) then + torun[i] = i + matched = true + end + end + if matched then + run_all = false + else + print(string.format("Warning: pattern '%s' does not match any tests.", a)) + end + end end P("Running tests...\n") local failed = 0 - for i,t in pairs(tests) do - testname = t + + local function runtest(i, tname) + testname = tname local shortname = nil - test_root, shortname = go_to_test_dir(t) + test_root, shortname = go_to_test_dir(testname) if i < 100 then P(" ") end if i < 10 then P(" ") end P(i .. " " .. shortname) @@ -247,22 +282,34 @@ end if r then P("ok\n") - clean_test_dir(testname) + test_log:close() + if not debugging then clean_test_dir(testname) end else if e == true then P("skipped\n") - clean_test_dir(testname) + test_log:close() + if not debugging then clean_test_dir(testname) end else P("FAIL\n") test_log:write("\n", e, "\n") failed = failed + 1 table.insert(failed_testlogs, tlog) + test_log:close() leave_test_dir() end end - test_log:close() end + if run_all then + for i,t in pairs(tests) do + runtest(i, t) + end + else + for i,_ in pairs(torun) do + runtest(i, tests[i]) + end + end + for i,log in pairs(failed_testlogs) do local tlog = io.open(log, "r") if tlog ~= nil then ============================================================ --- testsuite.lua d9cf07cfc76b9ab7ac28f2584e363918ec566449 +++ testsuite.lua c04000a84ded45f0920c2fee726b5ac6f4831ab4 @@ -90,7 +90,7 @@ table.insert(tests, "tests/scanning_trees") table.insert(tests, "tests/importing_a_file") table.insert(tests, "tests/generating_and_extracting_keys_and_certs") -table.insert(tests, "tests/calculation_of_unififfs") +table.insert(tests, "tests/calculation_of_unidiffs") table.insert(tests, "tests/persistence_of_passphrase") table.insert(tests, "tests/multiple_version_committing") table.insert(tests, "tests/creating_a_fork")