preload.lua 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. -- Modules loaded here will NOT be cleared and reloaded by Busted.
  2. -- Busted started doing this to help provide more isolation. See issue #62
  3. -- for more information about this.
  4. local helpers = require('test.functional.helpers')(nil)
  5. local iswin = helpers.iswin
  6. local busted = require("busted")
  7. if iswin() then
  8. local ffi = require('ffi')
  9. ffi.cdef[[
  10. typedef int errno_t;
  11. errno_t _set_fmode(int mode);
  12. ]]
  13. ffi.C._set_fmode(0x8000)
  14. end
  15. local testid = (function()
  16. local id = 0
  17. return (function()
  18. id = id + 1
  19. return id
  20. end)
  21. end)()
  22. -- Global before_each. https://github.com/Olivine-Labs/busted/issues/613
  23. local function before_each(_element, _parent)
  24. local id = ('T%d'):format(testid())
  25. _G._nvim_test_id = id
  26. return nil, true
  27. end
  28. busted.subscribe({ 'test', 'start' },
  29. before_each,
  30. {
  31. -- Ensure our --helper is handled before --output (see busted/runner.lua).
  32. priority = 1,
  33. -- Don't generate a test-id for skipped tests. /shrug
  34. predicate = function (element, _, status)
  35. return not ((element.descriptor == 'pending' or status == 'pending'))
  36. end
  37. })