-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ccbad5
commit 84f0850
Showing
6 changed files
with
267 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package testify | ||
|
||
// Basic imports | ||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
type OtherTestSuite struct { | ||
suite.Suite | ||
VariableThatShouldStartAtFive int | ||
} | ||
|
||
// A second suite setup method. | ||
func (suite *OtherTestSuite) SetupTest() { | ||
suite.VariableThatShouldStartAtFive = 5 | ||
} | ||
|
||
func TestOtherTestSuite(t *testing.T) { | ||
s := &OtherTestSuite{} | ||
suite.Run(t, s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
local nio = require("nio") | ||
local _ = require("plenary") | ||
|
||
local adapter = require("neotest-golang") | ||
local options = require("neotest-golang.options") | ||
local testify = require("neotest-golang.features.testify") | ||
|
||
local function compareIgnoringKeys(t1, t2, ignoreKeys) | ||
local function copyTable(t, ignoreKeys) | ||
local copy = {} | ||
for k, v in pairs(t) do | ||
if not ignoreKeys[k] then | ||
if type(v) == "table" then | ||
copy[k] = copyTable(v, ignoreKeys) | ||
else | ||
copy[k] = v | ||
end | ||
end | ||
end | ||
return copy | ||
end | ||
return copyTable(t1, ignoreKeys), copyTable(t2, ignoreKeys) | ||
end | ||
|
||
describe("With testify_enabled=false", function() | ||
it("Discover test functions", function() | ||
-- Arrange | ||
local test_filepath = vim.loop.cwd() | ||
.. "/tests/go/testify/positions_test.go" | ||
local expected = { | ||
{ | ||
id = test_filepath, | ||
name = "positions_test.go", | ||
path = test_filepath, | ||
type = "file", | ||
}, | ||
{ | ||
{ | ||
id = test_filepath .. "::TestExampleTestSuite", | ||
name = "TestExampleTestSuite", | ||
path = test_filepath, | ||
type = "test", | ||
}, | ||
}, | ||
{ | ||
{ | ||
id = test_filepath .. "::TestTrivial", | ||
name = "TestTrivial", | ||
path = test_filepath, | ||
type = "test", | ||
}, | ||
}, | ||
} | ||
|
||
-- Act | ||
---@type neotest.Tree | ||
local tree = | ||
nio.tests.with_async_context(adapter.discover_positions, test_filepath) | ||
|
||
-- Assert | ||
local result = tree:to_list() | ||
local ignoreKeys = { range = true } | ||
local expectedCopy, resultCopy = | ||
compareIgnoringKeys(expected, result, ignoreKeys) | ||
assert.are.same(vim.inspect(expectedCopy), vim.inspect(resultCopy)) | ||
assert.are.same(expectedCopy, resultCopy) | ||
end) | ||
end) | ||
|
||
describe("With testify_enabled=true", function() | ||
it("Discover namespaces, test methods and test function", function() | ||
-- Arrange | ||
local test_filepath = vim.loop.cwd() | ||
.. "/tests/go/testify/positions_test.go" | ||
options.set({ testify = true }) -- enable testify | ||
testify.lookup.generate() -- generate lookup | ||
|
||
local expected = { | ||
{ | ||
id = test_filepath, | ||
name = "positions_test.go", | ||
path = test_filepath, | ||
type = "file", | ||
}, | ||
{ | ||
{ | ||
id = test_filepath .. "::TestExampleTestSuite", | ||
name = "TestExampleTestSuite", | ||
path = test_filepath, | ||
type = "namespace", | ||
}, | ||
{ | ||
{ | ||
id = test_filepath .. "::TestExampleTestSuite::TestExample", | ||
name = "TestExample", | ||
path = test_filepath, | ||
type = "test", | ||
}, | ||
}, | ||
{ | ||
{ | ||
id = test_filepath .. "::TestExampleTestSuite::TestExample2", | ||
name = "TestExample2", | ||
path = test_filepath, | ||
type = "test", | ||
}, | ||
}, | ||
}, | ||
{ | ||
{ | ||
id = test_filepath .. "::ExampleTestSuite2", | ||
name = "ExampleTestSuite2", | ||
path = test_filepath, | ||
type = "namespace", | ||
}, | ||
{ | ||
{ | ||
id = test_filepath .. "::ExampleTestSuite2::TestExample", | ||
name = "TestExample", | ||
path = test_filepath, | ||
type = "test", | ||
}, | ||
}, | ||
{ | ||
{ | ||
id = test_filepath .. "::ExampleTestSuite2::TestExample2", | ||
name = "TestExample2", | ||
path = test_filepath, | ||
type = "test", | ||
}, | ||
}, | ||
}, | ||
{ | ||
{ | ||
id = test_filepath .. "::TestTrivial", | ||
name = "TestTrivial", | ||
path = test_filepath, | ||
type = "test", | ||
}, | ||
}, | ||
{ | ||
{ | ||
id = test_filepath .. "::TestOtherTestSuite", | ||
name = "TestOtherTestSuite", | ||
path = test_filepath, | ||
type = "namespace", | ||
}, | ||
{ | ||
{ | ||
id = test_filepath .. "::TestOtherTestSuite::TestOther", | ||
name = "TestOther", | ||
path = test_filepath, | ||
type = "test", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
-- Act | ||
---@type neotest.Tree | ||
local tree = | ||
nio.tests.with_async_context(adapter.discover_positions, test_filepath) | ||
|
||
-- Assert | ||
local result = tree:to_list() | ||
local ignoreKeys = { range = true } | ||
local expectedCopy, resultCopy = | ||
compareIgnoringKeys(expected, result, ignoreKeys) | ||
assert.are.same(vim.inspect(expectedCopy), vim.inspect(resultCopy)) | ||
assert.are.same(expectedCopy, resultCopy) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package testify | ||
|
||
// Basic imports | ||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
// Define the suite, and absorb the built-in basic suite | ||
// functionality from testify - including a T() method which | ||
// returns the current testing context | ||
type ExampleTestSuite struct { | ||
suite.Suite | ||
VariableThatShouldStartAtFive int | ||
} | ||
|
||
// Make sure that VariableThatShouldStartAtFive is set to five | ||
// before each test | ||
func (suite *ExampleTestSuite) SetupTest() { | ||
suite.VariableThatShouldStartAtFive = 5 | ||
} | ||
|
||
// All methods that begin with "Test" are run as tests within a | ||
// suite. | ||
func (suite *ExampleTestSuite) TestExample() { | ||
assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive) | ||
} | ||
|
||
func (suite *ExampleTestSuite) TestExample2() { | ||
assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive) | ||
} | ||
|
||
// In order for 'go test' to run this suite, we need to create | ||
// a normal test function and pass our suite to suite.Run | ||
func TestExampleTestSuite(t *testing.T) { | ||
suite.Run(t, new(ExampleTestSuite)) | ||
} | ||
|
||
// -------------------------------------------------------------------- | ||
|
||
type ExampleTestSuite2 struct { | ||
suite.Suite | ||
VariableThatShouldStartAtFive int | ||
} | ||
|
||
func (suite *ExampleTestSuite2) SetupTest() { | ||
suite.VariableThatShouldStartAtFive = 5 | ||
} | ||
|
||
func (suite *ExampleTestSuite2) TestExample() { | ||
assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive) | ||
} | ||
|
||
func (suite *ExampleTestSuite2) TestExample2() { | ||
assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive) | ||
} | ||
|
||
// -------------------------------------------------------------------- | ||
|
||
// Just a regular test. | ||
func TestTrivial(t *testing.T) { | ||
assert.Equal(t, 1, 1) | ||
} | ||
|
||
// -------------------------------------------------------------------- | ||
|
||
// A test method which uses a receiver type defined by struct in another file. | ||
func (suite *OtherTestSuite) TestOther() { | ||
assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.