all repos

gopher.nvim @ 7af08c978057499384c5dfcfd67e951d12cfb875

Minimalistic plugin for Go development
8 files changed, 39 insertions(+), 26 deletions(-)
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
Author: Smirnov Oleksandr ss2316544@gmail.com
Committed by: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2025-03-21 22:12:26 +0200
Parent: 9aa0038
M .envrc

@@ -1,3 +1,4 @@

dotenv +# GOPHER_DIR - needed only for tests, to find the root of the project env_vars_required GOPHER_DIR
D

@@ -1,10 +0,0 @@

-{ - "diagnostics.globals": [ - "describe", - "it", - "before_each", - "after_each", - "before_all", - "after_all" - ] -}
M lua/gopher/_utils/init.lua

@@ -4,18 +4,6 @@ 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 lvl? number function utils.notify(msg, lvl) lvl = lvl or vim.log.levels.INFO vim.notify(msg, lvl, {
M lua/gopher/init.lua

@@ -12,7 +12,7 @@

local log = require "gopher._utils.log" local tags = require "gopher.struct_tags" local tests = require "gopher.gotests" -local gocmd = require("gopher._utils.runner.gocmd").run +local gocmd = require("gopher._utils.gocmd").run local gopher = {} ---@toc_entry Setup
M lua/gopher/installer.lua

@@ -15,12 +15,17 @@ ---@param opt vim.SystemCompleted

---@param url string local function handle_intall_exit(opt, url) 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)) return end - u.deferred_notify("go install-ed: " .. url) + vim.schedule(function() + u.notify("go install-ed: " .. url) + end) end ---@param url string

@@ -40,7 +45,7 @@ ---Install required go deps

---@param opts? {sync:boolean} function installer.install_deps(opts) opts = opts or {} - for url, _ in pairs(urls) do + for _, url in pairs(urls) do if opts.sync then install_sync(url) else
A spec/unit/utils_test.lua

@@ -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