# # # add_dir "tests/change_workspace" # # add_file "tests/change_workspace/__driver__.lua" # content [cadfc1b8ddd93e56f5d87b1987b18246dd1e16d6] # # add_file "tests/change_workspace/test_hooks.lua" # content [2511c2e5f0e3305eb895e6f52fba49267dfcf23f] # ============================================================ --- tests/change_workspace/__driver__.lua cadfc1b8ddd93e56f5d87b1987b18246dd1e16d6 +++ tests/change_workspace/__driver__.lua cadfc1b8ddd93e56f5d87b1987b18246dd1e16d6 @@ -0,0 +1,28 @@ +-- Test Lua extension 'change_workspace' + +mtn_setup() + +-- We can't run Lua extensions directly from here, so we override the +-- normal test_hooks to provide a function that calls change_workspace +check(get("test_hooks.lua")) + +mkdir("aaron") +mkdir("betty") +check(indir("aaron", mtn("setup", "--branch=aaronbranch", ".")), 0, false, false) +check(indir("betty", mtn("setup", "--branch=bettybranch", ".")), 0, false, false) + +check(mtn("get_branch", "aaron"), 0, true, true) +check(readfile("stdout") == "aaronbranch\n") + +check(mtn("get_branch", "betty"), 0, true, true) +check(readfile("stdout") == "bettybranch\n") + +-- error cases +check(mtn("get_branch", "bogus"), 0, true, true) +check(qgrep("error: cannot change to directory .*/bogus", "stdout")) + +mkdir("other") +check(mtn("get_branch", "other"), 0, true, true) +check(qgrep("directory .*/other is not a workspace", "stdout")) + +-- end of file ============================================================ --- tests/change_workspace/test_hooks.lua 2511c2e5f0e3305eb895e6f52fba49267dfcf23f +++ tests/change_workspace/test_hooks.lua 2511c2e5f0e3305eb895e6f52fba49267dfcf23f @@ -0,0 +1,14 @@ +function get_branch(workspace) + local status, msg + status, msg = change_workspace(workspace) + if status then + _, msg = mtn_automate("get_option", "branch") + io.write(msg) + else + io.write(msg) + end +end + +register_command("get_branch", "workspace", "", "", "get_branch") + +-- end of file