# # # add_dir "tests/automate_get_file_size" # # add_file "tests/automate_get_file_size/__driver__.lua" # content [efb9dcb6dff3e51ae3942c43741cabca85136454] # # add_file "tests/automate_get_file_size/random1" # content [c9db4f88f168e4014a0b1f25a96d5ef4eede922d] # # add_file "tests/automate_get_file_size/random2" # content [94afe705d63bfae6c4f067cfa4a2d657e51993e3] # # add_file "tests/automate_get_file_size/random3" # content [7d8bda55078d5e30cb7051e38bca3ecd4bc633b5] # # patch "cmd_files.cc" # from [2edcbe2df9fb1890c646a386be837879315f0995] # to [b6fc0e569a082e6f897123a12168f1adf26c5959] # ============================================================ --- cmd_files.cc 2edcbe2df9fb1890c646a386be837879315f0995 +++ cmd_files.cc b6fc0e569a082e6f897123a12168f1adf26c5959 @@ -361,6 +361,10 @@ CMD_AUTOMATE(get_file_size, N_("FILEID") database db(app); hexenc hident(idx(args, 0)(), origin::user); file_id ident(decode_hexenc_as(hident(), hident.made_from)); + + E(db.file_version_exists(ident), origin::user, + F("no file version %s found in database") % ident); + file_size size; db.get_file_size(ident, size); output << lexical_cast(size) << "\n"; ============================================================ --- /dev/null +++ tests/automate_get_file_size/__driver__.lua efb9dcb6dff3e51ae3942c43741cabca85136454 @@ -0,0 +1,33 @@ + +mtn_setup() + +check(mtn("au", "get_file_size", string.rep("0123", 10)), 1, false, true) +check(qgrep("no file version " .. string.rep("0123", 10) .. " found in database", "stderr")) + +addfile("foo", "") +commit() + +local files = { "random1", "random2", "random3" } +local data = {} + +-- build the data forward +for _,v in pairs(files) do + get(v) + contents = readfile(v) + expected = string.len(contents) + check(mtn("au", "identify", v), 0, true, false) + ident = string.sub(readfile("stdout"), 1, -2) + + writefile("foo", contents) + commit() + + data[v] = { ["expected"]=expected, ["ident"]=ident } +end + +-- ...and check them in reverse +for idx = #files, 1, -1 do + check(mtn("au", "get_file_size", data[files[idx]].ident), 0, true, false) + got = string.sub(readfile("stdout"), 1, -2) + check(data[files[idx]].expected == tonumber(got)) +end + ============================================================ # tests/automate_get_file_size/random1 is binary ============================================================ # tests/automate_get_file_size/random2 is binary ============================================================ # tests/automate_get_file_size/random3 is binary