robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.0 KiB78 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
5local clear = n.clear
6local eq = t.eq
7local exec_lua = n.exec_lua
8local is_os = t.is_os
9local pathsep = n.get_pathsep()
10local write_file = t.write_file
11
12describe(':log', function()
13  local xstate = 'Xstate'
14  local name = (is_os('win') and 'nvim-data' or 'nvim')
15
16  before_each(function()
17    clear { env = { XDG_STATE_HOME = xstate } }
18
19    local std_state = xstate .. pathsep .. name
20    n.mkdir_p(std_state .. pathsep .. 'logs')
21    write_file(std_state .. '/logs/nvim.log', [[nvim log]])
22    write_file(std_state .. '/logs/foo.log', [[foo log]])
23  end)
24
25  after_each(function()
26    n.rmdir(xstate)
27  end)
28
29  it('without argument opens log folder', function()
30    eq(
31      xstate .. '/' .. name .. '/logs',
32      exec_lua(function()
33        vim.cmd('log')
34        return vim.fs.normalize(vim.fn.expand('%'))
35      end)
36    )
37  end)
38
39  it('with argument opens corresponding log file', function()
40    eq(
41      xstate .. '/' .. name .. '/logs/foo.log',
42      exec_lua(function()
43        vim.cmd('log foo')
44        return vim.fs.normalize(vim.fn.expand('%'))
45      end)
46    )
47  end)
48
49  it('nvim works with non-default $NVIM_LOG_FILE', function()
50    clear { env = { XDG_STATE_HOME = xstate, NVIM_LOG_FILE = 'Xfoo.log' } }
51    write_file('Xfoo.log', [[nvim log]])
52    eq(
53      'Xfoo.log',
54      exec_lua(function()
55        vim.cmd('log nvim')
56        return vim.fn.expand('%')
57      end)
58    )
59  end)
60
61  it('argument completion', function()
62    local completions = exec_lua(function()
63      return vim.fn.getcompletion('log ', 'cmdline')
64    end)
65    eq({ 'foo', 'nvim' }, completions)
66  end)
67
68  it('works without runtime', function()
69    clear {
70      args_rm = { '-u' },
71      args = { '-u', 'NONE' },
72      env = { VIMRUNTIME = 'non-existent' },
73    }
74    exec_lua(function()
75      vim.cmd('log')
76    end)
77  end)
78end)