Skip to content

Commit

Permalink
test: normalize path
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed Jan 21, 2025
1 parent e76af08 commit 57fe90a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/go/internal/positions/positions_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ local function compareIgnoringKeys(t1, t2, ignoreKeys)
return copyTable(t1, ignoreKeys), copyTable(t2, ignoreKeys)
end

local function normalize_windows_path(path)
return path:gsub("/", "\\")
end

describe("Discovery of test positions", function()
it("Discover OK", function()
-- Arrange
local test_filepath = vim.uv.cwd()
.. "/tests/go/internal/positions/positions_test.go"
if vim.fn.has("win32") == 1 then
test_filepath = normalize_windows_path(test_filepath)
end
local expected = {
{
id = test_filepath,
Expand Down
10 changes: 10 additions & 0 deletions tests/go/internal/testify/positions_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ local function compareIgnoringKeys(t1, t2, ignoreKeys)
return copyTable(t1, ignoreKeys), copyTable(t2, ignoreKeys)
end

local function normalize_windows_path(path)
return path:gsub("/", "\\")
end

describe("With testify_enabled=false", function()
it("Discover test functions", function()
-- Arrange
local test_filepath = vim.uv.cwd()
.. "/tests/go/internal/testify/positions_test.go"
if vim.fn.has("win32") == 1 then
test_filepath = normalize_windows_path(test_filepath)
end
local expected = {
{
id = test_filepath,
Expand Down Expand Up @@ -81,6 +88,9 @@ describe("With testify_enabled=true", function()
-- Arrange
local test_filepath = vim.uv.cwd()
.. "/tests/go/internal/testify/positions_test.go"
if vim.fn.has("win32") == 1 then
test_filepath = normalize_windows_path(test_filepath)
end
options.set({ testify_enabled = true }) -- enable testify
local filepaths = lib.find.go_test_filepaths(test_filepath)
testify.lookup.initialize_lookup(filepaths) -- generate lookup
Expand Down
12 changes: 12 additions & 0 deletions tests/go/lookup_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ local options = require("neotest-golang.options")
local lib = require("neotest-golang.lib")
local testify = require("neotest-golang.features.testify")

local function normalize_windows_path(path)
return path:gsub("/", "\\")
end

describe("Lookup", function()
it("Generates tree replacement instructions", function()
-- Arrange
options.set({ testify_enabled = true }) -- enable testify
local folderpath = vim.uv.cwd() .. "/tests/go"
if vim.fn.has("win32") == 1 then
folderpath = normalize_windows_path(folderpath)
end
local filepaths = lib.find.go_test_filepaths(vim.uv.cwd())
if vim.fn.has("win32") == 1 then
for i, filepath in ipairs(filepaths) do
filepaths[i] = normalize_windows_path(filepath)
end
end
local expected_lookup = {
[folderpath .. "/internal/operand/operand_test.go"] = {
package = "operand",
Expand Down

0 comments on commit 57fe90a

Please sign in to comment.