summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2012-09-08 16:18:07 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2012-09-08 16:18:07 +0100
commit3d14a3b8dfae2410778031ea55cce58a706fae33 (patch)
tree935f12b1cba16b15c45a0712334b3e2aee4f2ad4
parentea949ae3bb60172aa6cf84680dff308df13686e7 (diff)
downloadgall-3d14a3b8dfae2410778031ea55cce58a706fae33.tar.gz
GALL.COMMIT: Test gall.commit (except creation of commits)
-rw-r--r--Makefile2
-rw-r--r--lib/gall/commit.lua27
-rw-r--r--test/create_test_repo.sh2
-rw-r--r--test/signed.tarbin0 -> 20480 bytes
-rw-r--r--test/test-gall.commit.lua108
5 files changed, 126 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 32d4af7..7d5e0d8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
all: test
-MODULES := gall gall.util gall.ll gall.repository
+MODULES := gall gall.util gall.ll gall.repository gall.object gall.commit
LUA_VER := 5.1
INST_BASE := /usr/local
diff --git a/lib/gall/commit.lua b/lib/gall/commit.lua
index 92afff8..080c7ed 100644
--- a/lib/gall/commit.lua
+++ b/lib/gall/commit.lua
@@ -42,23 +42,26 @@ local function commitindex(commit, field)
if state == "headers" then
local first, second = l:match("^([^ ]+) (.+)$")
if first then
- if headers[first] then
- headers[first][#headers[first]+1] = second
+ if first == "gpgsig" then
+ signature = second .. "\n"
+ state = "signature"
else
- headers[first] = { second }
+ if headers[first] then
+ headers[first][#headers[first]+1] = second
+ else
+ headers[first] = { second }
+ end
end
else
state = "message"
end
- elseif state == "message" then
- if l == PGP_SIG_START then
- signature = l .. "\n"
- state = "signature"
- else
- body = body .. l .. "\n"
+ elseif state == "signature" then
+ signature = signature .. l:sub(2) .. "\n"
+ if l:find("END PGP SIG") then
+ state = "headers"
end
else
- signature = signature .. l .. "\n"
+ body = body .. l .. "\n"
end
end
@@ -94,14 +97,14 @@ local commitmeta = {
__tostring = committostring
}
-function _new(repo, obj)
+local function _new(repo, obj)
local ret = setmetatable({}, commitmeta)
objs[ret] = obj
repos[ret] = repo
return ret
end
-function _create(repo, data)
+local function _create(repo, data)
if not data.tree then
return nil, "No tree?"
end
diff --git a/test/create_test_repo.sh b/test/create_test_repo.sh
index 4d4793e..f56d9cb 100644
--- a/test/create_test_repo.sh
+++ b/test/create_test_repo.sh
@@ -43,3 +43,5 @@ _git checkout master
_git merge branchy
_git tag -a -m "Annotated Tag. Wahey" v1.0
+
+(cd .git; tar xf ../../signed.tar)
diff --git a/test/signed.tar b/test/signed.tar
new file mode 100644
index 0000000..9da308e
--- /dev/null
+++ b/test/signed.tar
Binary files differ
diff --git a/test/test-gall.commit.lua b/test/test-gall.commit.lua
new file mode 100644
index 0000000..dfb5454
--- /dev/null
+++ b/test/test-gall.commit.lua
@@ -0,0 +1,108 @@
+-- test/test-gall.commit.lua
+--
+-- Git Abstraction layer for Lua - Commit 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.commit_get()
+ local repo = test_repo()
+ local commit = repo:get("refs/heads/master").content
+ assert(commit)
+end
+
+function suite.commit_tostring()
+ local repo = test_repo()
+ local commit = repo:get("refs/heads/master").content
+ local commitstr = tostring(commit)
+ assert(commitstr:find("GitCommit"))
+end
+
+function suite.commit_message()
+ local repo = test_repo()
+ local commit = repo:get("refs/heads/master").content
+ local commitmsg = commit.message
+ assert(commitmsg:find("Merge branch"))
+end
+
+function suite.commit_parents()
+ local repo = test_repo()
+ local commit = repo:get("refs/heads/master").content
+ local parents = commit.parents
+ assert(parents[1])
+ assert(parents[2])
+ assert(parents[1].type == "commit")
+ assert(parents[2].type == "commit")
+ assert(not parents[3])
+end
+
+function suite.commit_committer()
+ local repo = test_repo()
+ local commit = repo:get("refs/heads/master").content
+ local person = commit.committer
+ assert(person.realname:find("Committer"))
+ assert(person.email:find("gall%-committer"))
+ assert(person.unixtime == "1347114766")
+ assert(person.timezone == "+0100")
+end
+
+function suite.commit_author()
+ local repo = test_repo()
+ local commit = repo:get("refs/heads/master").content
+ local person = commit.author
+ assert(person.realname:find("Author"))
+ assert(person.email:find("gall%-author"))
+ assert(person.unixtime == "1347114766")
+ assert(person.timezone == "+0000")
+end
+
+function suite.commit_signature()
+ local repo = test_repo()
+ local commit = repo:get("refs/heads/signed").content
+ local sig = commit.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)