# # # add_file "tests/common/automate_stdio.lua" # content [62810eafcae9612d7ba8f6ba96c3ead7dce84f20] # # patch "tests/automate_stdio/__driver__.lua" # from [9264b94767d6ced5dc815494bc99d021a6899027] # to [f2079f12b35d50480b2e2b96c8e8acd7178a951a] # # patch "tests/automate_stdio_options/__driver__.lua" # from [9f9b0600a85959c0eb66344ace1d2ce3c5f5f3be] # to [84e4676457d226499bab7cf0a491208949a17862] # ============================================================ --- tests/common/automate_stdio.lua 62810eafcae9612d7ba8f6ba96c3ead7dce84f20 +++ tests/common/automate_stdio.lua 62810eafcae9612d7ba8f6ba96c3ead7dce84f20 @@ -0,0 +1,39 @@ +function run_stdio(cmd, err, which, band) + check(mtn("automate", "stdio"), 0, true, false, cmd) + + local parse_stdio = function(dat, which) + local bands = {} + local errcodes = {} + while true do + local begin,End,cmdnum,res,band,size = string.find(dat, "(%d+):(%d+):(%l):(%d+):") + if begin == nil then break end + cmdnum = cmdnum + 0 + if bands[cmdnum] == nil then + bands[cmdnum] = { m = "" } + end + local content = string.sub(dat, End+1, End+size) + if band == "m" or band == "l" then + bands[cmdnum].m = bands[cmdnum].m .. content + else + if bands[cmdnum][band] == nil then + bands[cmdnum][band] = {} + end + table.insert(bands[cmdnum][band], content) + end + dat = string.sub(dat, End + 1 + size) + errcodes[cmdnum] = tonumber(res) + end + return bands[which], errcodes[which] + end + + if which == nil then + which = 0 + end + + local bands,errcode = parse_stdio(readfile("stdout"), which) + check(err == errcode) + if band == nil then + band = "m" + end + return bands[band] +end ============================================================ --- tests/automate_stdio/__driver__.lua 9264b94767d6ced5dc815494bc99d021a6899027 +++ tests/automate_stdio/__driver__.lua f2079f12b35d50480b2e2b96c8e8acd7178a951a @@ -1,29 +1,7 @@ -mtn_setup() +include("/common/automate_stdio.lua") -function run_stdio(cmd, err) - check(mtn("automate", "stdio"), 0, true, false, cmd) +mtn_setup() - local parse_stdio = function(dat, which) - local got = {} - local err = 0 - while true do - local b,e,n,r,s = string.find(dat, "(%d+):(%d+):[lm]:(%d+):") - if b == nil then break end - n = n + 0 - if got[n] == nil then got[n] = "" end - got[n] = got[n] .. string.sub(dat, e+1, e+s) - dat = string.sub(dat, e+1+s) - err = tonumber(r) - end - if got[which] == nil then got[which] = "" end - return got[which], err - end - - local o,e = parse_stdio(readfile("stdout"), 0) - check(err == e) - return o -end - -- a number of broken input strings run_stdio("le", 1) run_stdio("l", 1) ============================================================ --- tests/automate_stdio_options/__driver__.lua 9f9b0600a85959c0eb66344ace1d2ce3c5f5f3be +++ tests/automate_stdio_options/__driver__.lua 84e4676457d226499bab7cf0a491208949a17862 @@ -1,26 +1,12 @@ -mtn_setup() +include("/common/automate_stdio.lua") -function parse_stdio(dat, which) - local got = {} - while true do - local b,e,n,s = string.find(dat, "(%d+):%d+:[lm]:(%d+):") - if b == nil then break end - n = n + 0 - if got[n] == nil then got[n] = "" end - got[n] = got[n] .. string.sub(dat, e+1, e+s) - dat = string.sub(dat, e+1+s) - end - if got[which] == nil then got[which] = "" end - L("output of command ", which, ":\n") - L(got[which]) - return got[which] -end +mtn_setup() addfile("file", "contents") commit("testbranch") writefile("file", "modified") diffcmd = "o1:r12:h:testbranche l12:content_diffe" -check(mtn("automate", "stdio"), 0, true, false, string.rep(diffcmd, 2)) -dat = readfile("stdout") -check(parse_stdio(dat, 0) == parse_stdio(dat, 1)) +diff1 = run_stdio(string.rep(diffcmd, 2), 0, 0) +diff2 = run_stdio(string.rep(diffcmd, 2), 0, 1) +check(diff1 == diff2)