awesome/spec/beautiful/init_spec.lua

83 lines
3.5 KiB
Lua
Raw Normal View History

---------------------------------------------------------------------------
-- @author
-- @copyright 2019
---------------------------------------------------------------------------
local beautiful = require("beautiful")
local gdebug = require("gears.debug")
describe("beautiful init", function()
local dir = (os.getenv("SOURCE_DIRECTORY") or '.') .. "/spec/beautiful/tests/"
local shim
-- Check beautiful.get_font and get_merged_font
it('Check beautiful.get_font', function()
assert.is_same(beautiful.get_font("Monospace Bold 12"),
beautiful.get_merged_font("Monospace 12", "Bold"))
end)
-- Check beautiful.get_font_height
it('Check beautiful.get_font_height', function()
-- TODO: Will requires lgi-dpi
end)
-- Check beautiful.init
it('Check beautiful.init', function()
-- Check the error messages (needs a shim)
shim = gdebug.print_error
gdebug.print_error = function(message) error(message) end
assert.has_error(function() beautiful.init({}) end,
"beautiful: error loading theme: got an empty table")
assert.has_error(function() beautiful.init(dir .. "Bad_1.lua") end,
"beautiful: error loading theme: got an empty table from: " .. dir .. "Bad_1.lua")
assert.has_error(function() beautiful.init(dir .. "Bad_2.lua") end,
"beautiful: error loading theme: got a function from: " .. dir .. "Bad_2.lua")
assert.has_error(function() beautiful.init(dir .. "Bad_3.lua") end,
"beautiful: error loading theme: got a number from: " .. dir .. "Bad_3.lua")
assert.has_error(function() beautiful.init(dir .. "Bad_4.lua") end,
"beautiful: error loading theme: got a nil from: " .. dir .. "Bad_4.lua")
assert.has_error(function() beautiful.init(dir .. "Bad_5.lua") end,
"beautiful: error loading theme: got a nil from: " .. dir .. "Bad_5.lua")
assert.has_error(function() beautiful.init(dir .. "NO_FILE") end,
"beautiful: error loading theme: got a nil from: " .. dir .. "NO_FILE")
assert.has_no_error(function() beautiful.init({ font = "Monospace Bold 12" }) end, "")
assert.has_no_error(function() beautiful.init(dir .. "Good.lua") end, "")
-- Check the return values (remove the shim)
spec/beautiful: Don't print noise (#2612) This gets rid of the following output when running the unit tests: 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got an empty table 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got an empty table from: ./spec/beautiful/tests/Bad_1.lua 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got a function from: ./spec/beautiful/tests/Bad_2.lua 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got a number from: ./spec/beautiful/tests/Bad_3.lua 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got a nil from: ./spec/beautiful/tests/Bad_4.lua 2019-01-26 18:31:44 E: awesome: Error during a protected call: ./spec/beautiful/tests/Bad_5.lua:2: attempt to index local 'var' (a nil value) stack traceback: ./spec/beautiful/tests/Bad_5.lua:2: in main chunk [C]: in function 'dofile' [C]: in function 'xpcall' lib/gears/protected_call.lua:36: in function <lib/gears/protected_call.lua:35> (...tail calls...) lib/beautiful/init.lua:224: in function 'init' spec/beautiful/init_spec.lua:56: in function <spec/beautiful/init_spec.lua:25> [C]: in function 'xpcall' /usr/share/lua/5.2/busted/core.lua:178: in function 'safe' /usr/share/lua/5.2/busted/init.lua:40: in function 'executor' ... /usr/share/lua/5.2/busted/core.lua:312: in function 'execute' /usr/share/lua/5.2/busted/block.lua:155: in function 'execute' /usr/share/lua/5.2/busted/init.lua:7: in function 'executor' /usr/share/lua/5.2/busted/core.lua:312: in function </usr/share/lua/5.2/busted/core.lua:312> [C]: in function 'xpcall' /usr/share/lua/5.2/busted/core.lua:178: in function 'safe' /usr/share/lua/5.2/busted/core.lua:312: in function 'execute' /usr/share/lua/5.2/busted/execute.lua:58: in function 'execute' /usr/share/lua/5.2/busted/runner.lua:174: in function </usr/share/lua/5.2/busted/runner.lua:11> /usr/bin/busted:3: in main chunk [C]: in ? 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got a nil from: ./spec/beautiful/tests/Bad_5.lua 2019-01-26 18:31:44 E: awesome: Error during a protected call: cannot open ./spec/beautiful/tests/NO_FILE: No such file or directory stack traceback: [C]: in function 'dofile' [C]: in function 'xpcall' lib/gears/protected_call.lua:36: in function <lib/gears/protected_call.lua:35> (...tail calls...) lib/beautiful/init.lua:224: in function 'init' spec/beautiful/init_spec.lua:57: in function <spec/beautiful/init_spec.lua:25> [C]: in function 'xpcall' /usr/share/lua/5.2/busted/core.lua:178: in function 'safe' /usr/share/lua/5.2/busted/init.lua:40: in function 'executor' /usr/share/lua/5.2/busted/core.lua:312: in function </usr/share/lua/5.2/busted/core.lua:312> ... /usr/share/lua/5.2/busted/core.lua:312: in function 'execute' /usr/share/lua/5.2/busted/block.lua:155: in function 'execute' /usr/share/lua/5.2/busted/init.lua:7: in function 'executor' /usr/share/lua/5.2/busted/core.lua:312: in function </usr/share/lua/5.2/busted/core.lua:312> [C]: in function 'xpcall' /usr/share/lua/5.2/busted/core.lua:178: in function 'safe' /usr/share/lua/5.2/busted/core.lua:312: in function 'execute' /usr/share/lua/5.2/busted/execute.lua:58: in function 'execute' /usr/share/lua/5.2/busted/runner.lua:174: in function </usr/share/lua/5.2/busted/runner.lua:11> /usr/bin/busted:3: in main chunk [C]: in ? 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got a nil from: ./spec/beautiful/tests/NO_FILE Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-01-26 18:54:31 +01:00
gdebug.print_error = function() end
assert.is_nil(beautiful.init({}))
assert.is_nil(beautiful.init(dir .. "Bad_1.lua"))
assert.is_nil(beautiful.init(dir .. "Bad_2.lua"))
assert.is_nil(beautiful.init(dir .. "Bad_3.lua"))
assert.is_nil(beautiful.init(dir .. "Bad_4.lua"))
assert.is_nil(beautiful.init(dir .. "Bad_5.lua"))
assert.is_nil(beautiful.init(dir .. "NO_FILE"))
spec/beautiful: Don't print noise (#2612) This gets rid of the following output when running the unit tests: 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got an empty table 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got an empty table from: ./spec/beautiful/tests/Bad_1.lua 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got a function from: ./spec/beautiful/tests/Bad_2.lua 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got a number from: ./spec/beautiful/tests/Bad_3.lua 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got a nil from: ./spec/beautiful/tests/Bad_4.lua 2019-01-26 18:31:44 E: awesome: Error during a protected call: ./spec/beautiful/tests/Bad_5.lua:2: attempt to index local 'var' (a nil value) stack traceback: ./spec/beautiful/tests/Bad_5.lua:2: in main chunk [C]: in function 'dofile' [C]: in function 'xpcall' lib/gears/protected_call.lua:36: in function <lib/gears/protected_call.lua:35> (...tail calls...) lib/beautiful/init.lua:224: in function 'init' spec/beautiful/init_spec.lua:56: in function <spec/beautiful/init_spec.lua:25> [C]: in function 'xpcall' /usr/share/lua/5.2/busted/core.lua:178: in function 'safe' /usr/share/lua/5.2/busted/init.lua:40: in function 'executor' ... /usr/share/lua/5.2/busted/core.lua:312: in function 'execute' /usr/share/lua/5.2/busted/block.lua:155: in function 'execute' /usr/share/lua/5.2/busted/init.lua:7: in function 'executor' /usr/share/lua/5.2/busted/core.lua:312: in function </usr/share/lua/5.2/busted/core.lua:312> [C]: in function 'xpcall' /usr/share/lua/5.2/busted/core.lua:178: in function 'safe' /usr/share/lua/5.2/busted/core.lua:312: in function 'execute' /usr/share/lua/5.2/busted/execute.lua:58: in function 'execute' /usr/share/lua/5.2/busted/runner.lua:174: in function </usr/share/lua/5.2/busted/runner.lua:11> /usr/bin/busted:3: in main chunk [C]: in ? 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got a nil from: ./spec/beautiful/tests/Bad_5.lua 2019-01-26 18:31:44 E: awesome: Error during a protected call: cannot open ./spec/beautiful/tests/NO_FILE: No such file or directory stack traceback: [C]: in function 'dofile' [C]: in function 'xpcall' lib/gears/protected_call.lua:36: in function <lib/gears/protected_call.lua:35> (...tail calls...) lib/beautiful/init.lua:224: in function 'init' spec/beautiful/init_spec.lua:57: in function <spec/beautiful/init_spec.lua:25> [C]: in function 'xpcall' /usr/share/lua/5.2/busted/core.lua:178: in function 'safe' /usr/share/lua/5.2/busted/init.lua:40: in function 'executor' /usr/share/lua/5.2/busted/core.lua:312: in function </usr/share/lua/5.2/busted/core.lua:312> ... /usr/share/lua/5.2/busted/core.lua:312: in function 'execute' /usr/share/lua/5.2/busted/block.lua:155: in function 'execute' /usr/share/lua/5.2/busted/init.lua:7: in function 'executor' /usr/share/lua/5.2/busted/core.lua:312: in function </usr/share/lua/5.2/busted/core.lua:312> [C]: in function 'xpcall' /usr/share/lua/5.2/busted/core.lua:178: in function 'safe' /usr/share/lua/5.2/busted/core.lua:312: in function 'execute' /usr/share/lua/5.2/busted/execute.lua:58: in function 'execute' /usr/share/lua/5.2/busted/runner.lua:174: in function </usr/share/lua/5.2/busted/runner.lua:11> /usr/bin/busted:3: in main chunk [C]: in ? 2019-01-26 18:31:44 E: awesome: beautiful: error loading theme: got a nil from: ./spec/beautiful/tests/NO_FILE Signed-off-by: Uli Schlachter <psychon@znc.in>
2019-01-26 18:54:31 +01:00
gdebug.print_error = shim
assert.is_true(beautiful.init({ font = "Monospace Bold 12" }))
assert.is_true(beautiful.init(dir .. "Good.lua"))
end)
-- Check beautiful.get
it('Check beautiful.get', function()
assert.is_same(beautiful.get(), { font = "Monospace Bold 12" })
end)
-- Check getting a beautiful.value
it('Check getting a beautiful.value', function()
assert.is_same(beautiful.font, "Monospace Bold 12")
end)
-- Check setting a beautiful.value
it('Check setting a beautiful.value', function()
beautiful.font = "Monospace Bold 10"
assert.is_same(beautiful.font, "Monospace Bold 10")
end)
end)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80