diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-09-08 14:25:36 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2012-09-08 14:25:36 +0100 |
commit | b143d1ec3813f25128e34d06aa552b9d6703569b (patch) | |
tree | c82719337b4fa7552b4cccf08c32d94ce3eafbb8 | |
parent | 3c5a5bc87cccf5d4a99f155e449bbb7a98c4262f (diff) | |
download | gall-b143d1ec3813f25128e34d06aa552b9d6703569b.tar.gz |
GALL.LL: Initial testing for gall.ll
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | lib/gall/ll.lua | 9 | ||||
-rw-r--r-- | test/test-gall.ll.lua | 89 |
3 files changed, 96 insertions, 4 deletions
@@ -1,6 +1,6 @@ all: test -MODULES := gall gall.util +MODULES := gall gall.util gall.ll LUA_VER := 5.1 INST_BASE := /usr/local diff --git a/lib/gall/ll.lua b/lib/gall/ll.lua index 7f20683..24f76bb 100644 --- a/lib/gall/ll.lua +++ b/lib/gall/ll.lua @@ -65,8 +65,11 @@ local function _rungit(t) return why, stdout, stderr end -local function _setgit(e) - git_exe = e +local function get_set_git(e) + if e then + git_exe = e + end + return git_exe end local function _chomp(s) @@ -76,7 +79,7 @@ end local mod_ret = { rungit = _rungit, - setgit = _setgit, + get_set_git = get_set_git, chomp = _chomp } diff --git a/test/test-gall.ll.lua b/test/test-gall.ll.lua new file mode 100644 index 0000000..90e3f8b --- /dev/null +++ b/test/test-gall.ll.lua @@ -0,0 +1,89 @@ +-- test/test-gall.util.lua +-- +-- Git Abstraction layer for Lua - Utility function tests +-- +-- Copyright 2012 Daniel Silverstone <dsilvers@digital-scurf.org> +-- +-- For Licence terms, see COPYING +-- + +-- 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.test_ll_chomp() + local instr = "foo\n" + local outstr = gall.ll.chomp(instr) + assert(outstr == "foo") +end + +function suite.test_get_set_git() + local now_git = gall.ll.get_set_git() + assert(now_git == gall.ll.get_set_git()) + assert(now_git == "git") + assert("foobar" == gall.ll.get_set_git("foobar")) + assert(gall.ll.get_set_git() == "foobar") + assert(now_git == gall.ll.get_set_git(now_git)) + assert(now_git == gall.ll.get_set_git()) + assert(now_git == "git") +end + +function suite.test_rungit() + local args = { + repo = ".", + env = { GIT_EDITOR = "foobarbaz" }, + stdout = gall.ll.chomp, + "var", "GIT_EDITOR" + } + local why, stdout, stderr = gall.ll.rungit(args) + assert(why == 0) + assert(stdout == "foobarbaz") + assert(stderr == nil or stderr == "") +end + +function suite.test_hash_object() + local args = { + repo = ".", + stdin = "FOOBAR", + "-t", "blob", "--stdin", + } + local why, stdout, stderr = gall.ll.hash_object(args) + assert(why == 0) + assert(stdout == "389865bb681b358c9b102d79abd8d5f941e96551") + assert(stderr == nil or stderr == "") +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) |