From 9fc120edc511c4847c427cb488a89af24b5eeee0 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 20 Jul 2023 00:52:13 +0300 Subject: [PATCH 01/10] chore(lua_ls): now lua_ls knows about testing functions --- .luarc.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .luarc.json diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 0000000..a0d5712 --- /dev/null +++ b/.luarc.json @@ -0,0 +1,10 @@ +{ + "diagnostics.globals": [ + "describe", + "it", + "before_each", + "after_each", + "before_all", + "after_all" + ] +} From c608ddbd67cb98bd15a3fa0370bb0cbf6bae5ac0 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 20 Jul 2023 00:52:42 +0300 Subject: [PATCH 02/10] spec: change way how tests srtuctured --- spec/gopher_spec.lua | 5 -- spec/gopher_struct_tags_spec.lua | 49 ------------------- .../config_spec.lua} | 4 -- .../utils_spec.lua} | 0 4 files changed, 58 deletions(-) delete mode 100644 spec/gopher_spec.lua delete mode 100644 spec/gopher_struct_tags_spec.lua rename spec/{gopher_config_spec.lua => units/config_spec.lua} (94%) rename spec/{gopher_utils_spec.lua => units/utils_spec.lua} (100%) diff --git a/spec/gopher_spec.lua b/spec/gopher_spec.lua deleted file mode 100644 index b50b5ea..0000000 --- a/spec/gopher_spec.lua +++ /dev/null @@ -1,5 +0,0 @@ -describe("gopher", function() - it("can be required", function() - require "gopher" - end) -end) diff --git a/spec/gopher_struct_tags_spec.lua b/spec/gopher_struct_tags_spec.lua deleted file mode 100644 index ad8dd6e..0000000 --- a/spec/gopher_struct_tags_spec.lua +++ /dev/null @@ -1,49 +0,0 @@ -local cur_dir = vim.fn.expand "%:p:h" - -describe("gopher.struct_tags", function() - it("can be required", function() - require "gopher.struct_tags" - end) - - it("can add json tag to struct", function() - local tag = require "gopher.struct_tags" - local temp_file = vim.fn.tempname() .. ".go" - local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_input.go") - local output_file = - vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_output.go"), "\n") - - vim.fn.writefile(input_file, temp_file) - vim.cmd("silent exe 'e " .. temp_file .. "'") - vim.bo.filetype = "go" - - local bufn = vim.fn.bufnr(0) - vim.fn.setpos(".", { bufn, 3, 6, 0 }) - tag.add() - - vim.wait(100) - assert.are.same(output_file, vim.fn.join(vim.fn.readfile(temp_file), "\n")) - - vim.cmd("bd! " .. temp_file) - end) - - it("can remove json tag from struct", function() - local tag = require "gopher.struct_tags" - local temp_file = vim.fn.tempname() .. ".go" - local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_input.go") - local output_file = - vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_output.go"), "\n") - - vim.fn.writefile(input_file, temp_file) - vim.cmd("silent exe 'e " .. temp_file .. "'") - vim.bo.filetype = "go" - - local bufn = vim.fn.bufnr() - vim.fn.setpos(".", { bufn, 3, 6, 0 }) - tag.remove() - - vim.wait(100) - assert.are.same(output_file, vim.fn.join(vim.fn.readfile(temp_file), "\n")) - - vim.cmd("bd! " .. temp_file) - end) -end) diff --git a/spec/gopher_config_spec.lua b/spec/units/config_spec.lua similarity index 94% rename from spec/gopher_config_spec.lua rename to spec/units/config_spec.lua index 1d033c0..3693eb0 100644 --- a/spec/gopher_config_spec.lua +++ b/spec/units/config_spec.lua @@ -1,8 +1,4 @@ describe("gopher.config", function() - it("can be required", function() - require "gopher.config" - end) - it(".setup() when gets empty table not edit config", function() local c = require "gopher.config" c.setup {} diff --git a/spec/gopher_utils_spec.lua b/spec/units/utils_spec.lua similarity index 100% rename from spec/gopher_utils_spec.lua rename to spec/units/utils_spec.lua From 1ce9244c525f6c80d9450a46ad5d68c5a2f14ad3 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 20 Jul 2023 19:55:37 +0300 Subject: [PATCH 03/10] test(config): refactor tests --- spec/units/config_spec.lua | 40 +++++++++++++++----------------------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/spec/units/config_spec.lua b/spec/units/config_spec.lua index 3693eb0..1fd91dd 100644 --- a/spec/units/config_spec.lua +++ b/spec/units/config_spec.lua @@ -1,37 +1,29 @@ describe("gopher.config", function() - it(".setup() when gets empty table not edit config", function() + it(".setup() should provide default when .setup() is not called", function() local c = require "gopher.config" - c.setup {} - assert.are.same(c.config.commands.go, "go") - assert.are.same(c.config.commands.gomodifytags, "gomodifytags") - assert.are.same(c.config.commands.gotests, "gotests") - assert.are.same(c.config.commands.impl, "impl") + assert.are.same(c.commands.go, "go") + assert.are.same(c.commands.gomodifytags, "gomodifytags") + assert.are.same(c.commands.gotests, "gotests") + assert.are.same(c.commands.impl, "impl") + assert.are.same(c.commands.iferr, "iferr") + assert.are.same(c.commands.dlv, "dlv") end) - it(".setup() when get one custom value sets that", function() - local c = require "gopher.config" - c.setup { commands = { - go = "custom_go", - } } - - assert.are.same(c.config.commands.go, "custom_go") - end) - - it(".setup() when get all custom values sets it", function() + it(".setup() should change options on users config", function() local c = require "gopher.config" c.setup { commands = { - go = "go1.18", - gomodifytags = "user-gomodifytags", - gotests = "gotests", - impl = "goimpl", + go = "go1.420", + gomodifytags = "iDontUseRustBtw", }, } - assert.are.same(c.config.commands.go, "go1.18") - assert.are.same(c.config.commands.gomodifytags, "user-gomodifytags") - assert.are.same(c.config.commands.gotests, "gotests") - assert.are.same(c.config.commands.impl, "goimpl") + assert.are.same(c.commands.go, "go1.420") + assert.are.same(c.commands.gomodifytags, "iDontUseRustBtw") + assert.are.same(c.commands.gotests, "gotests") + assert.are.same(c.commands.impl, "impl") + assert.are.same(c.commands.iferr, "iferr") + assert.are.same(c.commands.dlv, "dlv") end) end) From a2959e84463255d419a4374d41b93b867b8f3773 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 20 Jul 2023 20:05:22 +0300 Subject: [PATCH 04/10] test: utils --- spec/units/utils_spec.lua | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/spec/units/utils_spec.lua b/spec/units/utils_spec.lua index f052cff..dcf94f2 100644 --- a/spec/units/utils_spec.lua +++ b/spec/units/utils_spec.lua @@ -1,19 +1,25 @@ describe("gopher._utils", function() - it("can be requried", function() - require "gopher._utils" - end) + local u = require "gopher._utils" - it(".empty() with non-empty talbe", function() - local empty = require("gopher._utils").empty - local res = empty { first = "1", second = 2 } + describe(".is_tbl_empty()", function() + it("it is empty", function() + assert.are.same(true, u.is_tbl_empty {}) + end) - assert.are.same(res, false) + it("it is not empty", function() + assert.are.same(false, u.is_tbl_empty { first = "1", second = 2 }) + end) end) - it(".empty() with empty talbe", function() - local empty = require("gopher._utils").empty - local res = empty {} + describe(".sreq()", function() + it("can require existing module", function() + assert.are.same(require "gopher", u.sreq "gopher") + end) - assert.are.same(res, true) + it("cannot require non-existing module", function() + assert.has.errors(function() + u.sreq "iDontExistBtw" + end) + end) end) end) From b745b0a5a2df42be5118db0c4ef2c9c5887410ad Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 20 Jul 2023 20:05:27 +0300 Subject: [PATCH 05/10] refactor(utils): remove not used function --- lua/gopher/_utils/init.lua | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/lua/gopher/_utils/init.lua b/lua/gopher/_utils/init.lua index a083a78..4915ab3 100644 --- a/lua/gopher/_utils/init.lua +++ b/lua/gopher/_utils/init.lua @@ -9,17 +9,6 @@ function utils.is_tbl_empty(t) return next(t) == nil end ----@param s string ----@return string -function utils.rtrim(s) - local n = #s - while n > 0 and s:find("^%s", n) do - n = n - 1 - end - - return s:sub(1, n) -end - ---@param msg string ---@param lvl any function utils.deferred_notify(msg, lvl) From 2b28db7c12181b9b6b9b926cfcbd4657ef5546ad Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 20 Jul 2023 20:07:50 +0300 Subject: [PATCH 06/10] chore(ci): add test runner --- .github/workflows/tests.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..5ea96dd --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,30 @@ +name: tests +on: [push, pull_request] + +jobs: + tests: + strategy: + matrix: + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v3 + - uses: arduino/setup-task@v1 + with: + version: 3.x + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Install Neovim + shell: bash + run: | + mkdir -p /tmp/nvim + wget -q https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage -O /tmp/nvim/nvim.appimage + cd /tmp/nvim + chmod a+x ./nvim.appimage + ./nvim.appimage --appimage-extract + echo "/tmp/nvim/squashfs-root/usr/bin/" >> $GITHUB_PATH + - name: Run Tests + run: | + nvim --version + [ ! -d tests ] && exit 0 + task tests From b81318c2d7a5d0090d3916b03c3748b66bc75299 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 20 Jul 2023 20:09:58 +0300 Subject: [PATCH 07/10] chore(ci): remove taskfile from deps --- .github/workflows/tests.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5ea96dd..4ca0372 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,11 +9,6 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 - - uses: arduino/setup-task@v1 - with: - version: 3.x - repo-token: ${{ secrets.GITHUB_TOKEN }} - - name: Install Neovim shell: bash run: | @@ -27,4 +22,4 @@ jobs: run: | nvim --version [ ! -d tests ] && exit 0 - task tests + nvim --headless -u ./spec/minimal_init.lua -c "PlenaryBustedDirectory spec {minimal_init='./spec/minimal_init.lua', sequential=true}" From 31302bdebd6213640fc14476a4775468f35a7291 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 20 Jul 2023 20:11:14 +0300 Subject: [PATCH 08/10] add thing for testing ci --- spec/i_am_not_working.lua | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spec/i_am_not_working.lua diff --git a/spec/i_am_not_working.lua b/spec/i_am_not_working.lua new file mode 100644 index 0000000..a129071 --- /dev/null +++ b/spec/i_am_not_working.lua @@ -0,0 +1,3 @@ +it("asdfl", function() + assert.are.same(false, true) +end) From 75ad579406aff2e2841cf4c14cf89e7d4bffc0f8 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 20 Jul 2023 20:13:43 +0300 Subject: [PATCH 09/10] fix ci --- .github/workflows/tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4ca0372..b3eecf5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,5 +21,4 @@ jobs: - name: Run Tests run: | nvim --version - [ ! -d tests ] && exit 0 nvim --headless -u ./spec/minimal_init.lua -c "PlenaryBustedDirectory spec {minimal_init='./spec/minimal_init.lua', sequential=true}" From 5d4ccb50bd853b53581cbfeed6bbc6d5426fce34 Mon Sep 17 00:00:00 2001 From: Smirnov Oleksandr Date: Thu, 20 Jul 2023 20:14:40 +0300 Subject: [PATCH 10/10] remove the thing --- spec/i_am_not_working.lua | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 spec/i_am_not_working.lua diff --git a/spec/i_am_not_working.lua b/spec/i_am_not_working.lua deleted file mode 100644 index a129071..0000000 --- a/spec/i_am_not_working.lua +++ /dev/null @@ -1,3 +0,0 @@ -it("asdfl", function() - assert.are.same(false, true) -end)