aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/.gitignore1
-rw-r--r--test/lua/Makefile2
-rw-r--r--test/lua/README.md2
-rw-r--r--test/lua/cursor.lua1
-rw-r--r--test/lua/file-empty.lua1
-rw-r--r--test/lua/lines.lua31
-rw-r--r--test/lua/map-basic.lua1
-rw-r--r--test/lua/pipe.lua2
-rwxr-xr-xtest/lua/test.sh9
-rw-r--r--test/lua/visrc.lua133
10 files changed, 135 insertions, 48 deletions
diff --git a/test/.gitignore b/test/.gitignore
index b62c022..4b76c8e 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -1,4 +1,3 @@
*.out
*.err
*.status
-*.busted
diff --git a/test/lua/Makefile b/test/lua/Makefile
index a7afc80..84a1eed 100644
--- a/test/lua/Makefile
+++ b/test/lua/Makefile
@@ -5,7 +5,7 @@ all: clean ../../vis test
@$(MAKE) -C ../..
clean:
- @rm -f *.out *.err *.busted
+ @rm -f *.out *.err
test:
@./test.sh
diff --git a/test/lua/README.md b/test/lua/README.md
index 5b9a1e6..a6bffb3 100644
--- a/test/lua/README.md
+++ b/test/lua/README.md
@@ -1,7 +1,7 @@
Unit Test for Vis' Lua API
--------------------------
-The tests use the [busted unit testing framework](https://olivinelabs.com/busted/).
+The test-suite is based on the [busted unit testing framework](https://olivinelabs.com/busted/).
Each `*.lua` file is sourced from a new `vis` instance which loads the
correspending `*.in` file.
diff --git a/test/lua/cursor.lua b/test/lua/cursor.lua
index 8ea3404..34d7ca0 100644
--- a/test/lua/cursor.lua
+++ b/test/lua/cursor.lua
@@ -1,4 +1,3 @@
-require 'busted.runner'()
local win = vis.win
diff --git a/test/lua/file-empty.lua b/test/lua/file-empty.lua
index 69ec17d..c94e523 100644
--- a/test/lua/file-empty.lua
+++ b/test/lua/file-empty.lua
@@ -1,4 +1,3 @@
-require 'busted.runner'()
local file = vis.win.file
diff --git a/test/lua/lines.lua b/test/lua/lines.lua
index 745e8b0..296ba77 100644
--- a/test/lua/lines.lua
+++ b/test/lua/lines.lua
@@ -1,4 +1,3 @@
-require 'busted.runner'()
local file = vis.win.file
@@ -22,33 +21,33 @@ end)
describe("get file.lines[]", function()
it("#lines", function()
- assert.are.equals(5, #file.lines)
+ assert.are.equal(5, #file.lines)
end)
it("get lines[0]", function()
-- is that what we want?
- assert.are.equals(file.lines[0], file.lines[1])
+ assert.are.equal(file.lines[0], file.lines[1])
end)
it("get lines[1]", function()
- assert.are.equals("1", file.lines[1])
+ assert.are.equal("1", file.lines[1])
end)
it("get empty \n line", function()
- assert.are.equals("", file.lines[2])
+ assert.are.equal("", file.lines[2])
end)
it("get empty \r\n line", function()
- assert.are.equals("\r", file.lines[4])
+ assert.are.equal("\r", file.lines[4])
end)
it("get lines[#lines]", function()
- assert.are.equals("5", file.lines[#file.lines])
+ assert.are.equal("5", file.lines[#file.lines])
end)
it("get lines[#lines+1]", function()
-- is that what we want?
- assert.are.equals("5", file.lines[#file.lines])
+ assert.are.equal("5", file.lines[#file.lines])
end)
end)
@@ -58,14 +57,14 @@ describe("set file.lines[]", function()
it("replace empty \n line", function()
local new = "line 2"
file.lines[2] = new
- assert.are.equals(new, file.lines[2])
+ assert.are.equal(new, file.lines[2])
end)
--[[
it("replace empty \r\n line", function()
local new = "line 4"
file.lines[4] = new
- assert.are.equals(new, file.lines[4])
+ assert.are.equal(new, file.lines[4])
end)
--]]
@@ -74,9 +73,9 @@ describe("set file.lines[]", function()
local new_first = "new first line"
local old_first = file.lines[1]
file.lines[0] = new_first
- assert.are.equals(lines+1, #file.lines)
- assert.are.equals(new_first, file.lines[1])
- assert.are.equals(old_first, file.lines[2])
+ assert.are.equal(lines+1, #file.lines)
+ assert.are.equal(new_first, file.lines[1])
+ assert.are.equal(old_first, file.lines[2])
end)
it("set lines[#lines+1], add new line at end", function()
@@ -84,9 +83,9 @@ describe("set file.lines[]", function()
local new_last = "new last line"
local old_last = file.lines[#file.lines]
file.lines[#file.lines+1] = new_last
- assert.are.equals(lines+1, #file.lines)
- assert.are.equals(new_last, file.lines[#file.lines])
- assert.are.equals(old_last, file.lines[lines])
+ assert.are.equal(lines+1, #file.lines)
+ assert.are.equal(new_last, file.lines[#file.lines])
+ assert.are.equal(old_last, file.lines[lines])
end)
end)
diff --git a/test/lua/map-basic.lua b/test/lua/map-basic.lua
index b0ce941..7e0dba1 100644
--- a/test/lua/map-basic.lua
+++ b/test/lua/map-basic.lua
@@ -1,4 +1,3 @@
-require 'busted.runner'()
vis:map(vis.modes.NORMAL, "K", function()
vis:feedkeys("iNormal Mode<Escape>")
diff --git a/test/lua/pipe.lua b/test/lua/pipe.lua
index 9dfb670..1edd073 100644
--- a/test/lua/pipe.lua
+++ b/test/lua/pipe.lua
@@ -1,5 +1,3 @@
-require 'busted.runner'()
-
local file = vis.win.file
describe("vis.pipe", function()
diff --git a/test/lua/test.sh b/test/lua/test.sh
index 4d885de..db7fb1e 100755
--- a/test/lua/test.sh
+++ b/test/lua/test.sh
@@ -9,11 +9,6 @@ if ! $VIS -v | grep '+lua' >/dev/null 2>&1; then
exit 0
fi
-type busted >/dev/null 2>&1 || {
- echo "busted(1) not found, skipping tests"
- exit 0
-}
-
TESTS_OK=0
TESTS_RUN=0
@@ -28,11 +23,11 @@ for t in $test_files; do
t=${t%.lua}
t=${t#./}
printf "%-30s" "$t"
- $VIS "$t.in" < /dev/null 2> /dev/null > "$t.busted"
+ $VIS "$t.in" < /dev/null 2> /dev/null > "$t.out"
if [ $? -ne 0 ]; then
printf "FAIL\n"
- cat "$t.busted"
+ cat "$t.out"
else
TESTS_OK=$((TESTS_OK + 1))
printf "OK\n"
diff --git a/test/lua/visrc.lua b/test/lua/visrc.lua
index 16aa8b9..a19916f 100644
--- a/test/lua/visrc.lua
+++ b/test/lua/visrc.lua
@@ -1,28 +1,127 @@
package.path = '../../lua/?.lua;'..package.path
+
dofile("../../lua/vis.lua")
--- redirect output to stdout, stderr is used by the vis UI
-io.stderr = io.stdout
+local function str(e)
+ if type(e) == "string" then
+ if e == "" then
+ return "an empty string"
+ else
+ return '"'..e..'"'
+ end
+ else
+ return tostring(e)
+ end
+end
+
+
+local function same(a, b)
+ if type(a) ~= type(b) then
+ return string.format("expected %s - got %s", type(a), type(b))
+ end
+
+ if type(a) ~= 'table' then
+ if a == b then
+ return nil
+ else
+ return string.format("expected %s - got %s", str(a), str(b))
+ end
+ end
+
+ if #a ~= #b then
+ return string.format("expected table of size %d got %d", #a, #b)
+ end
+
+ for k, v in pairs(a) do
+ if b[k] == nil then
+ return string.format("expected %s got nil", str(k))
+ end
+ r = same(v, b[k])
+ if r ~= nil then
+ return r
+ end
+ end
+ return nil
+end
--- make sure we gracefully terminate, cleanup terminal state etc.
-os.exit = function(status)
- vis:exit(status)
+
+local msg = ""
+function describe(s, fn)
+ group = {
+ before_each = function()
+ end,
+ tests = {},
+ after_each = function()
+ end,
+
+ }
+ function before_each(fn) group.before_each = fn end
+ function after_each(fn) group.after_each = fn end
+ function it(s, fn)
+ table.insert(group.tests, {
+ s = s,
+ fn = fn,
+ assertions = {},
+ })
+ end
+ fn()
+ for j, t in pairs(group.tests) do
+ group.before_each()
+ assert = {
+ has_error = function(fn)
+ local status, err = pcall(fn)
+ if err == nil then
+ msg = msg..string.format("%s %s: expected error\n", s, t.s)
+ end
+ end,
+ truthy = function(stat)
+ if not (stat) then
+ msg = msg..string.format("%s %s: expected to be truthy: %s\n", s, t.s, str(stat))
+ end
+ end,
+ falsy = function(stat)
+ if (stat) then
+ msg = msg..string.format("%s %s: expected to be falsy: %s\n", s, t.s, str(stat))
+ end
+ end,
+ are = {
+ equal = function(a, b)
+ if a ~= b then
+ msg = msg..string.format("%s %s: expected %s - got %s\n", s, t.s, str(a), str(b))
+ end
+ end,
+ same = function(a, b)
+ r = same(a, b) -- same returns a string which is a reason why a & b are not equal
+ if r ~= nil then
+ msg = msg..string.format("%s %s: %s\n", s, t.s, r)
+ end
+ end,
+ },
+ }
+ t.fn()
+ group.after_each()
+ end
end
+
vis.events.subscribe(vis.events.WIN_OPEN, function(win)
-- test.in file passed to vis
local in_file = win.file.name
- if in_file then
- -- use the corresponding test.lua file
- lua_file = string.gsub(in_file, '%.in$', '.lua')
- local ok, msg = pcall(dofile, lua_file)
- if not ok then
- if type(msg) == 'string' then
- print(msg)
- end
- vis:exit(1)
- return
- end
+ if not in_file then
+ return
+ end
+
+ -- use the corresponding test.lua file
+ lua_file = string.gsub(in_file, '%.in$', '.lua')
+
+ local ok, err = pcall(dofile, lua_file)
+ if not ok then
+ print(tostring(err))
+ vis:exit(2) -- ERROR
+ elseif msg ~= "" then
+ io.write(msg) -- no newline
+ vis:exit(1) -- FAIL
+ else
+ vis:exit(0) -- SUCCESS
end
- vis:exit(0)
end)