From a8834bfcc16c4c99e01ccdd7e7e4230ec90b04ef Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 9 Jul 2016 19:03:49 +0200 Subject: [PATCH] tests/examples: Move common template code into a common file (#993) Signed-off-by: Uli Schlachter --- tests/examples/awful/template.lua | 24 ++---------------- tests/examples/gears/shape/template.lua | 12 +++------ tests/examples/shims/_common_template.lua | 25 +++++++++++++++++++ tests/examples/text/template.lua | 21 ++-------------- .../wibox/container/defaults/template.lua | 22 ++-------------- tests/examples/wibox/layout/template.lua | 22 ++-------------- tests/examples/wibox/template.lua | 22 ++-------------- 7 files changed, 38 insertions(+), 110 deletions(-) create mode 100644 tests/examples/shims/_common_template.lua diff --git a/tests/examples/awful/template.lua b/tests/examples/awful/template.lua index b31088f3..5f810e2c 100644 --- a/tests/examples/awful/template.lua +++ b/tests/examples/awful/template.lua @@ -1,30 +1,10 @@ -local file_path, image_path, luacovpath = ... +local file_path, image_path = ... +require("_common_template")(...) local cairo = require("lgi").cairo local pango = require("lgi").Pango local pangocairo = require("lgi").PangoCairo --- Set the global shims --- luacheck: globals awesome root tag screen client mouse drawin -awesome = require( "awesome" ) -root = require( "root" ) -tag = require( "tag" ) -screen = require( "screen" ) -client = require( "client" ) -mouse = require( "mouse" ) -drawin = require( "drawin" ) - --- Force luacheck to be silent about setting those as unused globals -assert(awesome and root and tag and screen and client and mouse) - --- If luacov is available, use it. Else, do nothing. -pcall(function() - require("luacov.runner")(luacovpath) -end) - --- Silence debug warnings -require("gears.debug").print_warning = function() end - local color = require( "gears.color" ) local shape = require( "gears.shape" ) local beautiful = require( "beautiful" ) diff --git a/tests/examples/gears/shape/template.lua b/tests/examples/gears/shape/template.lua index e3b0ca25..22abe211 100644 --- a/tests/examples/gears/shape/template.lua +++ b/tests/examples/gears/shape/template.lua @@ -1,17 +1,11 @@ +local filepath, svgpath = ... +require("_common_template")(...) + -- Test if shape crash when called -- Also generate some SVG to be used by the documentation -- it also "prove" that the code examples are all working local cairo = require( "lgi" ).cairo local shape = require( "gears.shape" ) -local filepath, svgpath, luacovpath = ... - --- If luacov is available, use it. Else, do nothing. -pcall(function() - require("luacov.runner")(luacovpath) -end) - --- Silence debug warnings -require("gears.debug").print_warning = function() end local function get_surface(p) local img = cairo.SvgSurface.create(p, 288, 76) diff --git a/tests/examples/shims/_common_template.lua b/tests/examples/shims/_common_template.lua new file mode 100644 index 00000000..021b09fc --- /dev/null +++ b/tests/examples/shims/_common_template.lua @@ -0,0 +1,25 @@ +return function(_, _, luacovpath) + + -- Set the global shims + -- luacheck: globals awesome root tag screen client mouse drawin + awesome = require( "awesome" ) + root = require( "root" ) + tag = require( "tag" ) + screen = require( "screen" ) + client = require( "client" ) + mouse = require( "mouse" ) + drawin = require( "drawin" ) + + -- Force luacheck to be silent about setting those as unused globals + assert(awesome and root and tag and screen and client and mouse) + + -- If luacov is available, use it. Else, do nothing. + pcall(function() + require("luacov.runner")(luacovpath) + end) + + -- Silence debug warnings + require("gears.debug").print_warning = function() end +end + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/tests/examples/text/template.lua b/tests/examples/text/template.lua index a185adf3..948f3a14 100644 --- a/tests/examples/text/template.lua +++ b/tests/examples/text/template.lua @@ -1,22 +1,5 @@ -local file_path, _, luacovpath = ... - --- Set the global shims --- luacheck: globals awesome root tag screen client mouse drawin -awesome = require( "awesome" ) -root = require( "root" ) -tag = require( "tag" ) -screen = require( "screen" ) -client = require( "client" ) -mouse = require( "mouse" ) -drawin = require( "drawin" ) - --- If luacov is available, use it. Else, do nothing. -pcall(function() - require("luacov.runner")(luacovpath) -end) - --- Silence debug warnings -require("gears.debug").print_warning = function() end +local file_path = ... +require("_common_template")(...) -- Execute the test loadfile(file_path)() diff --git a/tests/examples/wibox/container/defaults/template.lua b/tests/examples/wibox/container/defaults/template.lua index 772389ce..56d2ef8e 100644 --- a/tests/examples/wibox/container/defaults/template.lua +++ b/tests/examples/wibox/container/defaults/template.lua @@ -1,29 +1,11 @@ -local file_path, image_path, luacovpath = ... - --- Set the global shims --- luacheck: globals awesome client tag drawin screen -awesome = require( "awesome" ) -client = require( "client" ) -tag = require( "tag" ) -drawin = require( "drawin" ) -screen = require( "screen" ) - --- Force luacheck to be silent about setting those as unused globals -assert(awesome and client and tag) +local file_path, image_path = ... +require("_common_template")(...) local beautiful = require( "beautiful" ) local wibox = require( "wibox" ) local surface = require( "gears.surface" ) local shape = require( "gears.shape" ) --- If luacov is available, use it. Else, do nothing. -pcall(function() - require("luacov.runner")(luacovpath) -end) - --- Silence debug warnings -require("gears.debug").print_warning = function() end - -- Let the test request a size and file format local before, after = loadfile(file_path)() diff --git a/tests/examples/wibox/layout/template.lua b/tests/examples/wibox/layout/template.lua index 50f9bf64..88462ad5 100644 --- a/tests/examples/wibox/layout/template.lua +++ b/tests/examples/wibox/layout/template.lua @@ -1,29 +1,11 @@ -local file_path, image_path, luacovpath = ... - --- Set the global shims --- luacheck: globals awesome client tag drawin screen -awesome = require( "awesome" ) -client = require( "client" ) -tag = require( "tag" ) -drawin = require( "drawin" ) -screen = require( "screen" ) - --- Force luacheck to be silent about setting those as unused globals -assert(awesome and client and tag) +local file_path, image_path = ... +require("_common_template")(...) local wibox = require( "wibox" ) local surface = require( "gears.surface" ) local color = require( "gears.color" ) local beautiful = require( "beautiful" ) --- If luacov is available, use it. Else, do nothing. -pcall(function() - require("luacov.runner")(luacovpath) -end) - --- Silence debug warnings -require("gears.debug").print_warning = function() end - -- Create a generic rectangle widget to show layout disposition local function generic_widget(text) return { diff --git a/tests/examples/wibox/template.lua b/tests/examples/wibox/template.lua index b765e44c..92402c1e 100644 --- a/tests/examples/wibox/template.lua +++ b/tests/examples/wibox/template.lua @@ -1,27 +1,9 @@ -local file_path, image_path, luacovpath = ... - --- Set the global shims --- luacheck: globals awesome client tag drawin screen -awesome = require( "awesome" ) -client = require( "client" ) -tag = require( "tag" ) -drawin = require( "drawin" ) -screen = require( "screen" ) - --- Force luacheck to be silent about setting those as unused globals -assert(awesome and client and tag) +local file_path, image_path = ... +require("_common_template")(...) local wibox = require( "wibox" ) local surface = require( "gears.surface" ) --- If luacov is available, use it. Else, do nothing. -pcall(function() - require("luacov.runner")(luacovpath) -end) - --- Silence debug warnings -require("gears.debug").print_warning = function() end - -- This is the main widget the tests will use as top level local container = wibox.layout.fixed.vertical()