# # # add_file "tester.cc" # content [cee71a1f004e66cdd9447c23f1c16f9bfdb0c246] # # add_file "tester.lua" # content [d2599eb84ec8f4a69baa547248fb39bb33f27c3b] # # patch "ChangeLog" # from [370663977be26921f4776ab93b7ec53f6f8aee8d] # to [03ae5685394a3b8b37410270305a8708ca3b0d4f] # # patch "Makefile.am" # from [14af4c728a8cdfc6154741d88841de958b71a7df] # to [07bd9acc2044ae79e1f2286aa62a4ffa8ff15e22] # ============================================================ --- tester.cc cee71a1f004e66cdd9447c23f1c16f9bfdb0c246 +++ tester.cc cee71a1f004e66cdd9447c23f1c16f9bfdb0c246 @@ -0,0 +1,133 @@ + +extern "C" { +#include +#include +#include +} + +#include "lua.hh" +#include "tester.h" +#include "paths.hh" + +#include + +#include +#include +#include +#include + +using std::string; +using boost::lexical_cast; + +fs::path source_dir; +fs::path run_dir; + +struct oops {}; + +static int panic_thrower(lua_State * st) +{ + throw oops(); +} + +extern "C" +{ + static int + go_to_test_dir(lua_State * L) + { + char const * testname = luaL_checkstring(L, -1); + fs::path tname(testname, fs::native); + fs::path testdir = run_dir / tname.leaf(); + fs::create_directory(testdir); + go_to_workspace(testdir.native_file_string()); + lua_pushstring(L, testdir.native_file_string().c_str()); + return 1; + } + + static int + get_source_dir(lua_State * L) + { + lua_pushstring(L, source_dir.native_file_string().c_str()); + return 1; + } + + /* + static int + set_redirect(lua_State * L) + { + char const * infile = luaL_checkstring(L, -3); + char const * outfile = luaL_checkstring(L, -2); + char const * errfile = luaL_checkstring(L, -1); + + lua_pushnumber(L, infd); + lua_pushnumber(L, outfd); + lua_pushnumber(L, errfd); + return 3; + } + + 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); + return 0; + } + */ +} + +int main(int argc, char **argv) +{ + string testfile; + if (argc > 1) + { + fs::path file(argv[1], fs::native); + testfile = argv[1]; + save_initial_path(); + source_dir = fs::complete(file.branch_path()); + run_dir = fs::initial_path() / "tester_dir"; + fs::create_directory(run_dir); + } + else + { + fprintf(stderr, "Usage: %s test-file [arguments]", argv[0]); + return 1; + } + lua_State *st = lua_open(); + lua_atpanic (st, &panic_thrower); + luaopen_base(st); + luaopen_io(st); + luaopen_string(st); + luaopen_math(st); + luaopen_table(st); + luaopen_debug(st); + add_functions(st); + lua_register(st, "go_to_test_dir", go_to_test_dir); + lua_register(st, "get_source_dir", get_source_dir); +// lua_register(st, "set_redirect", set_redirect); +// lua_register(st, "clear_redirect", clear_redirect); + + int ret = 2; + try + { + run_string(st, tester_constant, "tester builtin functions"); + printf("Loading test file %s\n", testfile.c_str()); + run_file(st, testfile); + Lua ll(st); + ll.func("run_tests"); + ll.push_table(); + for (int i = 2; i < argc; ++i) + { + ll.push_int(i-1); + ll.push_str(argv[i]); + ll.set_table(); + } + ll.call(1,1) + .extract_int(ret); + } + catch (oops &e) + { + } + + lua_close(st); + return ret; +} ============================================================ --- tester.lua d2599eb84ec8f4a69baa547248fb39bb33f27c3b +++ tester.lua d2599eb84ec8f4a69baa547248fb39bb33f27c3b @@ -0,0 +1,60 @@ +tests = {} +srcdir = get_source_dir() +test_root = nil +testname = nil + +function getfile(name) + local infile = io.open(srcdir .. "/" .. testname .. "/" .. name, "rb") + local outfile = io.open(name, "wb") + local size = 2^13 + while true do + local block = infile:read(size) + if not block then break end + outfile:write(block) + end + infile:close() + outfile:close() +end + +function execute(path, ...) + local pid + local ret = -1 + pid = spawn(path, unpack(arg)) + if (pid ~= -1) then ret, pid = wait(pid) end + return ret +end + +function prepare(...) + return function () return execute(unpack(arg)) end +end + +function check(func, ret, stdout, stderr, stdin) + if ret == nil then ret = 0 end + -- local i, o, e = set_redirect("stdin", "stdout", "stderr") + local result = func() + -- clear_redirect(i, o, e) + if result ~= ret then + error("Check failed: wanted " .. ret .. " got " .. result, 2) + end +end + +function run_tests(args) + print("Args:") + for i,a in pairs(args) do + print ("\t", i, a) + end + print("Running tests...") + for i,t in pairs(tests) do + testname = t + io.write(i .. "\t" .. testname .. "\t") + test_root = go_to_test_dir(testname) + local driver = srcdir .. "/" .. testname .. "/__driver__.lua" + local r,e = xpcall(loadfile(driver), debug.traceback) + if r then + io.write("OK.\n") + else + io.write("Test failed: " .. e .. "\n") + end + end + return 0 +end ============================================================ --- ChangeLog 370663977be26921f4776ab93b7ec53f6f8aee8d +++ ChangeLog 03ae5685394a3b8b37410270305a8708ca3b0d4f @@ -1,3 +1,13 @@ +2006-05-23 Timothy Brownawell + + * tester.cc tester.lua: New files, which will eventually become a + new testsuite system. + * Makefile.am: Break sanity.* and dependencies out as + SANITY_CORE_SOURCES. Break lua.* and non-sanity dependencies out + as LUAEXT_SOURCES. Right now these are just included into MOST_SOURCES, + maybe compile them into .a files later? New target tester also + uses these. + 2006-05-22 Timothy Brownawell * file_io.{cc,hh} localized_file_io.{cc,hh}: Split off the functions ============================================================ --- Makefile.am 14af4c728a8cdfc6154741d88841de958b71a7df +++ Makefile.am 07bd9acc2044ae79e1f2286aa62a4ffa8ff15e22 @@ -6,36 +6,41 @@ cmd_merging.cc cmd_db.cc cmd_diff_log.cc cmd_ws_commit.cc \ cmd_othervcs.cc cmd_automate.cc cmd_files.cc +SANITY_CORE_SOURCES = \ + sanity.cc sanity.hh ui.cc ui.hh quick_alloc.hh \ + vocab.hh vocab.cc vocab_terms.hh vocab_macros.hh \ + charset.cc charset.hh \ + simplestring_xform.cc simplestring_xform.hh \ + constants.cc constants.hh numeric_vocab.hh paths.cc paths.hh \ + interner.hh hash_map.hh platform.hh + +LUAEXT_SOURCES = \ + lua.cc lua.hh mkstemp.cc mkstemp.hh file_io.cc file_io.hh \ + globish.cc globish.hh basic_io.cc basic_io.hh + MOST_SOURCES = \ + $(SANITY_CORE_SOURCES) $(LUAEXT_SOURCES) \ app_state.cc app_state.hh \ commands.cc commands.hh $(CMD_SOURCES) \ diff_patch.cc diff_patch.hh \ - lua.cc lua.hh lua_hooks.cc lua_hooks.hh \ - transforms.cc transforms.hh charset.cc charset.hh \ - simplestring_xform.cc simplestring_xform.hh \ + lua_hooks.cc lua_hooks.hh \ + transforms.cc transforms.hh \ update.cc update.hh \ work.cc work.hh \ cert.cc cert.hh \ database.cc database.hh \ key_store.cc key_store.hh \ - file_io.cc file_io.hh localized_file_io.cc localized_file_io.hh\ + localized_file_io.cc localized_file_io.hh \ keys.cc keys.hh \ packet.cc packet.hh \ - sanity.cc sanity.hh \ - vocab.cc vocab.hh vocab_terms.hh \ - numeric_vocab.hh vocab_macros.hh \ rcs_file.cc rcs_file.hh \ xdelta.cc xdelta.hh \ - ui.cc ui.hh \ schema_migration.cc schema_migration.hh \ - constants.cc constants.hh \ refiner.cc refiner.hh \ enumerator.cc enumerator.hh \ netsync.cc netsync.hh \ netcmd.cc netcmd.hh \ merkle_tree.cc merkle_tree.hh \ - basic_io.cc basic_io.hh \ - mkstemp.cc mkstemp.hh \ lcs.cc lcs.hh \ rcs_import.cc rcs_import.hh \ revision.cc revision.hh \ @@ -50,21 +55,19 @@ annotate.cc annotate.hh \ restrictions.cc restrictions.hh \ hmac.cc hmac.hh \ - globish.cc globish.hh \ string_queue.cc string_queue.hh \ - paths.cc paths.hh \ roster_merge.cc roster_merge.hh \ merge.cc merge.hh \ legacy.cc legacy.hh \ \ lru_cache.h \ \ - cleanup.hh unit_tests.hh interner.hh \ - cycle_detector.hh randomfile.hh adler32.hh quick_alloc.hh \ + cleanup.hh unit_tests.hh \ + cycle_detector.hh randomfile.hh adler32.hh \ netio.hh smap.hh gettext.h \ package_revision.c package_revision.h \ package_full_revision.c package_full_revision.h options.hh \ - i18n.h hash_map.hh parallel_iter.hh safe_map.hh pch.hh + i18n.h parallel_iter.hh safe_map.hh pch.hh NETXX_SOURCES = \ netxx/accept.cxx netxx/accept.h netxx/address.cxx \ @@ -232,11 +235,12 @@ bin_PROGRAMS = mtn check_PROGRAMS = unit_tests noinst_PROGRAMS = txt2c -EXTRA_PROGRAMS = usher +EXTRA_PROGRAMS = usher tester mtn_SOURCES = $(MOST_SOURCES) monotone.cc main.cc usher_SOURCES = contrib/usher.cc unit_tests_SOURCES = $(MOST_SOURCES) unit_tests.cc crypto_tests.cc +tester_SOURCES = $(SANITY_CORE_SOURCES) $(LUAEXT_SOURCES) tester.cc txt2c_SOURCES = txt2c.cc @@ -300,6 +304,10 @@ unit_tests_CPPFLAGS = -DBUILD_UNIT_TESTS -I$(top_srcdir)/lua -I$(top_srcdir)/sqlite unit_tests_CXXFLAGS = $(AM_CXXFLAGS) $(PCH_FLAGS) +tester_LDFLAGS = +tester_CPPFLAGS = -I$(top_srcdir)/lua +tester_CXXFLAGS = $(AM_CXXFLAGS) + # conditionals from configury if STATIC_BOOST @@ -309,13 +317,16 @@ mtn_LDADD = lib3rdparty.a $(BOOSTLIBS) unit_tests_LDADD = lib3rdparty.a $(BOOSTLIBS) \ @BOOST_LIBDIR@/libboost_unit_test_framework$(BOOST_SUFFIX).a + tester_LDADD = lib3rdparty.a else mtn_LDADD = lib3rdparty.a unit_tests_LDADD = lib3rdparty.a -lboost_unit_test_framework$(BOOST_SUFFIX) + tester_LDADD = lib3rdparty.a endif mtn_LDADD += libplatform.a $(LIBICONV) $(LIBINTL) unit_tests_LDADD += libplatform.a $(LIBICONV) $(LIBINTL) +tester_LDADD += libplatform.a $(LIBICONV) $(LIBINTL) if WIN32_PLATFORM libplatform_a_SOURCES += $(WIN32_PLATFORM_SOURCES) @@ -382,7 +393,7 @@ monotone.html \ texinfo.css \ schema.sql views.sql \ - std_hooks.lua test_hooks.lua \ + std_hooks.lua test_hooks.lua tester.lua \ testsuite.at \ $(wildcard $(srcdir)/tests/t_*.at) \ testsuite \ @@ -480,7 +491,8 @@ # we generate some headers to copy data into the executable -BUILT_SOURCES_CLEAN = std_hooks.h test_hooks.h schema.h views.h \ +BUILT_SOURCES_CLEAN = std_hooks.h test_hooks.h tester.h \ + schema.h views.h \ package_revision.c \ package_full_revision.txt package_full_revision_raw.txt package_full_revision.c \ $(PCH_FILE) $(PCH_BUILD)