diff options
Diffstat (limited to 'test/unit/tempfile_spec.lua')
| -rw-r--r-- | test/unit/tempfile_spec.lua | 47 | 
1 files changed, 27 insertions, 20 deletions
| diff --git a/test/unit/tempfile_spec.lua b/test/unit/tempfile_spec.lua index cf0d78b7a7..c05abfd640 100644 --- a/test/unit/tempfile_spec.lua +++ b/test/unit/tempfile_spec.lua @@ -1,61 +1,68 @@ -local lfs = require 'lfs' -local helpers = require 'test.unit.helpers' +local lfs = require('lfs') +local helpers = require('test.unit.helpers')(after_each) +local itp = helpers.gen_itp(it) -local os = helpers.cimport './src/nvim/os/os.h' -local tempfile = helpers.cimport './src/nvim/fileio.h' +local eq = helpers.eq +local neq = helpers.neq +local cimport = helpers.cimport +local child_call_once = helpers.child_call_once +local child_cleanup_once = helpers.child_cleanup_once + +local lib = cimport('./src/nvim/os/os.h', './src/nvim/fileio.h')  describe('tempfile related functions', function()    before_each(function() -    tempfile.vim_deltempdir() -  end) -  after_each(function() -    tempfile.vim_deltempdir() +    local function vim_deltempdir() +      lib.vim_deltempdir() +    end +    child_call_once(vim_deltempdir) +    child_cleanup_once(vim_deltempdir)    end)    local vim_gettempdir = function() -    return helpers.ffi.string(tempfile.vim_gettempdir()) +    return helpers.ffi.string(lib.vim_gettempdir())    end    describe('vim_gettempdir', function() -    it('returns path to Neovim own temp directory', 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) +      eq(lib.os_file_is_writable(helpers.to_cstr(dir)), 2)        for entry in lfs.dir(dir) do          assert.True(entry == '.' or entry == '..')        end      end) -    it('returns the same directory on each call', function() +    itp('returns the same directory on each call', function()        local dir1 = vim_gettempdir()        local dir2 = vim_gettempdir() -      assert.equals(dir1, dir2) +      eq(dir1, dir2)      end)    end)    describe('vim_tempname', function()      local vim_tempname = function() -      return helpers.ffi.string(tempfile.vim_tempname()) +      return helpers.ffi.string(lib.vim_tempname())      end -    it('generate name of non-existing file', function() +    itp('generate name of non-existing file', function()        local file = vim_tempname()        assert.truthy(file) -      assert.False(os.os_path_exists(file)) +      assert.False(lib.os_path_exists(file))      end) -    it('generate different names on each call', function() +    itp('generate different names on each call', function()        local fst = vim_tempname()        local snd = vim_tempname() -      assert.not_equals(fst, snd) +      neq(fst, snd)      end) -    it('generate file name in Neovim own temp directory', function() +    itp('generate file name in Neovim own temp directory', function()        local dir = vim_gettempdir()        local file = vim_tempname() -      assert.truthy(file:find('^' .. dir .. '[^/]*$')) +      eq(string.sub(file, 1, string.len(dir)), dir)      end)    end)  end) | 
