Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Busted test framework and start porting tests #358

Merged
merged 10 commits into from
Oct 9, 2020
6 changes: 6 additions & 0 deletions .busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
return {
default = {
lpath = "./lua/?.lua;./lua/?/init.lua",
}
}
-- vim: ft=lua
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ not_globals = {
include_files = {
"**/*.lua",
"*.rockspec",
".busted",
".luacheckrc",
}

Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ before_install:
- hererocks here -r^ --$LUA
- source here/bin/activate
- luarocks install luacov-coveralls
- luarocks install busted

install:
- luarocks make

script:
- busted -c -v
- lua run.lua tests --luacov
- lua run.lua examples

Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ before_build:
- call here\bin\activate
- "if \"%LUA%\"==\"lua 5.4\" ( luarocks install bit32 )"
- luarocks install luacov-coveralls
- luarocks install busted

build_script:
- luarocks make

test_script:
- busted -c -v
- lua run.lua tests --luacov
- lua run.lua examples

Expand Down
8 changes: 8 additions & 0 deletions penlight-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ dependencies = {
"luafilesystem"
}

test_dependencies = {
"busted",
}

test = {
type = "busted",
}

build = {
type = "builtin",
modules = {
Expand Down
15 changes: 15 additions & 0 deletions spec/app_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local app = require("pl.app")

describe("pl.app.lua", function ()

local invocation = app.lua()

it("should pick up the arguments used to run this test", function ()
assert.is.truthy(invocation:match("lua.+package.+busted"))
Tieske marked this conversation as resolved.
Show resolved Hide resolved
end)

it("should be reusable to invoke Lua", function ()
assert.is.truthy(os.execute(app.lua()..' -e "n=1;os.exit(n-1)"'))
end)

end)
11 changes: 11 additions & 0 deletions spec/date_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local Date = require("pl.Date")

describe("pl.Date:__tostring()", function ()

it("should be suitable for serialization", function ()
local df = Date.Format()
local du = df:parse("2008-07-05")
assert.is.equal(du, du:toUTC())
end)

end)
11 changes: 11 additions & 0 deletions spec/text_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local text = require("pl.text")

describe("pl.text.Template", function ()

it("replaces placeholders", function ()
local tempalte = text.Template("${here} is the $answer")
local out = tempalte:substitute({ here = 'one', answer = 'two' })
assert.is.equal('one is the two', out)
end)

end)
5 changes: 0 additions & 5 deletions tests/test-date.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local test = require 'pl.test'
local app = require 'pl.app'
local utils = require 'pl.utils'
local asserteq, assertmatch = test.asserteq, test.assertmatch
local dump = require 'pl.pretty'.dump
local T = require 'pl.test'.tuple
Expand Down Expand Up @@ -121,8 +120,4 @@ local now,utc = Date(), Date 'utc'
asserteq(tostring(now - utc),'zero')

if app.platform() ~= 'Windows' then
print(app.lua())
if not utils.execute ("TZ='Europe/London' "..app.lua().." tests/test-date2.lua") then
error "buggered!"
end
end
10 changes: 0 additions & 10 deletions tests/test-date2.lua

This file was deleted.

8 changes: 0 additions & 8 deletions tests/test-text2.lua

This file was deleted.