summaryrefslogtreecommitdiff
path: root/test/test-gall.commit.lua
blob: dfb54540e36165243c8f711253c7352b103094fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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)