summaryrefslogtreecommitdiff
path: root/test/test-gall.repository.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-gall.repository.lua')
-rw-r--r--test/test-gall.repository.lua150
1 files changed, 150 insertions, 0 deletions
diff --git a/test/test-gall.repository.lua b/test/test-gall.repository.lua
new file mode 100644
index 0000000..41aa63b
--- /dev/null
+++ b/test/test-gall.repository.lua
@@ -0,0 +1,150 @@
+-- test/test-gall.repository.lua
+--
+-- Git Abstraction layer for Lua - Repository tests
+--
+-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org>
+--
+-- For Licence terms, see COPYING
+--
+
+-- This test includes repository wibbling
+dofile "test/withrepo.lua"
+
+-- Step one, start coverage
+
+local luacov = require 'luacov'
+
+local gall = require 'gall'
+
+local testnames = {}
+
+local real_assert = assert
+local total_asserts = 0
+local function assert(...)
+ local retval = real_assert(...)
+ total_asserts = total_asserts + 1
+ return retval
+end
+
+local function add_test(suite, name, value)
+ rawset(suite, name, value)
+ testnames[#testnames+1] = name
+end
+
+local suite = setmetatable({}, {__newindex = add_test})
+
+function suite.find_current_dot_git()
+ assert(gall.repository.new("./.git"))
+end
+
+function suite.find_current()
+ assert(gall.repository.new("."))
+end
+
+function suite.fail_to_find()
+ local ok, msg = gall.repository.new("/DOES_NOT_EXIST")
+ assert(not ok)
+ assert(msg:find("DOES_NOT_EXIST"))
+end
+
+function suite.make_repo()
+ assert(gall.repository.create("test/test_repo"))
+end
+
+function suite.make_repo_full()
+ assert(gall.repository.create("test/test_repo", true))
+end
+
+function suite.make_fail()
+ local ok, msg = gall.repository.create("/dev/null/CANNOT_CREATE")
+ assert(not ok)
+ assert(msg:find("CANNOT_CREATE"))
+end
+
+function suite.repo_tostring()
+ local repo = assert(gall.repository.new("."))
+ local repstr = tostring(repo)
+ assert(repstr:find("GitRepository"))
+ assert(repstr:find("%./%.git"))
+end
+
+function suite.repo_hash_blob()
+ local repo = assert(gall.repository.create("test/test_repo"))
+ local sha = repo:hash_object("blob", "FOOBAR")
+ assert(sha == "389865bb681b358c9b102d79abd8d5f941e96551")
+end
+
+function suite.repo_create_blob()
+ local repo = assert(gall.repository.create("test/test_repo"))
+ local sha = repo:hash_object("blob", "FOOBAR", true)
+ assert(sha == "389865bb681b358c9b102d79abd8d5f941e96551")
+end
+
+function suite.repo_create_retrieve_blob()
+ local repo = assert(gall.repository.create("test/test_repo"))
+ local sha = repo:hash_object("blob", "FOOBAR", true)
+ assert(sha == "389865bb681b358c9b102d79abd8d5f941e96551")
+ local repo2 = assert(gall.repository.new("test/test_repo"))
+ local obj = repo2:get("389865bb681b358c9b102d79abd8d5f941e96551")
+ assert(obj)
+ assert(obj.type == "blob")
+ assert(obj.content == "FOOBAR")
+end
+
+function suite.normalise_bad_ref()
+ local repo = assert(gall.repository.new("."))
+ local ok, msg = repo:normalise("PANTS")
+ assert(not ok)
+ assert(msg:find("PANTS"))
+end
+
+function suite.normalise_good_ref()
+ local repo = assert(gall.repository.new("."))
+ assert(repo:normalise("refs/heads/master"))
+end
+
+function suite.normalise_short_sha()
+ local repo = assert(gall.repository.new("."))
+ assert(repo:normalise("988de21"))
+end
+
+function suite.error_normalise()
+ local repo = assert(gall.repository.new("."))
+ repo.path = "/DOES_NOT_EXIST"
+ assert(not xpcall(function()repo:normalise("PANTS")end))
+end
+
+function suite.get_bad()
+ local repo = assert(gall.repository.new("."))
+ local ok, msg = repo:get("PANTS")
+ assert(not ok)
+ assert(msg:find("PANTS"))
+end
+
+function suite.get_ref()
+ local repo = assert(gall.repository.new("."))
+ assert(repo:get_ref("refs/heads/master"))
+end
+
+function suite.all_refs()
+ local repo = assert(gall.repository.new("."))
+ local refs, msg = repo:all_refs()
+ assert(refs, msg)
+ assert(refs["refs/heads/master"])
+end
+
+local count_ok = 0
+for _, testname in ipairs(testnames) do
+-- print("Run: " .. testname)
+ local ok, err = xpcall(suite[testname], debug.traceback)
+ if not ok then
+ print(err)
+ print()
+ else
+ count_ok = count_ok + 1
+ end
+end
+
+print(tostring(count_ok) .. "/" .. tostring(#testnames) .. " [" .. tostring(total_asserts) .. "] OK")
+
+os.exit(count_ok == #testnames and 0 or 1)