Skip to content

Commit 104822f

Browse files
committed
feat(test): Added Windows support for running tests
1 parent f15f9cc commit 104822f

File tree

4 files changed

+94
-10
lines changed

4 files changed

+94
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ __pycache__
4444

4545
.direnv/
4646
.testenv/
47+
oil_test_*/
4748
venv/
4849
doc/tags
4950
scripts/nvim_doc_tools

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,

0 commit comments

Comments
 (0)