repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
neovim/tests/bugabinga/pivi/runtime_spec.lua
Raw---@diagnostic disable: duplicate-set-field, need-check-nil, param-type-mismatch, assign-type-mismatch
local runtime = require 'bugabinga.pivi.runtime'
describe( 'pivi runtime', function()
local original
before_each( function()
original = vim.g.pivi_executable
end )
after_each( function()
vim.g.pivi_executable = original
end )
it( 'finds the assets pivi ships', function()
assert.is_true( runtime.extension_path():find( 'index.ts', 1, true ) ~= nil )
assert.is_true( runtime.client_path():find( 'client.lua', 1, true ) ~= nil )
assert.is_true( runtime.skill_path():find( 'SKILL.md', 1, true ) ~= nil )
end )
it( 'lists install directories without holes', function()
local directories = runtime.install_directories()
assert.is_true( #directories > 0 )
local counted = 0
for _ in pairs( directories ) do counted = counted + 1 end
-- A nil entry would end ipairs at the first index and hide every later directory.
assert.equal( #directories, counted )
for _, directory in ipairs( directories ) do
assert.is_nil( directory:find( '\\', 1, true ) )
end
end )
it( 'resolves pi to a path that can actually be spawned', function()
vim.g.pivi_executable = nil
local resolved, failure = runtime.executable()
assert.is_nil( failure )
assert.is_string( resolved )
assert.is_true( resolved:lower():find( 'pi', 1, true ) ~= nil )
local stat = vim.uv.fs_stat( resolved )
assert.is_true( stat ~= nil or vim.fn.executable( resolved ) == 1 )
end )
it( 'reports a configured executable that does not exist', function()
vim.g.pivi_executable = vim.fn.tempname() .. '-absent'
local resolved, failure = runtime.executable()
assert.is_nil( resolved )
assert.is_true( failure:find( 'not found', 1, true ) ~= nil )
end )
it( 'accepts a configured executable that exists', function()
local path = vim.fn.tempname() .. '.txt'
vim.fn.writefile( { 'not really pi', }, path )
vim.g.pivi_executable = path
assert.equal( vim.fs.normalize( path ), runtime.executable() )
end )
end )