test(harness): migrate away from magic globals

Problem:
The magic globals `it`, `describe`, etc., are more trouble than they are
worth.

- Hooking into `after_each` requires `getfenv()` hacks.
- They confuse luals/emmylua, because the top-level `.luarc.json` isn't
  merged with `test/.luarc.json` (apparently a luals limitation?)
- They totally defeat discoverability because the user just has to
  "know" about the various magic symbols.

So they harm DX, which means they serve no purpose at all.

Solution:
- Expose the test API from `testutil`, so tests can call `t.it()`,
  `t.describe()`, etc., in the conventional way.
- Drop `getfenv()` hacks.
- Drop the `setfenv()` injection in `load_chunk`.
- Drop `test/_meta.lua`.
This commit is contained in:
Justin M. Keyes
2026-07-20 17:16:51 +02:00
parent a71ee754ee
commit 6d8c8b18d5
535 changed files with 771 additions and 115 deletions

View File

@@ -2,6 +2,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, it, before_each = t.describe, t.it, t.before_each
local neq, eq, command = t.neq, t.eq, n.command
local clear = n.clear
local expect, eval = n.expect, n.eval

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
local eq = t.eq
local clear = n.clear
local fn = n.fn

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local eq = t.eq
local eval = n.eval
local feed = n.feed

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local eq = t.eq
local eval = n.eval
local api = n.api

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
local clear = n.clear
local eq = t.eq
local environ = n.fn.environ

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local clear = n.clear
local command = n.command
local eq = t.eq

View File

@@ -13,6 +13,8 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, it, before_each, setup, teardown, pending, finally =
t.describe, t.it, t.before_each, t.setup, t.teardown, t.pending, t.finally
local mkdir = t.mkdir
local pcall_err = t.pcall_err
local clear = n.clear

View File

@@ -1,6 +1,8 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each, setup, teardown, pending =
t.describe, t.it, t.before_each, t.setup, t.teardown, t.pending
local eq, clear, call, write_file, command = t.eq, n.clear, n.call, t.write_file, n.command
local eval, fn = n.eval, n.fn
local is_os = t.is_os

View File

@@ -2,6 +2,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, it, before_each = t.describe, t.it, t.before_each
local eq = t.eq
local eval = n.eval
local clear = n.clear

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local eq, clear, call = t.eq, n.clear, n.call
local command = n.command
local matches = t.matches

View File

@@ -1,6 +1,8 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each, setup, teardown =
t.describe, t.it, t.before_each, t.setup, t.teardown
local clear = n.clear
local eq = t.eq
local exec_lua = n.exec_lua

View File

@@ -8,6 +8,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local it, before_each = t.it, t.before_each
local clear = n.clear
local eval = n.eval
local matches = t.matches

View File

@@ -1,6 +1,8 @@
local n = require('test.functional.testnvim')()
local t = require('test.testutil')
local Screen = require('test.functional.ui.screen')
local describe, it, before_each = t.describe, t.it, t.before_each
local clear = n.clear
local exec = n.exec
local feed = n.feed

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local call = n.call
local clear = n.clear
local eq = t.eq

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
local clear, command, eval, eq = n.clear, n.command, n.eval, t.eq
local mkdir = t.mkdir

View File

@@ -2,6 +2,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, it, before_each, pending = t.describe, t.it, t.before_each, t.pending
local clear = n.clear
local connect = n.connect
local get_session = n.get_session

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local eq = t.eq
local ok = t.ok
local call = n.call

View File

@@ -2,6 +2,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, it, before_each = t.describe, t.it, t.before_each
local eq = t.eq
local pcall_err = t.pcall_err
local feed = n.feed

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, setup = t.describe, t.it, t.setup
local clear = n.clear
local fn = n.fn
local api = n.api

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each, pending = t.describe, t.it, t.before_each, t.pending
local clear, eval, eq = n.clear, n.eval, t.eq
local source = n.source

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local eq = t.eq
local clear = n.clear
local command = n.command

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local clear = n.clear
local eq = t.eq
local eval = n.eval

View File

@@ -2,6 +2,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, it, before_each = t.describe, t.it, t.before_each
local eq = t.eq
local pcall_err = t.pcall_err
local clear = n.clear

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, setup = t.describe, t.it, t.setup
local eq = t.eq
local eval = n.eval
local command = n.command

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
local assert_alive = n.assert_alive
local clear, command, write_file = n.clear, n.command, t.write_file

View File

@@ -1,4 +1,5 @@
local t = require('test.testutil')
local describe, it, setup = t.describe, t.it, t.setup
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
local command = n.command
local clear = n.clear
local api = n.api

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, setup = t.describe, t.it, t.setup
local eq = t.eq
local eval = n.eval
local clear = n.clear

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, setup = t.describe, t.it, t.setup
local clear = n.clear
local eq = t.eq
local pcall_err = t.pcall_err

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local clear, eq, ok = n.clear, t.eq, t.ok
local neq, command, fn = t.neq, n.command, n.fn
local matches = t.matches

View File

@@ -2,6 +2,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, it, before_each, setup = t.describe, t.it, t.before_each, t.setup
local clear, eq, neq = n.clear, t.eq, t.neq
local command, api, fn = n.command, n.api, n.fn
local tbl_deep_extend = vim.tbl_deep_extend

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local clear, eq, api = n.clear, t.eq, n.api
local command, fn = n.command, n.fn
local feed = n.feed

View File

@@ -2,6 +2,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, before_each, pending = t.describe, t.before_each, t.pending
local clear, eq, api = n.clear, t.eq, n.api
local command, fn = n.command, n.fn
local feed = n.feed

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local setpos = n.fn.setpos
local getpos = n.fn.getpos
local insert = n.insert

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, setup = t.describe, t.it, t.setup
local eq = t.eq
local NIL = vim.NIL
local eval = n.eval

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local command = n.command
local fn = n.fn
local clear = n.clear

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local clear = n.clear
local eq = t.eq
local exec = n.exec

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, setup = t.describe, t.it, t.setup
local clear = n.clear
local eq = t.eq
local command = n.command

View File

@@ -4,6 +4,8 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, it, before_each, after_each, pending, finally =
t.describe, t.it, t.before_each, t.after_each, t.pending, t.finally
local assert_alive = n.assert_alive
local testprg = n.testprg
local eq, call, clear, eval, feed_command, feed, api =

View File

@@ -2,6 +2,7 @@ local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local describe, it, before_each = t.describe, t.it, t.before_each
local feed, eq, eval, ok = n.feed, t.eq, n.eval, t.ok
local source, async_meths, run = n.source, n.async_meths, n.run
local clear, command, fn = n.clear, n.command, n.fn

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, setup = t.describe, t.it, t.setup
local eq = t.eq
local clear = n.clear
local command = n.command

View File

@@ -1,4 +1,5 @@
local t = require('test.testutil')
local describe, it, before_each = t.describe, t.it, t.before_each
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each = t.describe, t.it, t.before_each
local call = n.call
local clear = n.clear
local command = n.command

View File

@@ -1,6 +1,7 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
local mkdir = t.mkdir
local clear = n.clear
local eq = t.eq