From 7dbc44950b4820c9ec33ab1e3193f6e4bbbfbbd5 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Thu, 16 Nov 2017 15:39:58 +0100 Subject: [PATCH] subdirectory_cache_spec: Fix for non-yieldable pcalls Lua 5.1 cannot yield across protected calls. Thus, the test must run in an unprotected context here. Signed-off-by: Uli Schlachter --- .../filesystem/subdirectory_cache_spec.lua | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/spec/gears/filesystem/subdirectory_cache_spec.lua b/spec/gears/filesystem/subdirectory_cache_spec.lua index 0b071d854..de1982cf1 100644 --- a/spec/gears/filesystem/subdirectory_cache_spec.lua +++ b/spec/gears/filesystem/subdirectory_cache_spec.lua @@ -10,13 +10,25 @@ _G.os.time = function() end local dir_cache = require("gears.filesystem.subdirectory_cache") -local protected_call = require("gears.protected_call") local gio = require("lgi").Gio +local do_protected_call = require("gears.protected_call").call +do + local _, has_yieldable_pcall = coroutine.resume(coroutine.create(function() + return pcall(coroutine.yield, true) + end)) + if not has_yieldable_pcall then + -- No yieldable pcall, no protected call + do_protected_call = function(f, ...) + return f(...) + end + end +end + describe("gears.filesystem.subdirectory_cache", function() describe("finds files", function() -- This assumes that we are run from awesome's source directory - gio.Async.call(protected_call)(function() + gio.Async.call(do_protected_call)(function() local cache = dir_cache.async_new("spec/gears") assert.is_true(cache:async_check_exists("filesystem/subdirectory_cache_spec.lua")) assert.is_true(cache:async_check_exists("cache_spec.lua")) @@ -26,7 +38,7 @@ describe("gears.filesystem.subdirectory_cache", function() end) describe("non-existing directory", function() - gio.Async.call(protected_call)(function() + gio.Async.call(do_protected_call)(function() local gdebug = require("gears.debug") local print_warning = gdebug.print_warning local called @@ -54,7 +66,7 @@ describe("gears.filesystem.subdirectory_cache", function() test_path:delete() assert(test_path:make_directory()) - assert(gio.Async.call(protected_call)(function() + assert(gio.Async.call(do_protected_call)(function() -- At this point the directory is empty local cache = dir_cache.async_new(test_path:get_path()) assert.is.same({}, cache.known_paths)