diff --git a/spec/fixtures/tests/add_function_input.go b/spec/fixtures/tests/function_input.go similarity index 73% rename from spec/fixtures/tests/add_function_input.go rename to spec/fixtures/tests/function_input.go index 86d26e0..bde08df 100644 --- a/spec/fixtures/tests/add_function_input.go +++ b/spec/fixtures/tests/function_input.go @@ -1,4 +1,4 @@ -package for_test +package fortest func Add(x, y int) int { return 2 + x + y diff --git a/spec/fixtures/tests/add_function_output.go b/spec/fixtures/tests/function_output.go similarity index 62% rename from spec/fixtures/tests/add_function_output.go rename to spec/fixtures/tests/function_output.go index 846d465..42ebd4c 100644 --- a/spec/fixtures/tests/add_function_output.go +++ b/spec/fixtures/tests/function_output.go @@ -1,10 +1,6 @@ -package for_test +package fortest -import ( - "testing" - - "gotest.tools/v3/assert" -) +import "testing" func TestAdd(t *testing.T) { type args struct { @@ -20,7 +16,9 @@ func TestAdd(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - assert.Equal(t, tt.want, Add(tt.args.x, tt.args.y)) + if got := Add(tt.args.x, tt.args.y); got != tt.want { + t.Errorf("Add() = %v, want %v", got, tt.want) + } }) } } diff --git a/spec/fixtures/tests/method_input.go b/spec/fixtures/tests/method_input.go new file mode 100644 index 0000000..fe04124 --- /dev/null +++ b/spec/fixtures/tests/method_input.go @@ -0,0 +1,7 @@ +package fortest + +type ForTest struct{} + +func (t *ForTest) Add(x, y int) int { + return 2 + x + y +} diff --git a/spec/fixtures/tests/method_output.go b/spec/fixtures/tests/method_output.go new file mode 100644 index 0000000..7f927b5 --- /dev/null +++ b/spec/fixtures/tests/method_output.go @@ -0,0 +1,26 @@ +package fortest + +import "testing" + +func TestForTest_Add(t *testing.T) { + type args struct { + x int + y int + } + tests := []struct { + name string + tr *ForTest + args args + want int + }{ + // TODO: Add test cases. + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tr := &ForTest{} + if got := tr.Add(tt.args.x, tt.args.y); got != tt.want { + t.Errorf("ForTest.Add() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/spec/integration/gotests_test.lua b/spec/integration/gotests_test.lua index b5751b5..6f6a871 100644 --- a/spec/integration/gotests_test.lua +++ b/spec/integration/gotests_test.lua @@ -15,11 +15,27 @@ T["gotests"] = MiniTest.new_set {} --- All other parts are handled `gotests` tool itself. T["gotests"]["should add test for function under cursor"] = function() - MiniTest.skip "come back daddy" + local tmp = "/home/olex/2.go" + local fixtures = t.get_fixtures "tests/function" + t.writefile(tmp, fixtures.input) + + child.cmd("silent edit " .. tmp) + child.fn.setpos(".", { child.fn.bufnr "%", 3, 6 }) + child.cmd "GoTestAdd" + + t.eq(fixtures.output, t.readfile(tmp:gsub(".go", "_test.go"))) end T["gotests"]["should add test for method under cursor"] = function() - MiniTest.skip "come back daddy" + local tmp = "/home/olex/1.go" + local fixtures = t.get_fixtures "tests/method" + t.writefile(tmp, fixtures.input) + + child.cmd("silent edit " .. tmp) + child.fn.setpos(".", { child.fn.bufnr "%", 5, 19 }) + child.cmd "GoTestAdd" + + t.eq(fixtures.output, t.readfile(tmp:gsub(".go", "_test.go"))) end return T diff --git a/spec/testutils.lua b/spec/testutils.lua index eff2dfa..e5ab9a2 100644 --- a/spec/testutils.lua +++ b/spec/testutils.lua @@ -1,10 +1,10 @@ local base_dir = vim.env.GOPHER_DIR or vim.fn.expand "%:p:h" -local fixtures_dir = vim.fs.joinpath(base_dir, "/spec/fixtures/") ---@class gopher.TestUtils local testutils = {} -testutils.mininit_path = vim.fs.joinpath(base_dir, "/scripts/minimal_init.lua") +testutils.mininit_path = vim.fs.joinpath(base_dir, "scripts", "minimal_init.lua") +testutils.fixtures_dir = vim.fs.joinpath(base_dir, "spec/fixtures") ---@generic T ---@param a T @@ -35,8 +35,8 @@ end ---@return {input: string, output: string} function testutils.get_fixtures(fixture) return { - input = testutils.readfile(fixtures_dir .. fixture .. "_input.go"), - output = testutils.readfile(fixtures_dir .. fixture .. "_output.go"), + input = testutils.readfile(vim.fs.joinpath(testutils.fixtures_dir, fixture) .. "_input.go"), + output = testutils.readfile(vim.fs.joinpath(testutils.fixtures_dir, fixture) .. "_output.go"), } end