Skip to content

Commit

Permalink
Add a thing we'll use to skip Lean 3 tests when not present.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Oct 18, 2023
1 parent bc530c1 commit 047d940
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 23 deletions.
10 changes: 6 additions & 4 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
globals = {
"_clean_buffer_count",
"vim",
"lean_nvim_default_filetype",
assert = {fields = {"message"}},
"_clean_buffer_count",
"vim",
"lean_nvim_default_filetype",
"describe",
"it",
assert = {fields = {"message"}},
}
9 changes: 1 addition & 8 deletions lua/lean/lean3/health.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
local Job = require('plenary.job')

return {
--- Check whether Lean 3 support is healthy.
---
--- Call me via `:checkhealth lean3`.
check = function()
vim.health.start('lean3')
local succeeded, lean3ls = pcall(Job.new, Job, {
command = 'lean-language-server',
args = { '--stdio' },
writer = ''
})
if succeeded then
lean3ls:sync()
if require('lean.lean3').works() then
vim.health.ok('`lean-language-server`')
else
vim.health.warn('`lean-language-server` not found, lean 3 support will not work')
Expand Down
17 changes: 16 additions & 1 deletion lua/lean/lean3/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local a = require'plenary.async.util'
local Job = require('plenary.job')
local a = require('plenary.async.util')

local Element = require('lean.widgets').Element
local components = require('lean.infoview.components')
Expand All @@ -10,6 +11,20 @@ local subprocess_check_output = util.subprocess_check_output
local lean3 = {}


--- Check if Lean 3 is installed on the current system.
---
--- @return boolean succeeded whether starting Lean 3 worked or not
function lean3.works()
local succeeded, lean3ls = pcall(Job.new, Job, {
command = 'lean-language-server',
args = { '--stdio' },
writer = ''
})
if succeeded then lean3ls:sync() end
return succeeded
end


--- Return the current Lean 3 search path.
---
--- Includes both the Lean 3 core libraries as well as project-specific
Expand Down
28 changes: 21 additions & 7 deletions lua/tests/helpers.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
local assert = require('luassert')

local dedent = require('lean._util').dedent
local lean_lsp_diagnostics = require('lean._util').lean_lsp_diagnostics
local fixtures = require('tests.fixtures')
local infoview = require('lean.infoview')
local progress = require('lean.progress')
local util = require('lean._util')

local helpers = {_clean_buffer_counter = 1}
local helpers = { _clean_buffer_counter = 1 }

--- Run the given tests if Lean 3 is available, otherwise skip.
if require('lean.lean3').works() then
function helpers.if_has_lean3(description, fn)
return describe(description, fn)
end
else
function helpers.if_has_lean3(description, _)
return describe(description, function()
it('lean 3 missing', function()
print('Lean 3 missing. Skipping.')
end)
end)
end
end

--- Feed some keystrokes into the current buffer, replacing termcodes.
function helpers.feed(text, feed_opts)
Expand Down Expand Up @@ -136,7 +150,7 @@ end
function helpers.wait_for_line_diagnostics()
local succeeded, _ = vim.wait(15000, function()
if progress.is_processing(vim.uri_from_bufnr(0)) then return false end
local diagnostics = lean_lsp_diagnostics{
local diagnostics = util.lean_lsp_diagnostics{
lnum = vim.api.nvim_win_get_cursor(0)[1] - 1
}

Expand Down Expand Up @@ -171,7 +185,7 @@ assert:register('assertion', 'contents', has_buf_contents)

--- Assert about the current infoview contents.
local function has_infoview_contents(_, arguments)
local expected = dedent(arguments[1][1] or arguments[1])
local expected = util.dedent(arguments[1][1] or arguments[1])
local target_infoview = arguments[1].infoview or infoview.get_current_infoview()
-- In Lean 3, the fileProgress notification is unreliable,
-- so we may think we're done processing when we're actually not.
Expand Down Expand Up @@ -207,15 +221,15 @@ end

--- Assert about the current infoview contents without waiting for the pins to load.
local function has_infoview_contents_nowait(_, arguments)
local expected = dedent(arguments[1][1] or arguments[1])
local expected = util.dedent(arguments[1][1] or arguments[1])
local target_infoview = arguments[1].infoview or infoview.get_current_infoview()
local got = table.concat(target_infoview:get_lines(), '\n')
assert.are.same(expected, got)
return true
end

local function has_diff_contents(_, arguments)
local expected = dedent(arguments[1][1] or arguments[1])
local expected = util.dedent(arguments[1][1] or arguments[1])
local target_infoview = arguments[1].infoview or infoview.get_current_infoview()
local got = table.concat(target_infoview:get_diff_lines(), '\n')
assert.are.same(expected, got)
Expand Down
4 changes: 2 additions & 2 deletions lua/tests/lean3/checkhealth_spec.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require('tests.helpers')
local if_has_lean3 = require('tests.helpers').if_has_lean3

describe('checkhealth', function()
if_has_lean3('checkhealth', function()
it('passes the health check', function()
vim.api.nvim_command('silent checkhealth lean3')
assert.has_match([[
Expand Down
2 changes: 1 addition & 1 deletion lua/tests/lean3/ft_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local fixtures = require('tests.fixtures')

require('lean').setup { lsp3 = { enable = true } }

describe('ft.detect', function()
helpers.if_has_lean3('ft.detect', function()
for kind, path in unpack(fixtures.lean3_project.files_it) do
it('detects ' .. kind .. ' lean 3 files', function()
vim.cmd('edit! ' .. path)
Expand Down

0 comments on commit 047d940

Please sign in to comment.