summaryrefslogtreecommitdiff
path: root/mac/.config/LunarVim/tests/lvim/helpers.lua
blob: 83f7a1ab33ded151a9246394de3092603aaa7faf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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 = vim.loop.cwd(),
    on_stderr = function(_, data)
      table.insert(stderr, data)
    end,
  }):sync()
  return ret, stdout, stderr
end

function M.log_contains(query)
  local logfile = require("lvim.core.log"):get_path()
  local ret, stdout, 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
  return false
end

return M