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 <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2017-11-16 15:39:58 +01:00
parent 674120786c
commit 7dbc44950b
1 changed files with 16 additions and 4 deletions

View File

@ -10,13 +10,25 @@ _G.os.time = function()
end end
local dir_cache = require("gears.filesystem.subdirectory_cache") local dir_cache = require("gears.filesystem.subdirectory_cache")
local protected_call = require("gears.protected_call")
local gio = require("lgi").Gio 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("gears.filesystem.subdirectory_cache", function()
describe("finds files", function() describe("finds files", function()
-- This assumes that we are run from awesome's source directory -- 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") 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("filesystem/subdirectory_cache_spec.lua"))
assert.is_true(cache:async_check_exists("cache_spec.lua")) assert.is_true(cache:async_check_exists("cache_spec.lua"))
@ -26,7 +38,7 @@ describe("gears.filesystem.subdirectory_cache", function()
end) end)
describe("non-existing directory", function() describe("non-existing directory", function()
gio.Async.call(protected_call)(function() gio.Async.call(do_protected_call)(function()
local gdebug = require("gears.debug") local gdebug = require("gears.debug")
local print_warning = gdebug.print_warning local print_warning = gdebug.print_warning
local called local called
@ -54,7 +66,7 @@ describe("gears.filesystem.subdirectory_cache", function()
test_path:delete() test_path:delete()
assert(test_path:make_directory()) 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 -- At this point the directory is empty
local cache = dir_cache.async_new(test_path:get_path()) local cache = dir_cache.async_new(test_path:get_path())
assert.is.same({}, cache.known_paths) assert.is.same({}, cache.known_paths)