summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-09-08 16:26:45 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-09-08 16:26:45 +0100
commit2481a2b73ca6f805b13321dede1c6fb608b23b51 (patch)
tree400f845a42f1751e7a235bf3d619db6712860f57
parent3d14a3b8dfae2410778031ea55cce58a706fae33 (diff)
downloadgall-2481a2b73ca6f805b13321dede1c6fb608b23b51.tar.gz
GALL.TAG: Test tags including signed ones
-rw-r--r--lib/gall/tag.lua8
-rw-r--r--test/test-gall.tag.lua95
2 files changed, 99 insertions, 4 deletions
diff --git a/lib/gall/tag.lua b/lib/gall/tag.lua
index 707af31..7bafbe7 100644
--- a/lib/gall/tag.lua
+++ b/lib/gall/tag.lua
@@ -12,8 +12,6 @@ local objs = setmetatable({}, {__mode="k"})
local repos = setmetatable({}, {__mode="k"})
local parsed = setmetatable({}, {__mode="k"})
-local _new
-
local function parse_person(pers)
local real, email, when, tz = pers:match("^(.-) <([^>]+)> ([0-9]+) ([+-][0-9]+)$")
return {
@@ -24,6 +22,8 @@ local function parse_person(pers)
}
end
+local PGP_SIG_START = "-----BEGIN PGP SIGNATURE-----"
+
local function tagindex(tag, field)
if not parsed[tag] then
local raw = objs[tag].raw
@@ -61,7 +61,7 @@ local function tagindex(tag, field)
-- Always one tag name
rawset(tag, "tag", headers.tag[1])
-- Always one tagger
- rawset(tag, "tagger", parse_person(headers.tag[1]))
+ rawset(tag, "tagger", parse_person(headers.tagger[1]))
-- A message
rawset(tag, "message", body)
-- And an optional signature
@@ -85,7 +85,7 @@ local tagmeta = {
__tostring = tagtostring
}
-function _new(repo, obj)
+local function _new(repo, obj)
local ret = setmetatable({}, tagmeta)
objs[ret] = obj
repos[ret] = repo
diff --git a/test/test-gall.tag.lua b/test/test-gall.tag.lua
new file mode 100644
index 0000000..35f95d8
--- /dev/null
+++ b/test/test-gall.tag.lua
@@ -0,0 +1,95 @@
+-- test/test-gall.tag.lua
+--
+-- Git Abstraction layer for Lua - Tag object tests
+--
+-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org>
+--
+-- For Licence terms, see COPYING
+--
+
+-- This test includes object 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.tag_get()
+ local repo = test_repo()
+ local tag = repo:get("refs/tags/v1.0").content
+ assert(tag)
+end
+
+function suite.tag_tostring()
+ local repo = test_repo()
+ local tag = repo:get("refs/tags/v1.0").content
+ local tagstr = tostring(tag)
+ assert(tagstr:find("GitTag"))
+end
+
+function suite.tag_message()
+ local repo = test_repo()
+ local tag = repo:get("refs/tags/v1.0").content
+ local tagmsg = tag.message
+ assert(tagmsg:find("Annotated"))
+end
+
+function suite.tag_object()
+ local repo = test_repo()
+ local tag = repo:get("refs/tags/v1.0").content
+ local obj = tag.object
+ assert(obj)
+ assert(obj.type == "commit")
+end
+
+function suite.tag_tagger()
+ local repo = test_repo()
+ local tag = repo:get("refs/tags/v1.0").content
+ local person = tag.tagger
+ assert(person.realname:find("Committer"))
+ assert(person.email:find("gall%-committer"))
+ assert(person.unixtime == "1347114766")
+ assert(person.timezone == "+0100")
+end
+
+function suite.tag_signature()
+ local repo = test_repo()
+ local tag = repo:get("refs/tags/signed-tag").content
+ local sig = tag.signature
+ assert(sig)
+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)