diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/package_shell_test.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/package_shell_test.lua b/tests/package_shell_test.lua new file mode 100644 index 0000000..8a004ca --- /dev/null +++ b/tests/package_shell_test.lua @@ -0,0 +1,33 @@ +local package_dir = "yazi-enter.yazi" +local entry_name = "main.lua" +local entry_path = package_dir .. "/" .. entry_name + +assert(entry_path == "yazi-enter.yazi/main.lua", "unexpected plugin entry path") + +local file = assert(io.open(entry_path, "rb")) +local source = assert(file:read("*a")) +file:close() + +local first_line = source:match("^([^\r\n]*)") +assert(first_line == "--- @since 26.9.1", "invalid compatibility annotation") +assert(not source:find("--- @sync entry", 1, true), "entry must use the default async context") + +local sync_calls = 0 +local environment = { + ya = { + sync = function(callback) + sync_calls = sync_calls + 1 + assert(type(callback) == "function", "ya.sync requires a function") + return callback + end, + }, +} + +local chunk = assert(load(source, "@" .. entry_path, "t", environment)) +local plugin = chunk() + +assert(sync_calls == 1, "expected one top-level synchronous transaction") +assert(type(plugin) == "table", "plugin must export a table") +assert(type(plugin.entry) == "function", "plugin must export an entry method") + +print("package shell checks passed") |