From 844bd1eb057dcc493a308ef0a22f2fa865e9d357 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 15 Feb 2017 00:46:27 +0100 Subject: [PATCH] Test that beautiful is not used too early (#1471) For loading a theme, beautiful.init() has to be called. We do not handle dynamic changes of the theme, so if the theme is changed after something was already queried, this change will not apply. This also means that before the theme is loaded, nothing useful can be returned. In fact, code that tries to access the theme during require() will never get a useful value from beautiful, but just nils. To catch this, one Travis build is modified so that an error is raised if the theme is accessed before beautiful.init() was called. Signed-off-by: Uli Schlachter --- .travis.yml | 8 +++++++- spec/preload.lua | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e0442ed8..0437e86b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ env: matrix: - LUA=5.2 DO_CHECKQA=1 LUANAME=lua5.2 DO_COVERAGE=coveralls # luajit: installed from source. - - LUA=5.1 LUANAME=luajit-2.0 LUALIBRARY=/usr/lib/libluajit-5.1.so LUAROCKS_ARGS=--lua-suffix=jit-2.0.4 TEST_PREV_COMMITS=1 + - LUA=5.1 LUANAME=luajit-2.0 LUALIBRARY=/usr/lib/libluajit-5.1.so LUAROCKS_ARGS=--lua-suffix=jit-2.0.4 TEST_PREV_COMMITS=1 EMPTY_THEME_WHILE_LOADING=1 # Note: luarocks does not work with Lua 5.0. - LUA=5.1 LUANAME=lua5.1 BUILD_IN_DIR=/tmp/awesome-build # Lua 5.2 with older lgi and screen size not divisible by 2. @@ -138,6 +138,12 @@ install: } script: - export CMAKE_ARGS="-DLUA_LIBRARY=${LUALIBRARY} -DLUA_INCLUDE_DIR=${LUAINCLUDE} -D OVERRIDE_VERSION=$AWESOME_VERSION -DSTRICT_TESTS=true" + - | + if [ "$EMPTY_THEME_WHILE_LOADING" = 1 ]; then + # Break beautiful so that trying to access the theme before beautiful.init() causes an error + sed -i -e 's/theme = {}/theme = setmetatable({}, { __index = function() error("May not access theme before beautiful.init()") end })/' lib/beautiful/init.lua \ + && grep -q 'May not access' lib/beautiful/init.lua + fi - | set -e if [ -n "$BUILD_IN_DIR" ]; then diff --git a/spec/preload.lua b/spec/preload.lua index 8535a2d8..9e5bd8ef 100644 --- a/spec/preload.lua +++ b/spec/preload.lua @@ -3,4 +3,7 @@ -- is not safe to reload and yet Busted manages to do this. require("lgi") +-- "fix" some intentional beautiful breakage done by .travis.yml +require("beautiful").init{} + -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80