Skip to content

Commit d695a7b

Browse files
committed
feat(test): Added Windows support for running tests
1 parent 11e40d9 commit d695a7b

File tree

4 files changed

+133
-40
lines changed

4 files changed

+133
-40
lines changed

run_tests.ps1

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env pwsh
2+
$ErrorActionPreference = "Stop"
3+
4+
# Create required directories
5+
$dirs = @(
6+
".testenv/config/nvim",
7+
".testenv/data/nvim",
8+
".testenv/state/nvim",
9+
".testenv/run/nvim",
10+
".testenv/cache/nvim"
11+
)
12+
foreach ($dir in $dirs) {
13+
New-Item -ItemType Directory -Force -Path $dir | Out-Null
14+
}
15+
16+
# Plugin directory
17+
$PLUGINS = ".testenv/data/nvim-data/site/pack/plugins/start"
18+
19+
# Ensure plenary.nvim is present
20+
$plenaryPath = Join-Path $PLUGINS "plenary.nvim"
21+
if (-Not (Test-Path $plenaryPath)) {
22+
git clone --depth=1 https://github.com/nvim-lua/plenary.nvim.git $plenaryPath
23+
} else {
24+
Push-Location $plenaryPath
25+
git pull
26+
Pop-Location
27+
}
28+
29+
# Set environment variables
30+
$env:XDG_CONFIG_HOME = ".testenv/config"
31+
$env:XDG_DATA_HOME = ".testenv/data"
32+
$env:XDG_STATE_HOME = ".testenv/state"
33+
$env:XDG_RUNTIME_DIR = ".testenv/run"
34+
$env:XDG_CACHE_HOME = ".testenv/cache"
35+
36+
# Run Neovim tests
37+
$nvimArgs = @(
38+
"--headless",
39+
"-u", "./tests/minimal_init.lua",
40+
"-c", "PlenaryBustedDirectory $($args[0] ?? 'tests') { minimal_init = './tests/minimal_init.lua' }"
41+
)
42+
43+
nvim @nvimArgs
44+
45+
Write-Host "Success"
46+

tests/files_spec.lua

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require("plenary.async").tests.add_to_env()
22
local TmpDir = require("tests.tmpdir")
33
local files = require("oil.adapters.files")
4+
local fs = require("oil.fs")
45
local test_util = require("tests.test_util")
56

67
a.describe("files adapter", function()
@@ -15,13 +16,25 @@ a.describe("files adapter", function()
1516
test_util.reset_editor()
1617
end)
1718

18-
a.it("tmpdir creates files and asserts they exist", function()
19-
tmpdir:create({ "a.txt", "foo/b.txt", "foo/c.txt", "bar/" })
19+
a.it("tmpdir creates file and asserts it exists", function()
20+
tmpdir:create({ "a.txt" })
2021
tmpdir:assert_fs({
2122
["a.txt"] = "a.txt",
23+
})
24+
end)
25+
26+
a.it("tmpdir creates directory and asserts it exists", function()
27+
tmpdir:create({ "bar/" })
28+
tmpdir:assert_fs({
29+
["bar/"] = true,
30+
})
31+
end)
32+
33+
a.it("tmpdir creates directory and files and asserts they exist", function()
34+
tmpdir:create({ "foo/b.txt", "foo/c.txt" })
35+
tmpdir:assert_fs({
2236
["foo/b.txt"] = "foo/b.txt",
2337
["foo/c.txt"] = "foo/c.txt",
24-
["bar/"] = true,
2538
})
2639
end)
2740

@@ -147,16 +160,32 @@ a.describe("files adapter", function()
147160
})
148161
end)
149162

150-
a.it("Editing a new oil://path/ creates an oil buffer", function()
163+
a.it("Editing a new unnormalized oil://path/ creates an oil buffer", function()
151164
local tmpdir_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "/"
152165
vim.cmd.edit({ args = { tmpdir_url } })
153166
test_util.wait_oil_ready()
154-
local new_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "newdir"
155-
vim.cmd.edit({ args = { new_url } })
167+
local unnormalized_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "newdir"
168+
local normalized_url = "oil://"
169+
.. fs.os_to_posix_path(vim.fn.fnamemodify(tmpdir.path, ":p"))
170+
.. "newdir/"
171+
vim.cmd.edit({ args = { unnormalized_url } })
156172
test_util.wait_oil_ready()
157173
assert.equals("oil", vim.bo.filetype)
158174
-- The normalization will add a '/'
159-
assert.equals(new_url .. "/", vim.api.nvim_buf_get_name(0))
175+
assert.equals(normalized_url, vim.api.nvim_buf_get_name(0))
176+
end)
177+
178+
a.it("Editing a new normalized oil://path/ creates an oil buffer", function()
179+
local tmpdir_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "/"
180+
vim.cmd.edit({ args = { tmpdir_url } })
181+
test_util.wait_oil_ready()
182+
local new_url = "oil://"
183+
.. fs.os_to_posix_path(vim.fn.fnamemodify(tmpdir.path, ":p"))
184+
.. "newdir/"
185+
vim.cmd.edit({ args = { new_url } })
186+
test_util.wait_oil_ready()
187+
assert.equals("oil", vim.bo.filetype)
188+
assert.equals(new_url, vim.api.nvim_buf_get_name(0))
160189
end)
161190

162191
a.it("Editing a new oil://file.rb creates a normal buffer", function()

tests/tmpdir.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ end
4141
---@param paths string[]
4242
function TmpDir:create(paths)
4343
for _, path in ipairs(paths) do
44-
local pieces = vim.split(path, fs.sep)
44+
local pieces = vim.split(path, "[\\/]")
4545
local partial_path = self.path
4646
for i, piece in ipairs(pieces) do
4747
partial_path = fs.join(partial_path, piece)
48-
if i == #pieces and not vim.endswith(partial_path, fs.sep) then
48+
if
49+
i == #pieces
50+
and not vim.endswith(partial_path, "/")
51+
and not vim.endswith(partial_path, "\\")
52+
then
4953
await(touch, 2, partial_path)
5054
elseif not exists(partial_path) then
5155
vim.loop.fs_mkdir(partial_path, 493)
@@ -90,7 +94,7 @@ end
9094
local assert_fs = function(root, paths)
9195
local unlisted_dirs = {}
9296
for k in pairs(paths) do
93-
local pieces = vim.split(k, "/")
97+
local pieces = vim.split(k, "[/\\]")
9498
local partial_path = ""
9599
for i, piece in ipairs(pieces) do
96100
partial_path = partial_path .. piece .. "/"
@@ -110,11 +114,15 @@ local assert_fs = function(root, paths)
110114
if entry.type == "directory" then
111115
shortpath = shortpath .. "/"
112116
end
117+
shortpath = shortpath:gsub("\\", "/")
113118
local expected_content = paths[shortpath]
114119
paths[shortpath] = nil
115120
assert.truthy(expected_content, string.format("Unexpected entry '%s'", shortpath))
116121
if entry.type == "file" then
117122
local data = read_file(fullpath)
123+
if data ~= nil then
124+
data = data:gsub("\\", "/")
125+
end
118126
assert.equals(
119127
expected_content,
120128
data,

tests/url_spec.lua

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,49 @@ local util = require("oil.util")
44
local uv = vim.uv or vim.loop
55

66
describe("url", function()
7-
if not uv.os_uname().version:match("Windows") then
8-
--These tests rely on functions like vim.fn.getcwd and vim.loop.os_homedir
9-
--returning unix style paths so these test don't make sense to run on Windows
10-
it("get parent url for empty string path", function()
11-
local input = ""
12-
local expected = "oil://" .. util.addslash(vim.fn.getcwd())
7+
it("get parent url for empty string path", function()
8+
if uv.os_uname().version:match("Windows") then
9+
pending("Skipping this test on Windows because it relies on a unix styled current directory")
10+
return
11+
end
12+
local input = ""
13+
local expected = "oil://" .. util.addslash(vim.fn.getcwd())
1314

14-
local output, basename = oil.get_buffer_parent_url(input, true)
15-
assert.equals(expected, output, string.format('Parent url for path "%s" failed', input))
16-
assert.equals(nil, basename, string.format('Basename for path "%s" failed', input))
17-
end)
18-
19-
it("get parent url for term name", function()
20-
local input = "term://~/oil.nvim//52953:/bin/sh"
21-
local expected = "oil://" .. vim.loop.os_homedir() .. "/oil.nvim/"
22-
local output, basename = oil.get_buffer_parent_url(input, true)
23-
assert.equals(expected, output, string.format('Parent url for path "%s" failed', input))
24-
assert.equals(nil, basename, string.format('Basename for path "%s" failed', input))
25-
end)
15+
local output, basename = oil.get_buffer_parent_url(input, true)
16+
assert.equals(expected, output, string.format('Parent url for path "%s" failed', input))
17+
assert.equals(nil, basename, string.format('Basename for path "%s" failed', input))
18+
end)
2619

27-
it("get parent url for unix path", function()
28-
local input = "/foo/bar.txt"
29-
local expected = "oil:///foo/"
30-
local expected_basename = "bar.txt"
31-
local output, basename = oil.get_buffer_parent_url(input, true)
32-
assert.equals(expected, output, string.format('Parent url for path "%s" failed', input))
33-
assert.equals(
34-
expected_basename,
35-
basename,
36-
string.format('Basename for path "%s" failed', input)
20+
it("get parent url for term name", function()
21+
if uv.os_uname().version:match("Windows") then
22+
pending(
23+
"Skipping this test on Windows because it relies on a unix styled current home directory"
3724
)
38-
end)
39-
end
25+
return
26+
end
27+
local input = "term://~/oil.nvim//52953:/bin/sh"
28+
local expected = "oil://" .. vim.loop.os_homedir() .. "/oil.nvim/"
29+
local output, basename = oil.get_buffer_parent_url(input, true)
30+
assert.equals(expected, output, string.format('Parent url for path "%s" failed', input))
31+
assert.equals(nil, basename, string.format('Basename for path "%s" failed', input))
32+
end)
33+
34+
it("get parent url for unix path", function()
35+
if uv.os_uname().version:match("Windows") then
36+
pending("Skipping this test on Windows because it relies on a unix styled absolute path")
37+
return
38+
end
39+
local input = "/foo/bar.txt"
40+
local expected = "oil:///foo/"
41+
local expected_basename = "bar.txt"
42+
local output, basename = oil.get_buffer_parent_url(input, true)
43+
assert.equals(expected, output, string.format('Parent url for path "%s" failed', input))
44+
assert.equals(
45+
expected_basename,
46+
basename,
47+
string.format('Basename for path "%s" failed', input)
48+
)
49+
end)
4050

4151
it("get parent url for oil path", function()
4252
local input = "oil:///foo/bar.txt"

0 commit comments

Comments
 (0)