diff --git a/.envrc b/.envrc index dd6cca9..1973517 100644 --- a/.envrc +++ b/.envrc @@ -1,3 +1,4 @@ dotenv +# GOPHER_DIR - needed only for tests, to find the root of the project env_vars_required GOPHER_DIR diff --git a/.luarc.json b/.luarc.json deleted file mode 100644 index a0d5712..0000000 --- a/.luarc.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "diagnostics.globals": [ - "describe", - "it", - "before_each", - "after_each", - "before_all", - "after_all" - ] -} diff --git a/lua/gopher/_utils/runner/gocmd.lua b/lua/gopher/_utils/gocmd.lua similarity index 100% rename from lua/gopher/_utils/runner/gocmd.lua rename to lua/gopher/_utils/gocmd.lua diff --git a/lua/gopher/_utils/init.lua b/lua/gopher/_utils/init.lua index 1ff0f28..0d9f5e2 100644 --- a/lua/gopher/_utils/init.lua +++ b/lua/gopher/_utils/init.lua @@ -2,18 +2,6 @@ local c = require "gopher.config" local log = require "gopher._utils.log" 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) diff --git a/lua/gopher/_utils/runner/init.lua b/lua/gopher/_utils/runner.lua similarity index 100% rename from lua/gopher/_utils/runner/init.lua rename to lua/gopher/_utils/runner.lua diff --git a/lua/gopher/init.lua b/lua/gopher/init.lua index dfcefc9..0028dcc 100644 --- a/lua/gopher/init.lua +++ b/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 diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index adcbec6..cc61f92 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -15,12 +15,17 @@ local urls = { ---@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 @@ end ---@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 diff --git a/spec/unit/utils_test.lua b/spec/unit/utils_test.lua new file mode 100644 index 0000000..7001261 --- /dev/null +++ b/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