mirror of https://github.com/lcpz/lain.git
Added first set of tests and fixed the requires again
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
24e4c34421
commit
8792d0de68
|
@ -34,3 +34,11 @@ jobs:
|
|||
else
|
||||
echo "Rockspec unchanged, nothing to do"
|
||||
fi
|
||||
|
||||
unit_tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Run Busted
|
||||
uses: lunarmodules/busted@v0
|
||||
|
|
11
init.lua
11
init.lua
|
@ -8,8 +8,13 @@
|
|||
|
||||
--]]
|
||||
|
||||
local requirePrefix= tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix=requirePrefix.."."
|
||||
end
|
||||
|
||||
return {
|
||||
layout = require(tostring(...):match(".*lain") .. ".layout"),
|
||||
util = require(tostring(...):match(".*lain") .. ".util"),
|
||||
widget = require(tostring(...):match(".*lain") .. ".widget")
|
||||
layout = require(requirePrefix .. "layout"),
|
||||
util = require(requirePrefix .. "util"),
|
||||
widget = require(requirePrefix .. "widget")
|
||||
}
|
||||
|
|
|
@ -11,9 +11,14 @@
|
|||
|
||||
--]]
|
||||
|
||||
local wrequire = require(tostring(...):match(".*lain") .. ".helpers").wrequire
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local wrequire = require(requirePrefix .. "helpers").wrequire
|
||||
local setmetatable = setmetatable
|
||||
|
||||
local layout = { _NAME = tostring(...):match(".*lain") .. ".layout" }
|
||||
local layout = { _NAME = requirePrefix .. "layout" }
|
||||
|
||||
return setmetatable(layout, { __index = wrequire })
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
line1
|
||||
line2
|
||||
line3
|
||||
line4
|
|
@ -0,0 +1,138 @@
|
|||
describe("Test helpers functions", function()
|
||||
package.loaded["awful"] = {}
|
||||
package.loaded["awful.spawn"] = {
|
||||
easy_async=function (cmd,f)
|
||||
f(cmd,0,0,1)
|
||||
end,
|
||||
easy_async_with_shell=function (cmd,f)
|
||||
f(cmd,0,0,1)
|
||||
end,
|
||||
with_line_callback=function (cmd,f)
|
||||
f.stdout(cmd)
|
||||
end
|
||||
|
||||
}
|
||||
local timer ={
|
||||
start= function () end,
|
||||
connect_signal= function (t,f) end,
|
||||
emit_signal= function (t) end,
|
||||
}
|
||||
local timerMock=mock(timer,true)
|
||||
package.loaded["gears.timer"] =function() return timerMock end
|
||||
|
||||
|
||||
it("file_exists", function()
|
||||
local helpers = require("helpers")
|
||||
assert.is_true(helpers.file_exists("init.lua"))
|
||||
assert.is_false(helpers.file_exists("init2.lua"))
|
||||
end)
|
||||
it("lines_from", function()
|
||||
local result = {
|
||||
"line1",
|
||||
"line2",
|
||||
"line3",
|
||||
"line4",
|
||||
}
|
||||
local helpers = require("helpers")
|
||||
assert.are.same(helpers.lines_from("spec/data/lines_from.txt"),result)
|
||||
end)
|
||||
it("lines_match", function()
|
||||
local result = {
|
||||
"line1",
|
||||
"line3",
|
||||
}
|
||||
local helpers = require("helpers")
|
||||
assert.are.same(helpers.lines_match("line[1,3]","spec/data/lines_from.txt"),result)
|
||||
end)
|
||||
it("first_line", function()
|
||||
local helpers = require("helpers")
|
||||
assert.are.same(helpers.first_line("spec/data/lines_from.txt"),"line1")
|
||||
assert.are.equals(helpers.first_line("spec/data/no_file.txt"),nil)
|
||||
end)
|
||||
it("first_nonempty_line", function()
|
||||
local helpers = require("helpers")
|
||||
assert.are.same(helpers.first_nonempty_line("spec/data/lines_from.txt"),"line1")
|
||||
end)
|
||||
|
||||
|
||||
it("newtimer", function()
|
||||
local helpers = require("helpers")
|
||||
|
||||
assert.is_false(helpers.newtimer("name",10,"fun",false,false))
|
||||
assert.stub(timer.start).was.called_with(timerMock)
|
||||
assert.stub(timer.connect_signal).was.called_with(timerMock,"timeout", "fun")
|
||||
assert.stub(timer.emit_signal).was.called_with(timerMock,"timeout")
|
||||
assert.are.equals(helpers.newtimer("name",10,"fun",true,true),timerMock)
|
||||
end)
|
||||
|
||||
it("async", function()
|
||||
local helpers = require("helpers")
|
||||
helpers.async("date",function (out,code)
|
||||
assert.is.truthy(#out)
|
||||
assert.is.truthy(code)
|
||||
end)
|
||||
end)
|
||||
it("async_with_shell", function()
|
||||
local helpers = require("helpers")
|
||||
helpers.async_with_shell("date",function (out,code)
|
||||
assert.is.truthy(#out)
|
||||
assert.is.truthy(code)
|
||||
end)
|
||||
end)
|
||||
it("line_callback", function()
|
||||
local helpers = require("helpers")
|
||||
helpers.line_callback("date",function (out)
|
||||
assert.is.truthy(#out)
|
||||
end)
|
||||
end)
|
||||
|
||||
it("map_table", function()
|
||||
local helpers = require("helpers")
|
||||
helpers.set_map("key","value")
|
||||
assert.are.equals(helpers.get_map("key"),"value")
|
||||
end)
|
||||
|
||||
it("element_in_table", function()
|
||||
local helpers = require("helpers")
|
||||
local table={
|
||||
a=1,
|
||||
b=2,
|
||||
c=3,
|
||||
}
|
||||
assert.is_true(helpers.element_in_table(1,table))
|
||||
assert.is_false(helpers.element_in_table(5,table))
|
||||
end)
|
||||
|
||||
it("spairs", function()
|
||||
local helpers = require("helpers")
|
||||
local table={
|
||||
a=1,
|
||||
c=3,
|
||||
b=2,
|
||||
}
|
||||
local f=helpers.spairs(table)
|
||||
key,value=f()
|
||||
assert.are.equals(key,"a")
|
||||
assert.are.equals(value,1)
|
||||
key,value=f()
|
||||
assert.are.equals(key,"b")
|
||||
assert.are.equals(value,2)
|
||||
key,value=f()
|
||||
assert.are.equals(key,"c")
|
||||
assert.are.equals(value,3)
|
||||
end)
|
||||
|
||||
it("trivial_partition_set", function()
|
||||
local helpers = require("helpers")
|
||||
local table={"a","b","c"}
|
||||
local result={{"a"}, {"b"}, {"c"}}
|
||||
assert.are.same(helpers.trivial_partition_set(table),result)
|
||||
end)
|
||||
|
||||
it("powerset", function()
|
||||
local helpers = require("helpers")
|
||||
local table={"a","b","c"}
|
||||
local result={{},{"a"}, {"b"},{"b","a"}, {"c"},{"c","a"},{"c","b"},{"c","b","a"}}
|
||||
assert.are.same(helpers.powerset(table),result)
|
||||
end)
|
||||
end)
|
|
@ -0,0 +1,17 @@
|
|||
describe("Test the requires", function()
|
||||
package.loaded["awful"] = {}
|
||||
package.loaded["awful.spawn"] = {}
|
||||
package.loaded["gears.timer"] = {}
|
||||
it("init", function()
|
||||
require("init")
|
||||
end)
|
||||
it("layout", function()
|
||||
require("layout")
|
||||
end)
|
||||
it("util", function()
|
||||
require("util")
|
||||
end)
|
||||
it("widget", function()
|
||||
require("widget")
|
||||
end)
|
||||
end)
|
|
@ -11,17 +11,22 @@
|
|||
|
||||
--]]
|
||||
|
||||
local requirePrefix= tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix=requirePrefix.."."
|
||||
end
|
||||
|
||||
local awful = require("awful")
|
||||
local sqrt = math.sqrt
|
||||
local pairs = pairs
|
||||
local client = client
|
||||
local tonumber = tonumber
|
||||
local wrequire = require(tostring(...):match(".*lain") .. ".helpers").wrequire
|
||||
local wrequire = require(requirePrefix .. "helpers").wrequire
|
||||
local setmetatable = setmetatable
|
||||
|
||||
-- Lain utilities submodule
|
||||
-- lain.util
|
||||
local util = { _NAME = tostring(...):match(".*lain") .. ".util" }
|
||||
local util = { _NAME = requirePrefix .. "util" }
|
||||
|
||||
-- Like awful.menu.clients, but only show clients of currently selected tags
|
||||
function util.menu_clients_current_tags(menu, args)
|
||||
|
|
|
@ -10,8 +10,13 @@
|
|||
-- Menu iterator with Naughty notifications
|
||||
-- lain.util.menu_iterator
|
||||
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local naughty = require("naughty")
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local atable = require("awful.util").table
|
||||
local assert = assert
|
||||
local pairs = pairs
|
||||
|
|
|
@ -6,7 +6,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local shell = require("awful.util").shell
|
||||
local wibox = require("wibox")
|
||||
local string = string
|
||||
|
|
|
@ -6,7 +6,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local awful = require("awful")
|
||||
local naughty = require("naughty")
|
||||
local wibox = require("wibox")
|
||||
|
|
|
@ -6,7 +6,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local fs = require("gears.filesystem")
|
||||
local naughty = require("naughty")
|
||||
local wibox = require("wibox")
|
||||
|
|
|
@ -5,8 +5,13 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local markup = require(tostring(...):match(".*lain") .. ".util.markup")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local markup = require(requirePrefix .. "util.markup")
|
||||
local awful = require("awful")
|
||||
local naughty = require("naughty")
|
||||
local floor = math.floor
|
||||
|
|
|
@ -10,9 +10,14 @@
|
|||
|
||||
--]]
|
||||
|
||||
local wrequire = require(tostring(...):match(".*lain") .. ".helpers").wrequire
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local wrequire = require(requirePrefix .. "helpers").wrequire
|
||||
local setmetatable = setmetatable
|
||||
|
||||
local widget = { _NAME = tostring(...):match(".*lain") .. ".widget.contrib" }
|
||||
local widget = { _NAME = requirePrefix .. "widget.contrib" }
|
||||
|
||||
return setmetatable(widget, { __index = wrequire })
|
||||
|
|
|
@ -5,7 +5,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local shell = require("awful.util").shell
|
||||
local focused = require("awful.screen").focused
|
||||
local escape_f = require("awful.util").escape
|
||||
|
|
|
@ -6,7 +6,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local async = require(tostring(...):match(".*lain") .. ".helpers").async
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local async = require(requirePrefix .. ".helpers").async
|
||||
local awful = require("awful")
|
||||
local execute = os.execute
|
||||
local type = type
|
||||
|
|
|
@ -5,8 +5,13 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local markup = require(tostring(...):match(".*lain") .. ".util").markup
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local markup = require(requirePrefix .. "util").markup
|
||||
local awful = require("awful")
|
||||
local naughty = require("naughty")
|
||||
local mouse = mouse
|
||||
|
|
|
@ -6,7 +6,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local focused = require("awful.screen").focused
|
||||
local naughty = require("naughty")
|
||||
local wibox = require("wibox")
|
||||
|
|
|
@ -6,7 +6,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local wibox = require("wibox")
|
||||
local math = math
|
||||
local string = string
|
||||
|
|
|
@ -7,7 +7,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local Gio = require("lgi").Gio
|
||||
local focused = require("awful.screen").focused
|
||||
local wibox = require("wibox")
|
||||
|
|
|
@ -5,7 +5,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local naughty = require("naughty")
|
||||
local wibox = require("wibox")
|
||||
local awful = require("awful")
|
||||
|
|
|
@ -11,9 +11,14 @@
|
|||
|
||||
--]]
|
||||
|
||||
local wrequire = require(tostring(...):match(".*lain") .. ".helpers").wrequire
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local wrequire = require(requirePrefix .. "helpers").wrequire
|
||||
local setmetatable = setmetatable
|
||||
|
||||
local widget = { _NAME = tostring(...):match(".*lain") .. ".widget" }
|
||||
local widget = { _NAME = requirePrefix .. "widget" }
|
||||
|
||||
return setmetatable(widget, { __index = wrequire })
|
||||
|
|
|
@ -6,7 +6,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local wibox = require("wibox")
|
||||
local gmatch, lines, floor = string.gmatch, io.lines, math.floor
|
||||
|
||||
|
|
|
@ -6,7 +6,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local shell = require("awful.util").shell
|
||||
local escape_f = require("awful.util").escape
|
||||
local focused = require("awful.screen").focused
|
||||
|
|
|
@ -6,7 +6,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local naughty = require("naughty")
|
||||
local wibox = require("wibox")
|
||||
local string = string
|
||||
|
|
|
@ -5,7 +5,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local shell = require("awful.util").shell
|
||||
local wibox = require("wibox")
|
||||
local string = string
|
||||
|
|
|
@ -6,7 +6,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local awful = require("awful")
|
||||
local naughty = require("naughty")
|
||||
local wibox = require("wibox")
|
||||
|
|
|
@ -6,7 +6,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local wibox = require("wibox")
|
||||
local open, match = io.open, string.match
|
||||
|
||||
|
|
|
@ -5,7 +5,12 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local wibox = require("wibox")
|
||||
local tonumber = tonumber
|
||||
|
||||
|
|
|
@ -5,8 +5,13 @@
|
|||
|
||||
--]]
|
||||
|
||||
local helpers = require(tostring(...):match(".*lain") .. ".helpers")
|
||||
local json = require(tostring(...):match(".*lain") .. ".util").dkjson
|
||||
local requirePrefix = tostring(...):match(".*lain") or ""
|
||||
if requirePrefix then
|
||||
requirePrefix = requirePrefix .. "."
|
||||
end
|
||||
|
||||
local helpers = require(requirePrefix .. "helpers")
|
||||
local json = require(requirePrefix .. "util").dkjson
|
||||
local focused = require("awful.screen").focused
|
||||
local naughty = require("naughty")
|
||||
local wibox = require("wibox")
|
||||
|
|
Loading…
Reference in New Issue