Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add macos and windows and more robust scandir tests #74

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 54 additions & 8 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,43 @@ name: default
on: [push, pull_request]

jobs:
x64-ubuntu:
name: X64-ubuntu
runs-on: ubuntu-20.04
native:
name: native
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macos-10.15]
include:
- os: ubuntu-20.04
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz
manager: sudo apt
packages: fd-find
- os: macos-10.15
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-macos.tar.gz
manager: brew
packages: fd
steps:
- uses: actions/checkout@v2
- run: date +%F > todays-date
- name: Restore cache for today's nightly.
uses: actions/cache@v2
with:
path: _neovim
key: ${{ runner.os }}-x64-${{ hashFiles('todays-date') }}
key: ${{ matrix.os }}-${{ hashFiles('todays-date') }}

- name: Prepare
run: |
${{ matrix.manager }} install ${{ matrix.packages }}
test -d _neovim || {
mkdir -p _neovim
curl -sL ${{ matrix.url }} | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
}

- name: Run tests
run: |
curl -OL https://raw.githubusercontent.com/norcalli/bot-ci/master/scripts/github-actions-setup.sh
source github-actions-setup.sh nightly-x64
export PATH="${PWD}/_neovim/bin:${PATH}"
export VIM="${PWD}/_neovim/share/nvim/runtime"
nvim --version
make test

appimage-ubuntu:
Expand All @@ -35,6 +56,7 @@ jobs:

- name: Prepare
run: |
sudo apt install fd-find
test -d build || {
mkdir -p build
wget https://github.com/neovim/neovim/releases/download/nightly/nvim.appimage
Expand All @@ -44,5 +66,29 @@ jobs:

- name: Run tests
run: |
export PATH="${PWD}/build/:${PATH}"
make test
export PATH="${PWD}/build/:${PATH}"
make test

windows:
name: Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v2

# TODO(conni2461): Cache
- name: Prepare
run: |
curl -sL https://github.com/neovim/neovim/releases/download/nightly/nvim-win64.zip --output nvim-win64.zip
unzip nvim-win64.zip
rm nvim-win64.zip

curl -sL https://github.com/sharkdp/fd/releases/download/v8.2.1/fd-v8.2.1-x86_64-pc-windows-msvc.zip --output fd.zip
unzip fd.zip
rm fd.zip

- name: Run tests
run: |
$env:Path += ";Neovim/bin/;Fd/"
nvim --version
# nvim --headless --noplugin -u scripts/minimal.vim -c "PlenaryBustedFile tests/plenary/simple_busted_spec.lua"
make test
4 changes: 2 additions & 2 deletions lua/plenary/scandir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ end
local process_item = function(opts, name, typ, current_dir, next_dir, bp, data, giti, msp)
if opts.hidden or name:sub(1, 1) ~= '.' then
if typ == 'directory' then
local entry = current_dir .. '/' .. name
local entry = current_dir .. os_sep .. name
if opts.depth then
table.insert(next_dir, handle_depth(bp, entry, opts.depth))
else
Expand All @@ -85,7 +85,7 @@ local process_item = function(opts, name, typ, current_dir, next_dir, bp, data,
end
end
else
local entry = current_dir .. '/' .. name
local entry = current_dir .. os_sep .. name
if not giti or interpret_gitignore(giti, bp, entry) then
if not msp or msp(entry) then
table.insert(data, entry)
Expand Down
24 changes: 18 additions & 6 deletions lua/plenary/test_harness.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
local Path = require("plenary.path")
local Job = require("plenary.job")
local scan = require("plenary.scandir")

local f = require("plenary.functional")
local log = require("plenary.log")
local win_float = require("plenary.window.float")

local headless = require("plenary.nvim_meta").is_headless
local os_sep = Path.path.sep
local is_windows = os_sep == '\\'

local harness = {}

Expand All @@ -31,6 +34,11 @@ end)
function harness.test_directory_command(command)
local split_string = vim.split(command, " ")
local directory = table.remove(split_string, 1)
if is_windows then
for k, v in ipairs(split_string) do
split_string[k] = v:gsub('\\', '\\\\')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First we need to do that because we fail because of some escape char. So we do that and afterwards we move back to /

end
end

local opts = assert(loadstring('return ' .. table.concat(split_string, " ")))()

Expand Down Expand Up @@ -81,6 +89,12 @@ function harness.test_directory(directory, opts)
table.insert(args, '-u')
table.insert(args, opts.minimal_init)
end
-- PLEASE SOMEONE TELL ME WHY WE NEED TO DO THAT?!?
if is_windows then
for k, v in ipairs(args) do
args[k] = v:gsub('\\', '/')
end
end

return Job:new {
command = 'nvim',
Expand Down Expand Up @@ -140,12 +154,10 @@ function harness.test_directory(directory, opts)
end

function harness._find_files_to_run(directory)
local finder = Job:new {
command = 'find',
args = {directory, '-type', 'f', '-name', '*_spec.lua'},
}

return f.map(Path.new, finder:sync())
if directory:sub(#directory, -1) == os_sep then
directory = directory:sub(1, -2)
end
return f.map(Path.new, scan.scan_dir(directory, { search_pattern = '.*%_spec%.lua' }))
end

function harness._run_path(test_type, directory)
Expand Down
5 changes: 5 additions & 0 deletions tests/plenary/curl_spec.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
local curl = require('plenary.curl')

local os_sep = require'plenary.path'.path.sep

local eq = assert.are.same
local incl = function(p, s)
return (nil ~= string.find(s, p))
end

describe('CURL Wrapper:', function()
-- TODO(conni2461): Doesn't run on windows dunno why
if os_sep == '\\' then return end

describe('request', function() -----------------------------------------------

Expand Down
73 changes: 34 additions & 39 deletions tests/plenary/job_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ local has_all_executables = function(execs)
return true
end

local contains = function(a, b)
local found = 0
for _, v in ipairs(a) do
for _, w in ipairs(b) do
if v == w then found = found + 1 end
end
end
return found == #b
end

describe('Job', function()
describe('> cat manually >', function()
it('should split simple stdin', function()
Expand Down Expand Up @@ -106,7 +116,7 @@ describe('Job', function()

job:sync()

assert.are.same(job:result(), { 'A=100' })
assert.are.same(true, contains(job:result(), { 'A=100' }))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows doesn't get a clean env. Or maybe it is a clean env but windows needs like 100 env vars to even function 🤣 Idk we just check that it contains now. Doesn't matter

assert.are.same(job:result(), results)
end)

Expand All @@ -122,7 +132,7 @@ describe('Job', function()

job:sync()

assert.are.same(job:result(), { 'A=100', 'B=test' })
assert.are.same(true, contains(job:result(), { 'A=100', 'B=test' }))
assert.are.same(job:result(), results)
end)

Expand All @@ -138,7 +148,7 @@ describe('Job', function()

job:sync()

assert.are.same(job:result(), { 'A=100' })
assert.are.same(true, contains(job:result(), { 'A=100' }))
assert.are.same(job:result(), results)
end)

Expand All @@ -154,7 +164,7 @@ describe('Job', function()

job:sync()

assert.are.same(job:result(), { 'A=This is a long env var' })
assert.are.same(true, contains(job:result(), { 'A=This is a long env var' }))
assert.are.same(job:result(), results)
end)

Expand All @@ -170,7 +180,7 @@ describe('Job', function()

job:sync()

assert.are.same(job:result(), { 'A=This is a long env var' })
assert.are.same(true, contains(job:result(), { 'A=This is a long env var' }))
assert.are.same(job:result(), results)
end)

Expand All @@ -186,15 +196,7 @@ describe('Job', function()

job:sync()

local expected = { 'A=100', 'B=test' }
local found = { false, false }
for k, v in ipairs(job:result()) do
for _, w in ipairs(expected) do
if v == w then found[k] = true end
end
end

assert.are.same({ true, true }, found)
assert.are.same(true, contains(job:result(), { 'A=100', 'B=test' }))
assert.are.same(job:result(), results)
end)

Expand All @@ -210,15 +212,7 @@ describe('Job', function()

job:sync()

local expected = { 'A=100', 'B=test' }
local found = { false, false }
for k, v in ipairs(job:result()) do
for _, w in ipairs(expected) do
if v == w then found[k] = true end
end
end

assert.are.same({ true, true }, found)
assert.are.same(true, contains(job:result(), { 'A=100', 'B=test' }))
assert.are.same(job:result(), results)
end)
end)
Expand All @@ -237,11 +231,12 @@ describe('Job', function()
end)

it('should match larger systemlist', function()
local results = vim.fn.systemlist('find')
local results = vim.fn.systemlist('find .')
local stdout_results = {}

local job = Job:new {
command = 'find',
args = { '.' },

on_stdout = function(_, line) table.insert(stdout_results, line) end
}
Expand Down Expand Up @@ -303,11 +298,11 @@ describe('Job', function()
third_job:wait()
fourth_job:wait()

assert.are.same({'a=1', 'b=2', 'c=3'}, results)
assert.are.same({'a=1'}, first_job:result())
assert.are.same({'b=2'}, second_job:result())
assert.are.same(true, contains(results, { 'a=1', 'b=2', 'c=3' }))
assert.are.same(true, contains(first_job:result(), { 'a=1' }))
assert.are.same(true, contains(second_job:result(), { 'b=2' }))
assert.are.same(1, third_job.code)
assert.are.same({'c=3'}, fourth_job:result())
assert.are.same(true, contains(fourth_job:result(), { 'c=3' }))
end)

it('should only run the next job on success when using and_then_on_success', function()
Expand Down Expand Up @@ -341,9 +336,9 @@ describe('Job', function()
second_job:wait()
third_job:wait()

assert.are.same({'a=1', 'b=2'}, results)
assert.are.same({'a=1'}, first_job:result())
assert.are.same({'b=2'}, second_job:result())
assert.are.same(true, contains(results, { 'a=1', 'b=2' }))
assert.are.same(true, contains(first_job:result(), { 'a=1' }))
assert.are.same(true, contains(second_job:result(), { 'b=2' }))
assert.are.same(1, third_job.code)
assert.are.same(nil, fourth_job.handle, "Job never started")
end)
Expand Down Expand Up @@ -375,8 +370,8 @@ describe('Job', function()

assert.are.same(1, first_job.code)
assert.are.same(1, ret)
assert.are.same({'a=1'}, results)
assert.are.same({'a=1'}, second_job:result())
assert.are.same(true, contains(results, { 'a=1' }))
assert.are.same(true, contains(second_job:result(), { 'a=1' }))
assert.are.same(nil, third_job.handle, "Job never started")
end)

Expand All @@ -399,8 +394,8 @@ describe('Job', function()
first_job:sync()
second_job:wait()

assert.are.same({'a=1'}, results)
assert.are.same({'a=1'}, first_job:result())
assert.are.same(true, contains(results, { 'a=1' }))
assert.are.same(true, contains(first_job:result(), { 'a=1' }))
assert.are.same(1, second_job.code)
assert.are.same(11, code)
end)
Expand All @@ -426,8 +421,8 @@ describe('Job', function()
first_job:sync()
second_job:wait()

assert.are.same({'a=1'}, results)
assert.are.same({'a=1'}, first_job:result())
assert.are.same(true, contains(results, { 'a=1' }))
assert.are.same(true, contains(first_job:result(), { 'a=1' }))
assert.are.same(1, second_job.code)
assert.are.same(10, code)
assert.are.same(nil, third_job.handle)
Expand Down Expand Up @@ -455,8 +450,8 @@ describe('Job', function()
local _, ret = first_job:sync()
second_job:wait()

assert.are.same({'a=1'}, results)
assert.are.same({'a=1'}, second_job:result())
assert.are.same(true, contains(results, { 'a=1' }))
assert.are.same(true, contains(second_job:result(), { 'a=1' }))
assert.are.same(1, ret)
assert.are.same(1, first_job.code)
assert.are.same(1, code)
Expand Down
Loading