mirror of
https://github.com/neovim/neovim.git
synced 2026-01-04 10:26:42 +10:00
Used
sed -r -i -e '/ helpers =/ s/$/\nlocal itp = helpers.gen_itp(it)/; s/^(\s*)it\(/\1itp(/' test/unit/**/*_spec.lua
to alter all tests. Locally they all run fine now.
Reasoning:
1. General: state from one test should not affect other tests.
2. Local: travis build is failing with something which may be an output of
garbage collector. This should prevent state of the garbage collector from
interferring as well.
63 lines
1.8 KiB
Lua
63 lines
1.8 KiB
Lua
local lfs = require 'lfs'
|
|
local helpers = require 'test.unit.helpers'
|
|
local itp = helpers.gen_itp(it)
|
|
|
|
local os = helpers.cimport './src/nvim/os/os.h'
|
|
local tempfile = helpers.cimport './src/nvim/fileio.h'
|
|
|
|
describe('tempfile related functions', function()
|
|
before_each(function()
|
|
tempfile.vim_deltempdir()
|
|
end)
|
|
after_each(function()
|
|
tempfile.vim_deltempdir()
|
|
end)
|
|
|
|
local vim_gettempdir = function()
|
|
return helpers.ffi.string(tempfile.vim_gettempdir())
|
|
end
|
|
|
|
describe('vim_gettempdir', function()
|
|
itp('returns path to Neovim own temp directory', function()
|
|
local dir = vim_gettempdir()
|
|
assert.True(dir ~= nil and dir:len() > 0)
|
|
-- os_file_is_writable returns 2 for a directory which we have rights
|
|
-- to write into.
|
|
assert.equals(os.os_file_is_writable(helpers.to_cstr(dir)), 2)
|
|
for entry in lfs.dir(dir) do
|
|
assert.True(entry == '.' or entry == '..')
|
|
end
|
|
end)
|
|
|
|
itp('returns the same directory on each call', function()
|
|
local dir1 = vim_gettempdir()
|
|
local dir2 = vim_gettempdir()
|
|
assert.equals(dir1, dir2)
|
|
end)
|
|
end)
|
|
|
|
describe('vim_tempname', function()
|
|
local vim_tempname = function()
|
|
return helpers.ffi.string(tempfile.vim_tempname())
|
|
end
|
|
|
|
itp('generate name of non-existing file', function()
|
|
local file = vim_tempname()
|
|
assert.truthy(file)
|
|
assert.False(os.os_path_exists(file))
|
|
end)
|
|
|
|
itp('generate different names on each call', function()
|
|
local fst = vim_tempname()
|
|
local snd = vim_tempname()
|
|
assert.not_equals(fst, snd)
|
|
end)
|
|
|
|
itp('generate file name in Neovim own temp directory', function()
|
|
local dir = vim_gettempdir()
|
|
local file = vim_tempname()
|
|
assert.truthy(file:find('^' .. dir .. '[^/]*$'))
|
|
end)
|
|
end)
|
|
end)
|