aboutsummaryrefslogtreecommitdiff
path: root/test/lua_runner.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:40:31 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-29 22:40:31 +0000
commit339e2d15cc26fe86988ea06468d912a46c8d6f29 (patch)
treea6167fc8fcfc6ae2dc102f57b2473858eac34063 /test/lua_runner.lua
parent067dc73729267c0262438a6fdd66e586f8496946 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.gz
rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.tar.bz2
rneovim-339e2d15cc26fe86988ea06468d912a46c8d6f29.zip
Merge remote-tracking branch 'upstream/master' into fix_repeatcmdline
Diffstat (limited to 'test/lua_runner.lua')
-rw-r--r--test/lua_runner.lua83
1 files changed, 83 insertions, 0 deletions
diff --git a/test/lua_runner.lua b/test/lua_runner.lua
new file mode 100644
index 0000000000..686df9feec
--- /dev/null
+++ b/test/lua_runner.lua
@@ -0,0 +1,83 @@
+local platform = vim.uv.os_uname()
+local deps_install_dir = table.remove(_G.arg, 1)
+local subcommand = table.remove(_G.arg, 1)
+local suffix = (platform and platform.sysname:lower():find'windows') and '.dll' or '.so'
+package.path = deps_install_dir.."/share/lua/5.1/?.lua;"..deps_install_dir.."/share/lua/5.1/?/init.lua;"..package.path
+package.cpath = deps_install_dir.."/lib/lua/5.1/?"..suffix..";"..package.cpath;
+
+local uv = vim.uv
+
+-- we use busted and luacheck and their lua dependencies
+-- But installing their binary dependencies with luarocks is very
+-- slow, replace them with vim.uv wrappers
+
+local system = {}
+package.loaded['system.core'] = system
+function system.monotime()
+ uv.update_time()
+ return uv.now()*1e-3
+end
+function system.gettime()
+ local sec, usec = uv.gettimeofday()
+ return sec+usec*1e-6
+end
+function system.sleep(sec)
+ uv.sleep(sec*1e3)
+end
+
+local term = {}
+package.loaded['term.core'] = term
+function term.isatty(_)
+ return uv.guess_handle(1) == 'tty'
+end
+
+local lfs = {_VERSION = 'fake'}
+package.loaded['lfs'] = lfs
+
+function lfs.attributes(path, attr)
+ local stat = uv.fs_stat(path)
+ if attr == 'mode' then
+ return stat and stat.type or ''
+ elseif attr == 'modification' then
+ if not stat then return nil end
+ local mtime = stat.mtime
+ return mtime.sec + mtime.nsec*1e-9
+ else
+ error('not implemented')
+ end
+end
+
+function lfs.currentdir()
+ return uv.cwd()
+end
+
+function lfs.chdir(dir)
+ local status, err = pcall(uv.chdir, dir)
+ if status then
+ return true
+ else
+ return nil, err
+ end
+end
+
+function lfs.dir(path)
+ local fs = uv.fs_scandir(path)
+ return function()
+ if not fs then
+ return
+ end
+ return uv.fs_scandir_next(fs)
+ end
+end
+
+function lfs.mkdir(dir)
+ return uv.fs_mkdir(dir, 493) -- octal 755
+end
+
+if subcommand == "busted" then
+ require 'busted.runner'({ standalone = false })
+elseif subcommand == "luacheck" then
+ require 'luacheck.main'
+else
+ error 'unknown subcommand'
+end