# # # patch "tester.cc" # from [da5d3a00ca842a183e2a6e61080e92cd630725f0] # to [37526a3e98b2b767fd696bcfd396327401ed9cdc] # # patch "tester.lua" # from [633fdce7b3d7b6da00b87b13ebc9783f86c42d02] # to [e6ccae74a62bb918e905e87d141d787e804166a7] # # patch "tests/calculation_of_unidiffs/__driver__.lua" # from [c0a0249daca57c2505f9e7b38a01719777b98019] # to [dc4049addaabebcced1d345d174db4e7abcaa7e1] # # patch "tests/renaming_and_editing_a_file/__driver__.lua" # from [83c3b6d4b1898ea545a62213725b7d82f348efd5] # to [7fcfa15642b32a2fa515afa84e1b54df0323d53b] # # patch "testsuite.lua" # from [af091d9e1c6478f69881ed2290fcc9aa197e2e74] # to [354a2946c7548b447bda504e476be5666567d54e] # # patch "visualc/monotone.sln" # from [fa18fc0588bbea416f61b2cde71037c2f1c897fd] # to [da308320cd55dee05bb3c0e5adfd6af8905a6c37] # # patch "visualc/monotone.vcproj" # from [9d46921fd44aaade50e10bc7708a2d1f31205ea6] # to [043a7d043be1dd87525e61a9c2665ccbf0777cdf] # # patch "win32/process.cc" # from [a676cde60954e4ea86ccb5f5e0c118b01e92f51e] # to [615b38daf893dd7dd4fc7856ba36684795462efc] # # patch "win32/read_password.cc" # from [e0ff008b1b8f115b4de22862b75093940b3c7b79] # to [77682e22c4209b65114b40a0a7c93e6efe8c9fea] # ============================================================ --- tester.cc da5d3a00ca842a183e2a6e61080e92cd630725f0 +++ tester.cc 37526a3e98b2b767fd696bcfd396327401ed9cdc @@ -27,15 +27,104 @@ using std::make_pair; using boost::lexical_cast; +namespace redirect +{ + enum what {in, out, err}; +} #ifdef WIN32 -#include -inline int dup2(int x, int y) {return _dup2(x,y);} -inline int dup(int x) {return _dup(x);} -inline int close(int x) {return _close(x);} +#include +namespace redirect {typedef HANDLE savetype;} +HANDLE set_redirect(redirect::what what, string where) +{ + HANDLE file; + SECURITY_ATTRIBUTES sa; + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + sa.lpSecurityDescriptor = 0; + sa.bInheritHandle = true; + if (what == redirect::in) + { + file = CreateFile(where.c_str(), + GENERIC_READ, + FILE_SHARE_READ, + &sa, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + } + else + { + file = CreateFile(where.c_str(), + GENERIC_WRITE, + 0, + &sa, + CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + NULL); + } + HANDLE old; + switch(what) + { + case redirect::in: + old = GetStdHandle(STD_INPUT_HANDLE); + SetStdHandle(STD_INPUT_HANDLE, file); + break; + case redirect::out: + old = GetStdHandle(STD_OUTPUT_HANDLE); + SetStdHandle(STD_OUTPUT_HANDLE, file); + break; + case redirect::err: + old = GetStdHandle(STD_ERROR_HANDLE); + SetStdHandle(STD_ERROR_HANDLE, file); + break; + } + return old; +} +void clear_redirect(redirect::what what, HANDLE saved) +{ + switch(what) + { + case redirect::in: + CloseHandle(GetStdHandle(STD_INPUT_HANDLE)); + SetStdHandle(STD_INPUT_HANDLE, saved); + break; + case redirect::out: + CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE)); + SetStdHandle(STD_OUTPUT_HANDLE, saved); + break; + case redirect::err: + CloseHandle(GetStdHandle(STD_ERROR_HANDLE)); + SetStdHandle(STD_ERROR_HANDLE, saved); + break; + } +} #else #include +int set_redirect(int what, string where, string mode) +{ + int saved = dup(what); + FILE *f = fopen(where.c_str(), mode.c_str()); + if (!f) + return -1; + dup2(fileno(f), what); + fclose(f); + return saved; +} +void clear_redirect(int what, int saved) +{ + dup2(saved, what); + close(saved); +} #endif +namespace redirect +{ + struct saveblock + { + savetype in; + savetype out; + savetype err; + }; +} #include map orig_env_vars; @@ -56,7 +145,7 @@ if (old) orig_env_vars.insert(make_pair(var, string(old))); else - orig_env_vars.insert(make_pair(var, "")) + orig_env_vars.insert(make_pair(var, "")); _putenv_s(var.c_str(), val.c_str()); } #else @@ -88,23 +177,7 @@ } #endif -int set_redirect(int what, string where, string mode) -{ - int saved = dup(what); - FILE *f = fopen(where.c_str(), mode.c_str()); - if (!f) - return -1; - dup2(fileno(f), what); - fclose(f); - return saved; -} -void clear_redirect(int what, int saved) -{ - dup2(saved, what); - close(saved); -} - fs::path source_dir; fs::path run_dir; @@ -191,37 +264,38 @@ } static int + clear_redirect(lua_State * L) + { + typedef redirect::saveblock rsb; + rsb const *sb = static_cast(lua_topointer(L, 1)); + clear_redirect(redirect::in, sb->in); + clear_redirect(redirect::out, sb->out); + clear_redirect(redirect::err, sb->err); + return 0; + } + + 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); - int infd = set_redirect(0, infile, "r"); - int outfd = set_redirect(1, outfile, "w"); - int errfd = set_redirect(2, errfile, "w"); + typedef redirect::saveblock rsb; + rsb *sb = static_cast (lua_newuserdata(L, sizeof(rsb))); + sb->in = set_redirect(redirect::in, infile); + sb->out = set_redirect(redirect::out, outfile); + sb->err = set_redirect(redirect::err, errfile); + lua_newtable(L); + lua_pushstring(L, "restore"); + lua_pushcfunction(L,clear_redirect); + lua_settable(L, -3); + lua_setmetatable(L, -2); - lua_pushnumber(L, infd); - lua_pushnumber(L, outfd); - lua_pushnumber(L, errfd); - return 3; + return 1; } static int - clear_redirect(lua_State * L) - { - 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); - clear_redirect(2, errfd); - - return 0; - } - - static int get_ostype(lua_State * L) { string str; @@ -263,10 +337,10 @@ needhelp = true; if (argc > 1 && !needhelp) { - fs::path file(argv[1], fs::native); - testfile = fs::complete(file).native_file_string(); + fs::path file = fs::complete(fs::path(argv[1], fs::native)); + testfile = file.native_file_string(); save_initial_path(); - source_dir = fs::complete(file.branch_path()); + source_dir = file.branch_path(); run_dir = fs::initial_path() / "tester_dir"; fs::create_directory(run_dir); go_to_workspace(run_dir.native_file_string()); ============================================================ --- tester.lua 633fdce7b3d7b6da00b87b13ebc9783f86c42d02 +++ tester.lua e6ccae74a62bb918e905e87d141d787e804166a7 @@ -54,6 +54,19 @@ old_mkdir(name) end +old_existsonpath = existsonpath +existsonpath = function(name) + local r = (old_existsonpath(name) == 0) + local what + if r then + what = "exists" + else + what = "does not exist" + end + L(locheader(), name, " ", what, " on the path\n") + return r +end + function fsize(filename) local file = io.open(filename, "r") if file == nil then error("Cannot open file " .. filename, 2) end @@ -62,8 +75,7 @@ return size end -function readfile(filename) - L(locheader(), "readfile ", filename, "\n") +function readfile_q(filename) local file = io.open(filename, "rb") if file == nil then error("Cannot open file " .. filename) @@ -73,8 +85,12 @@ return dat end -function writefile(filename, dat) - L(locheader(), "writefile ", filename, "\n") +function readfile(filename) + L(locheader(), "readfile ", filename, "\n") + return readfile_q(filename) +end + +function writefile_q(filename, dat) local file = io.open(filename, "wb") if file == nil then L("Cannot open file " .. filename) @@ -85,6 +101,11 @@ return true end +function writefile(filename, dat) + L(locheader(), "writefile ", filename, "\n") + return writefile_q(filename, dat) +end + function copyfile(from, to) L(locheader(), "copyfile ", from, " ", to, "\n") local infile = io.open(from, "rb") @@ -146,7 +167,7 @@ end function trim(str) - return string.gsub(str, "^%s*(.-)%s$", "%1") + return string.gsub(str, "^%s*(.-)%s*$", "%1") end function execute(path, ...) @@ -220,7 +241,7 @@ end function log_file_contents(filename) - L(readfile(filename)) + L(readfile_q(filename)) end -- std{out,err} can be: @@ -245,9 +266,12 @@ os.rename("stdin", "ts-stdin") L("stdin:\n") log_file_contents("ts-stdin") - local i, o, e = set_redirect("ts-stdin", "ts-stdout", "ts-stderr") + -- local i, o, e = set_redirect("ts-stdin", "ts-stdout", "ts-stderr") + local redir = set_redirect("ts-stdin", "ts-stdout", "ts-stderr") local ok, result = pcall(func) - clear_redirect(i, o, e) + -- redir:restore() + clear_redirect(redir) + -- clear_redirect(i, o, e) L("stdout:\n") log_file_contents("ts-stdout") L("stderr:\n") @@ -310,7 +334,8 @@ error("Check failed: " .. first .. " ~= 0", 2) end else - error("Bad argument to check()", 2) + errfile,errline = getsrcline() + error("Bad argument to check() (" .. type(first) .. ")", 2) end end @@ -399,7 +424,7 @@ local tlog = test_root .. "/tester.log" test_log = io.open(tlog, "w") - test_log:write("Test number ", i, ", ", shortname, "\n") + L("Test number ", i, ", ", shortname, "\n") local driverfile = srcdir .. "/" .. testname .. "/__driver__.lua" local driver, e = loadfile(driverfile) @@ -487,6 +512,7 @@ if tlog ~= nil then local dat = tlog:read("*a") tlog:close() + logfile:write("\n", string.rep("*", 50), "\n") logfile:write(dat) end end ============================================================ --- tests/calculation_of_unidiffs/__driver__.lua c0a0249daca57c2505f9e7b38a01719777b98019 +++ tests/calculation_of_unidiffs/__driver__.lua dc4049addaabebcced1d345d174db4e7abcaa7e1 @@ -7,7 +7,7 @@ getfile("firstfile", "testfile") check(cmd(mtn("add", "testfile")), 0, false, false) commit() -os.rename("testfile", "firstfile") +rename("testfile", "firstfile") -- get second file getfile("secondfile", "testfile") @@ -15,11 +15,11 @@ -- calculate diff to second file using monotone check(cmd(mtn("diff")), 0, true) canonicalize("stdout") -os.rename("stdout", "monodiff") -os.rename("testfile", "secondfile") +rename("stdout", "monodiff") +rename("testfile", "secondfile") -- see if patch likes that -os.rename("monodiff", "stdin") +rename("monodiff", "stdin") check(cmd("patch", "firstfile"), 0, false, false, true) -- see if the resulting file has been properly patched ============================================================ --- tests/renaming_and_editing_a_file/__driver__.lua 83c3b6d4b1898ea545a62213725b7d82f348efd5 +++ tests/renaming_and_editing_a_file/__driver__.lua 7fcfa15642b32a2fa515afa84e1b54df0323d53b @@ -15,12 +15,12 @@ root_f_sha=sha1("foo") -- produce 4-step path with move in the middle -os.rename("foo2", "foo") +rename_over("foo2", "foo") check(cmd(mtn("commit", "--message=edit-foo")), 0, false, false) check(cmd(mtn("rename", "foo", "bar")), 0, false, false) -os.rename("bar1", "bar") +rename_over("bar1", "bar") check(cmd(mtn("commit", "--message=rename-to-bar")), 0, false, false) -os.rename("bar2", "bar") +rename_over("bar2", "bar") check(cmd(mtn("commit", "--message=edit-bar")), 0, false, false) -- revert to root ============================================================ --- testsuite.lua af091d9e1c6478f69881ed2290fcc9aa197e2e74 +++ testsuite.lua 354a2946c7548b447bda504e476be5666567d54e @@ -84,6 +84,7 @@ function canonicalize(filename) if ostype == "Windows" then + L("Canonicalizing ", filename, "\n") local f = io.open(filename, "rb") local indat = f:read("*a") f:close() @@ -91,6 +92,8 @@ f = io.open(filename, "wb") f:write(outdat) f:close() + else + L("Canonicalization not needed (", filename, ")\n") end end ============================================================ --- visualc/monotone.sln fa18fc0588bbea416f61b2cde71037c2f1c897fd +++ visualc/monotone.sln da308320cd55dee05bb3c0e5adfd6af8905a6c37 @@ -1,15 +1,15 @@  Microsoft Visual Studio Solution File, Format Version 9.00 # Visual Studio 2005 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "monotone", "monotone.vcproj", "{83E1EB91-ABA9-4DC5-9423-87B3D977F015}" ProjectSection(ProjectDependencies) = postProject - {EFC02287-836F-470D-9955-44A8F81FB764} = {EFC02287-836F-470D-9955-44A8F81FB764} + {84286BE1-7522-4A9E-853C-27CD329B96D1} = {84286BE1-7522-4A9E-853C-27CD329B96D1} + {4B57DCC2-608A-42E3-B54F-89DAA495D7BA} = {4B57DCC2-608A-42E3-B54F-89DAA495D7BA} {FF042D9E-E5DC-4C89-AB5B-6CD03990A595} = {FF042D9E-E5DC-4C89-AB5B-6CD03990A595} - {CA00DD78-49F0-43BD-B5BB-D649C796FA95} = {CA00DD78-49F0-43BD-B5BB-D649C796FA95} + {EFC02287-836F-470D-9955-44A8F81FB764} = {EFC02287-836F-470D-9955-44A8F81FB764} {44CBCA82-69A9-40BC-9E6E-6A65797F617A} = {44CBCA82-69A9-40BC-9E6E-6A65797F617A} {A075E27B-893B-4426-9B52-D6A795F699DE} = {A075E27B-893B-4426-9B52-D6A795F699DE} - {84286BE1-7522-4A9E-853C-27CD329B96D1} = {84286BE1-7522-4A9E-853C-27CD329B96D1} - {4B57DCC2-608A-42E3-B54F-89DAA495D7BA} = {4B57DCC2-608A-42E3-B54F-89DAA495D7BA} + {CA00DD78-49F0-43BD-B5BB-D649C796FA95} = {CA00DD78-49F0-43BD-B5BB-D649C796FA95} EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Dependencies", "Dependencies", "{36B323F6-E1FE-4B73-846C-21F62E28CC90}" @@ -28,6 +28,12 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "txt2c", "txt2c.vcproj", "{EFC02287-836F-470D-9955-44A8F81FB764}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tester", "tester.vcproj", "{56C03BD7-0CFA-404B-B666-58020593A071}" + ProjectSection(ProjectDependencies) = postProject + {EFC02287-836F-470D-9955-44A8F81FB764} = {EFC02287-836F-470D-9955-44A8F81FB764} + {84286BE1-7522-4A9E-853C-27CD329B96D1} = {84286BE1-7522-4A9E-853C-27CD329B96D1} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -66,6 +72,10 @@ {EFC02287-836F-470D-9955-44A8F81FB764}.Debug|Win32.Build.0 = Debug|Win32 {EFC02287-836F-470D-9955-44A8F81FB764}.Release|Win32.ActiveCfg = Release|Win32 {EFC02287-836F-470D-9955-44A8F81FB764}.Release|Win32.Build.0 = Release|Win32 + {56C03BD7-0CFA-404B-B666-58020593A071}.Debug|Win32.ActiveCfg = Debug|Win32 + {56C03BD7-0CFA-404B-B666-58020593A071}.Debug|Win32.Build.0 = Debug|Win32 + {56C03BD7-0CFA-404B-B666-58020593A071}.Release|Win32.ActiveCfg = Release|Win32 + {56C03BD7-0CFA-404B-B666-58020593A071}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE ============================================================ --- visualc/monotone.vcproj 9d46921fd44aaade50e10bc7708a2d1f31205ea6 +++ visualc/monotone.vcproj 043a7d043be1dd87525e61a9c2665ccbf0777cdf @@ -324,10 +324,6 @@ > - - + + @@ -418,6 +418,10 @@ > + + ============================================================ --- win32/process.cc a676cde60954e4ea86ccb5f5e0c118b01e92f51e +++ win32/process.cc 615b38daf893dd7dd4fc7856ba36684795462efc @@ -132,7 +132,7 @@ memset(&si, 0, sizeof(si)); si.cb = sizeof(STARTUPINFO); /* We don't need to set any of the STARTUPINFO members */ - if (CreateProcess(realexe, (char*)cmd.c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)==0) + if (CreateProcess(realexe, (char*)cmd.c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)==0) { os_err_t errnum = GetLastError(); L(FL("CreateProcess failed, err=%s (%d)\n") % os_strerror(errnum) % errnum); ============================================================ --- win32/read_password.cc e0ff008b1b8f115b4de22862b75093940b3c7b79 +++ win32/read_password.cc 77682e22c4209b65114b40a0a7c93e6efe8c9fea @@ -20,7 +20,8 @@ I(buf != NULL); mt_stdin = GetStdHandle(STD_INPUT_HANDLE); - I(mt_stdin != INVALID_HANDLE_VALUE && mt_stdin != NULL); // NULL is non-interactive. Can't get a passphrase if we're non-interactive + I(mt_stdin != INVALID_HANDLE_VALUE); + I(mt_stdin != NULL); // NULL is non-interactive. Can't get a passphrase if we're non-interactive if (GetConsoleMode(mt_stdin, &origmode) == 0) { /* This looks like we're not a real windows console.