diff options
Diffstat (limited to 'test/test-gall.repository.lua')
-rw-r--r-- | test/test-gall.repository.lua | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/test/test-gall.repository.lua b/test/test-gall.repository.lua index 41aa63b..88be480 100644 --- a/test/test-gall.repository.lua +++ b/test/test-gall.repository.lua @@ -133,6 +133,162 @@ function suite.all_refs() assert(refs["refs/heads/master"]) end +function suite.force_empty_tree() + local repo = test_repo() + local obj = assert(repo:force_empty_tree()) + assert(obj.type == "tree") +end + +function suite.update_ref() + local repo = test_repo() + local head = repo:get("HEAD") + assert(repo:update_ref("refs/heads/temp", head.sha)) +end + +function suite.update_ref_delete() + local repo = test_repo() + local head = repo:get("HEAD") + assert(repo:update_ref("refs/heads/master", nil)) +end + +function suite.update_ref_delete_fail() + local repo = test_repo() + local head = repo:get("HEAD") + local ok, msg = repo:update_ref("refs/heads/absent", nil, "whatever", head.sha) + assert(not ok) +end + +function suite.update_server_info() + local repo = test_repo() + assert(repo:update_server_info()) + assert(io.open("test/test_repo/.git/info/refs", "r")) +end + +function suite.update_server_info_bad() + local repo = test_repo() + repo.path="/BONG" + assert(not repo:update_server_info()) +end + +function suite.check_pass_env() + local repo = test_repo() + local ok, out, err = repo:_run_with_input_and_env({GIT_EDITOR="foobar"}, + nil, gall.ll.chomp, + "var", "GIT_EDITOR") + assert(ok == 0) + assert(out == "foobar") +end + +function suite.merge_base() + local repo = test_repo() + local sha_1 = "dbd507be22d1e8933008f453ec62e9a6fbd8c832" + local sha_2 = "8b50f4e456886de10e5f40f10991a4451b64aea3" + local sha_b = "b972b3345490a898f46df143a7285cb7840b9845" + assert(repo:merge_base(sha_1, sha_2) == sha_b) +end + +function suite.merge_base_all() + local repo = test_repo() + local sha_1 = "dbd507be22d1e8933008f453ec62e9a6fbd8c832" + local sha_2 = "8b50f4e456886de10e5f40f10991a4451b64aea3" + local sha_b = "b972b3345490a898f46df143a7285cb7840b9845" + assert(repo:merge_base(sha_1, sha_2, true) == sha_b) +end + +function suite.merge_base_badsha() + local repo = test_repo() + local sha_1 = "dbd507be22d1e8933008f453ec62e9a6fbd8c833" + local sha_2 = "8b50f4e456886de10e5f40f10991a4451b64aea3" + local ok, msg = repo:merge_base(sha_1, sha_2) + assert(not ok) +end + +function suite.merge_base_nobase() + local repo = test_repo() + local sha_1 = "dbd507be22d1e8933008f453ec62e9a6fbd8c832" + local sha_2 = "ca4e324f8a86ed08d3467a1588dc01a8609a4004" + local ok, msg = repo:merge_base(sha_1, sha_2) + assert(ok == true) +end + +function suite.rev_list() + local repo = test_repo() + local sha_new = "0b65c32b6a5277ff0e75ddad9e3914148914042d" + local sha_old = "b972b3345490a898f46df143a7285cb7840b9845" + local rlist = assert(repo:rev_list(sha_old, sha_new)) +end + +function suite.rev_list_backward() + local repo = test_repo() + local sha_new = "0b65c32b6a5277ff0e75ddad9e3914148914042d" + local sha_old = "b972b3345490a898f46df143a7285cb7840b9845" + local rlist = assert(repo:rev_list(sha_new, sha_old) == true) +end + +function suite.rev_list_first() + local repo = test_repo() + local sha_new = "0b65c32b6a5277ff0e75ddad9e3914148914042d" + local sha_old = "b972b3345490a898f46df143a7285cb7840b9845" + local rlist = assert(repo:rev_list(sha_old, sha_new, true)) +end + +function suite.rev_list_bad() + local repo = test_repo() + local sha_new = "0b65c32b6a5277ff0e75ddad9e3914148914042e" + local sha_old = "b972b3345490a898f46df143a7285cb7840b9845" + assert(not repo:rev_list(sha_old, sha_new)) +end + +function suite.symbolic_ref() + local repo = test_repo() + local ok, ref = repo:symbolic_ref "HEAD" + assert(ok) + assert(ref == "refs/heads/master") +end + +function suite.symbolic_ref_not_symbolic() + local repo = test_repo() + local ok, ref = repo:symbolic_ref "refs/heads/master" + assert(ok == false) +end + +function suite.symbolic_ref_bad_name() + local repo = test_repo() + local ok, ref = repo:symbolic_ref "refs" + assert(ok == nil) + assert(ref:find("No such ref")) +end + +function suite.symbolic_ref_set() + local repo = test_repo() + local ok = repo:symbolic_ref("HEAD", "refs/heads/signed") + assert(ok) + local ok, ref = repo:symbolic_ref "HEAD" + assert(ok) + assert(ref == "refs/heads/signed") +end + +function suite.symbolic_ref_set_bad() + local repo = test_repo() + local ok, msg = repo:symbolic_ref("refs", "refs/heads/signed") + assert(ok == nil) +end + +function suite.config_read() + local repo = test_repo() + local ok, conf = repo:config("core.bare") + assert(ok) + assert(conf == "false") +end + +function suite.config_write() + local repo = test_repo() + local ok = repo:config("gall.test", "thingy") + local ok, conf = repo:config("gall.test") + assert(ok) + assert(conf == "thingy") +end + local count_ok = 0 for _, testname in ipairs(testnames) do -- print("Run: " .. testname) |