summaryrefslogtreecommitdiff
path: root/tests/helpers.lua
diff options
context:
space:
mode:
authorkylo252 <[email protected]>2022-01-02 14:53:01 +0100
committerGitHub <[email protected]>2022-01-02 14:53:01 +0100
commitb3cfd165fbca4c8b595ed577027a5171e33a00e9 (patch)
treebfc6526edf613b294733d46ff823d69d6e9a58df /tests/helpers.lua
parent73bf039c6333ba9cb3af93437b26c41e14566c47 (diff)
refactor(test): cleanup test utilities (#2132)
Diffstat (limited to 'tests/helpers.lua')
-rw-r--r--tests/helpers.lua51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/helpers.lua b/tests/helpers.lua
new file mode 100644
index 00000000..ada83267
--- /dev/null
+++ b/tests/helpers.lua
@@ -0,0 +1,51 @@
+local M = {}
+
+function M.search_file(file, args)
+ local Job = require "plenary.job"
+ local stderr = {}
+ local stdout, ret = Job
+ :new({
+ command = "grep",
+ args = { args, file },
+ cwd = get_cache_dir(),
+ on_stderr = function(_, data)
+ table.insert(stderr, data)
+ end,
+ })
+ :sync()
+ return stdout, ret, stderr
+end
+
+function M.file_contains(file, query)
+ local stdout, ret, stderr = M.search_file(file, query)
+ if ret == 0 then
+ return true
+ end
+ if not vim.tbl_isempty(stderr) then
+ error(vim.inspect(stderr))
+ end
+ if not vim.tbl_isempty(stdout) then
+ error(vim.inspect(stdout))
+ end
+ return false
+end
+
+function M.log_contains(query)
+ local logfile = require("lvim.core.log"):get_path()
+ local stdout, ret, stderr = M.search_file(logfile, query)
+ if ret == 0 then
+ return true
+ end
+ if not vim.tbl_isempty(stderr) then
+ error(vim.inspect(stderr))
+ end
+ if not vim.tbl_isempty(stdout) then
+ error(vim.inspect(stdout))
+ end
+ if not vim.tbl_isempty(stderr) then
+ error(vim.inspect(stderr))
+ end
+ return false
+end
+
+return M