test: unit (#97)

* refactor(utils): remove unused function

* fix(installer): actually pass what should be passed

* docs: add explanation comment

* test: add utils

* refactor(utils): flatten the dir of files

* remove .luarc
This commit is contained in:
Smirnov Oleksandr 2025-03-21 22:10:40 +02:00 committed by Oleksandr Smirnov
parent 9aa0038125
commit 7af08c9780
No known key found for this signature in database
8 changed files with 39 additions and 26 deletions

1
.envrc
View file

@ -1,3 +1,4 @@
dotenv dotenv
# GOPHER_DIR - needed only for tests, to find the root of the project
env_vars_required GOPHER_DIR env_vars_required GOPHER_DIR

View file

@ -1,10 +0,0 @@
{
"diagnostics.globals": [
"describe",
"it",
"before_each",
"after_each",
"before_all",
"after_all"
]
}

View file

@ -2,18 +2,6 @@ local c = require "gopher.config"
local log = require "gopher._utils.log" local log = require "gopher._utils.log"
local utils = {} local utils = {}
---@param msg string
---@param lvl? number
function utils.deferred_notify(msg, lvl)
lvl = lvl or vim.log.levels.INFO
vim.defer_fn(function()
vim.notify(msg, lvl, {
title = c.___plugin_name,
})
log.debug(msg)
end, 0)
end
---@param msg string ---@param msg string
---@param lvl? number ---@param lvl? number
function utils.notify(msg, lvl) function utils.notify(msg, lvl)

View file

@ -12,7 +12,7 @@
local log = require "gopher._utils.log" local log = require "gopher._utils.log"
local tags = require "gopher.struct_tags" local tags = require "gopher.struct_tags"
local tests = require "gopher.gotests" local tests = require "gopher.gotests"
local gocmd = require("gopher._utils.runner.gocmd").run local gocmd = require("gopher._utils.gocmd").run
local gopher = {} local gopher = {}
---@toc_entry Setup ---@toc_entry Setup

View file

@ -15,12 +15,17 @@ local urls = {
---@param url string ---@param url string
local function handle_intall_exit(opt, url) local function handle_intall_exit(opt, url)
if opt.code ~= 0 then if opt.code ~= 0 then
u.deferred_notify("go install failed: " .. url) vim.schedule(function()
u.notify("go install failed: " .. url)
end)
log.error("go install failed:", "url", url, "opt", vim.inspect(opt)) log.error("go install failed:", "url", url, "opt", vim.inspect(opt))
return return
end end
u.deferred_notify("go install-ed: " .. url) vim.schedule(function()
u.notify("go install-ed: " .. url)
end)
end end
---@param url string ---@param url string
@ -40,7 +45,7 @@ end
---@param opts? {sync:boolean} ---@param opts? {sync:boolean}
function installer.install_deps(opts) function installer.install_deps(opts)
opts = opts or {} opts = opts or {}
for url, _ in pairs(urls) do for _, url in pairs(urls) do
if opts.sync then if opts.sync then
install_sync(url) install_sync(url)
else else

29
spec/unit/utils_test.lua Normal file
View file

@ -0,0 +1,29 @@
local t = require "spec.testutils"
local child = MiniTest.new_child_neovim()
local T = MiniTest.new_set {
hooks = {
post_once = child.stop,
pre_case = function()
child.restart { "-u", t.mininit_path }
end,
},
}
T["utils"] = MiniTest.new_set()
T["utils"]["should .remove_empty_lines()"] = function()
local u = require "gopher._utils"
local inp = { "hi", "", "a", "", "", "asdf" }
t.eq(u.remove_empty_lines(inp), { "hi", "a", "asdf" })
end
T["utils"]["should .readfile_joined()"] = function()
local data = "line1\nline2\nline3"
local tmp = t.tmpfile()
local u = require "gopher._utils"
t.writefile(tmp, data)
t.eq(u.readfile_joined(tmp), data)
end
return T