From bc15b075d14c85098d674a2466d2386e08b0005f Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 1 Mar 2023 10:51:22 -0600 Subject: feat(vim.fs): pass path to find() predicate, lazy evaluate #22378 Problem: No easy way to find files under certain directories (ex: grab all files under `test/`) or exclude the content of certain paths (ex. `build/`, `.git/`) Solution: Pass the full `path` as an arg to the predicate. --- test/functional/lua/fs_spec.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/functional/lua/fs_spec.lua') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 642d36f63a..03de16c079 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -8,6 +8,7 @@ local mkdir_p = helpers.mkdir_p local rmdir = helpers.rmdir local nvim_dir = helpers.nvim_dir local test_build_dir = helpers.test_build_dir +local test_source_path = helpers.test_source_path local nvim_prog = helpers.nvim_prog local is_os = helpers.is_os @@ -252,6 +253,16 @@ describe('vim.fs', function() local opts = { path = dir, upward = true, type = 'directory' } return vim.fs.find(function(x) return x == 'no-match' end, opts) ]], nvim_dir)) + eq( + exec_lua([[ + local dir = ... + return vim.tbl_map(vim.fs.basename, vim.fn.glob(dir..'/contrib/*', false, true)) + ]], test_source_path), + exec_lua([[ + local dir = ... + local opts = { path = dir, limit = math.huge } + return vim.tbl_map(vim.fs.basename, vim.fs.find(function(_, d) return d:match('[\\/]contrib$') end, opts)) + ]], test_source_path)) end) end) -- cgit From ba38f35d3e2f37c2289543e6e0c4451c679c5834 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 5 Mar 2023 11:21:37 +0100 Subject: test: don't search entire repo for files Searching the entire repo for a directory named "contrib" causes failure if there happens to be another subdirectory with the name "contrib". Instead, point directly to the correct contrib directory. --- test/functional/lua/fs_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/lua/fs_spec.lua') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 03de16c079..da60b5c13b 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -260,7 +260,7 @@ describe('vim.fs', function() ]], test_source_path), exec_lua([[ local dir = ... - local opts = { path = dir, limit = math.huge } + local opts = { path = dir .. "/contrib", limit = math.huge } return vim.tbl_map(vim.fs.basename, vim.fs.find(function(_, d) return d:match('[\\/]contrib$') end, opts)) ]], test_source_path)) end) -- cgit From 743860de40502227b3f0ed64317eb937d24d4a36 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 4 Apr 2023 21:59:06 +0200 Subject: test: replace lfs with luv and vim.fs test: replace lfs with luv luv already pretty much does everything lfs does, so this duplication of dependencies isn't needed. --- test/functional/lua/fs_spec.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/functional/lua/fs_spec.lua') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index da60b5c13b..aeb2e5d9a6 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -1,5 +1,4 @@ local helpers = require('test.functional.helpers')(after_each) -local lfs = require('lfs') local clear = helpers.clear local exec_lua = helpers.exec_lua @@ -11,6 +10,7 @@ local test_build_dir = helpers.test_build_dir local test_source_path = helpers.test_source_path local nvim_prog = helpers.nvim_prog local is_os = helpers.is_os +local mkdir = helpers.mkdir local nvim_prog_basename = is_os('win') and 'nvim.exe' or 'nvim' @@ -133,10 +133,10 @@ describe('vim.fs', function() describe('dir()', function() before_each(function() - lfs.mkdir('testd') - lfs.mkdir('testd/a') - lfs.mkdir('testd/a/b') - lfs.mkdir('testd/a/b/c') + mkdir('testd') + mkdir('testd/a') + mkdir('testd/a/b') + mkdir('testd/a/b/c') end) after_each(function() -- cgit From fd32a987520cb132455d61301467182cb58cddf2 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 5 Apr 2023 23:56:33 +0200 Subject: test(vim.fs.normalize): enable test on Windows --- test/functional/lua/fs_spec.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'test/functional/lua/fs_spec.lua') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index aeb2e5d9a6..2fcbc9450f 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -271,10 +271,11 @@ describe('vim.fs', function() eq('C:/Users/jdoe', exec_lua [[ return vim.fs.normalize('C:\\Users\\jdoe') ]]) end) it('works with ~', function() - if is_os('win') then - pending([[$HOME does not exist on Windows ¯\_(ツ)_/¯]]) - end - eq(os.getenv('HOME') .. '/src/foo', exec_lua [[ return vim.fs.normalize('~/src/foo') ]]) + eq( exec_lua([[ + local home = ... + return home .. '/src/foo' + ]], is_os('win') and vim.fs.normalize(os.getenv('USERPROFILE')) or os.getenv('HOME') + ) , exec_lua [[ return vim.fs.normalize('~/src/foo') ]]) end) it('works with environment variables', function() local xdg_config_home = test_build_dir .. '/.config' -- cgit From 826b95203ac9c8decf02e332fbb55cf4ebf73aef Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Thu, 18 May 2023 16:27:47 +0200 Subject: build: bundle uncrustify Uncrustify is sensitive to version changes, which causes friction for contributors that doesn't have that exact version. It's also simpler to download and install the correct version than to have bespoke version checking. --- test/functional/lua/fs_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/lua/fs_spec.lua') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 2fcbc9450f..f646e676c6 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -223,7 +223,7 @@ describe('vim.fs', function() describe('find()', function() it('works', function() - eq({test_build_dir}, exec_lua([[ + eq({test_build_dir .. "/build"}, exec_lua([[ local dir = ... return vim.fs.find('build', { path = dir, upward = true, type = 'directory' }) ]], nvim_dir)) @@ -239,7 +239,7 @@ describe('vim.fs', function() end) it('accepts predicate as names', function() - eq({test_build_dir}, exec_lua([[ + eq({test_build_dir .. "/build"}, exec_lua([[ local dir = ... local opts = { path = dir, upward = true, type = 'directory' } return vim.fs.find(function(x) return x == 'build' end, opts) -- cgit From e3e6fadfd82861471c32fdcabe00bbef3de84563 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 20 May 2023 17:30:48 +0200 Subject: feat(fs): expose join_paths as `vim.fs.joinpath` (#23685) This is a small function but used a lot in some plugins. --- test/functional/lua/fs_spec.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test/functional/lua/fs_spec.lua') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index f646e676c6..aae0ed91a7 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -266,6 +266,17 @@ describe('vim.fs', function() end) end) + describe('joinpath()', function() + it('works', function() + eq('foo/bar/baz', exec_lua([[ + return vim.fs.joinpath('foo', 'bar', 'baz') + ]], nvim_dir)) + eq('foo/bar/baz', exec_lua([[ + return vim.fs.joinpath('foo', '/bar/', '/baz') + ]], nvim_dir)) + end) + end) + describe('normalize()', function() it('works with backward slashes', function() eq('C:/Users/jdoe', exec_lua [[ return vim.fs.normalize('C:\\Users\\jdoe') ]]) -- cgit From 8a7e3353eb5bffb10015254917361266b4b20511 Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Sun, 18 Jun 2023 14:49:33 +0300 Subject: fix(fs): make `normalize()` work with '/' path (#24047) Problem: Current implementation of "remove trailing /" doesn't account for the case of literal '/' as path. Solution: Remove trailing / only if it preceded by something else. Co-authored by: notomo --- test/functional/lua/fs_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/lua/fs_spec.lua') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index aae0ed91a7..c1091cff60 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -281,6 +281,12 @@ describe('vim.fs', function() it('works with backward slashes', function() eq('C:/Users/jdoe', exec_lua [[ return vim.fs.normalize('C:\\Users\\jdoe') ]]) end) + it('removes trailing /', function() + eq('/home/user', exec_lua [[ return vim.fs.normalize('/home/user/') ]]) + end) + it('works with /', function() + eq('/', exec_lua [[ return vim.fs.normalize('/') ]]) + end) it('works with ~', function() eq( exec_lua([[ local home = ... -- cgit From e4da418ba8388e94bb186e3f9a2004ee1e96f1e5 Mon Sep 17 00:00:00 2001 From: Mike <4576770+mike325@users.noreply.github.com> Date: Tue, 18 Jul 2023 08:36:04 +0200 Subject: fix(fs.lua): normalize slash truncation (#23753) Preserve last slash in windows' root drive directories --- test/functional/lua/fs_spec.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/functional/lua/fs_spec.lua') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index c1091cff60..2c7b3ff324 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -301,5 +301,10 @@ describe('vim.fs', function() return vim.fs.normalize('$XDG_CONFIG_HOME/nvim') ]], xdg_config_home)) end) + if is_os('win') then + it('Last slash is not truncated from root drive', function() + eq('C:/', exec_lua [[ return vim.fs.normalize('C:/') ]]) + end) + end end) end) -- cgit From 2d9e7a33f41c842521c74d45927cfcb1874c711b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 15 Sep 2023 10:33:26 +0200 Subject: test(windows): unskip working tests (#25153) Also simplify home detection with os_homedir() --- test/functional/lua/fs_spec.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'test/functional/lua/fs_spec.lua') diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 2c7b3ff324..6bdb9ed79d 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -1,4 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) +local uv = require('luv') local clear = helpers.clear local exec_lua = helpers.exec_lua @@ -288,11 +289,12 @@ describe('vim.fs', function() eq('/', exec_lua [[ return vim.fs.normalize('/') ]]) end) it('works with ~', function() - eq( exec_lua([[ - local home = ... - return home .. '/src/foo' - ]], is_os('win') and vim.fs.normalize(os.getenv('USERPROFILE')) or os.getenv('HOME') - ) , exec_lua [[ return vim.fs.normalize('~/src/foo') ]]) + eq( + exec_lua([[ + local home = ... + return home .. '/src/foo' + ]], vim.fs.normalize(uv.os_homedir())), + exec_lua [[ return vim.fs.normalize('~/src/foo') ]]) end) it('works with environment variables', function() local xdg_config_home = test_build_dir .. '/.config' -- cgit