mirror of
https://github.com/neovim/neovim.git
synced 2026-02-18 17:38:32 +00:00
unittests: Run all unit tests in their own processes
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.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
local lfs = require('lfs')
|
||||
local helpers = require('test.unit.helpers')
|
||||
local itp = helpers.gen_itp(it)
|
||||
|
||||
local cimport = helpers.cimport
|
||||
local eq = helpers.eq
|
||||
@@ -45,7 +46,7 @@ describe('path function', function()
|
||||
buffer = cstr(length, '')
|
||||
end)
|
||||
|
||||
it('returns the absolute directory name of a given relative one', function()
|
||||
itp('returns the absolute directory name of a given relative one', function()
|
||||
local result = path_full_dir_name('..', buffer, length)
|
||||
eq(OK, result)
|
||||
local old_dir = lfs.currentdir()
|
||||
@@ -55,16 +56,16 @@ describe('path function', function()
|
||||
eq(expected, (ffi.string(buffer)))
|
||||
end)
|
||||
|
||||
it('returns the current directory name if the given string is empty', function()
|
||||
itp('returns the current directory name if the given string is empty', function()
|
||||
eq(OK, (path_full_dir_name('', buffer, length)))
|
||||
eq(lfs.currentdir(), (ffi.string(buffer)))
|
||||
end)
|
||||
|
||||
it('fails if the given directory does not exist', function()
|
||||
itp('fails if the given directory does not exist', function()
|
||||
eq(FAIL, path_full_dir_name('does_not_exist', buffer, length))
|
||||
end)
|
||||
|
||||
it('works with a normal relative dir', function()
|
||||
itp('works with a normal relative dir', function()
|
||||
local result = path_full_dir_name('unit-test-directory', buffer, length)
|
||||
eq(lfs.currentdir() .. '/unit-test-directory', (ffi.string(buffer)))
|
||||
eq(OK, result)
|
||||
@@ -91,24 +92,24 @@ describe('path function', function()
|
||||
os.remove(f2)
|
||||
end)
|
||||
|
||||
it('returns kEqualFiles when passed the same file', function()
|
||||
itp('returns kEqualFiles when passed the same file', function()
|
||||
eq(kEqualFiles, (path_full_compare(f1, f1)))
|
||||
end)
|
||||
|
||||
it('returns kEqualFileNames when files that dont exist and have same name', function()
|
||||
itp('returns kEqualFileNames when files that dont exist and have same name', function()
|
||||
eq(kEqualFileNames, (path_full_compare('null.txt', 'null.txt', true)))
|
||||
end)
|
||||
|
||||
it('returns kBothFilesMissing when files that dont exist', function()
|
||||
itp('returns kBothFilesMissing when files that dont exist', function()
|
||||
eq(kBothFilesMissing, (path_full_compare('null.txt', 'null.txt')))
|
||||
end)
|
||||
|
||||
it('returns kDifferentFiles when passed different files', function()
|
||||
itp('returns kDifferentFiles when passed different files', function()
|
||||
eq(kDifferentFiles, (path_full_compare(f1, f2)))
|
||||
eq(kDifferentFiles, (path_full_compare(f2, f1)))
|
||||
end)
|
||||
|
||||
it('returns kOneFileMissing if only one does not exist', function()
|
||||
itp('returns kOneFileMissing if only one does not exist', function()
|
||||
eq(kOneFileMissing, (path_full_compare(f1, 'null.txt')))
|
||||
eq(kOneFileMissing, (path_full_compare('null.txt', f1)))
|
||||
end)
|
||||
@@ -121,11 +122,11 @@ describe('path function', function()
|
||||
return ffi.string(res)
|
||||
end
|
||||
|
||||
it('returns the tail of a given file path', function()
|
||||
itp('returns the tail of a given file path', function()
|
||||
eq('file.txt', path_tail('directory/file.txt'))
|
||||
end)
|
||||
|
||||
it('returns an empty string if file ends in a slash', function()
|
||||
itp('returns an empty string if file ends in a slash', function()
|
||||
eq('', path_tail('directory/'))
|
||||
end)
|
||||
end)
|
||||
@@ -137,24 +138,24 @@ describe('path function', function()
|
||||
return ffi.string(res)
|
||||
end
|
||||
|
||||
it('returns the tail of a file together with its separator', function()
|
||||
itp('returns the tail of a file together with its separator', function()
|
||||
eq('///file.txt', path_tail_with_sep('directory///file.txt'))
|
||||
end)
|
||||
|
||||
it('returns an empty string when given an empty file name', function()
|
||||
itp('returns an empty string when given an empty file name', function()
|
||||
eq('', path_tail_with_sep(''))
|
||||
end)
|
||||
|
||||
it('returns only the separator if there is a trailing separator', function()
|
||||
itp('returns only the separator if there is a trailing separator', function()
|
||||
eq('/', path_tail_with_sep('some/directory/'))
|
||||
end)
|
||||
|
||||
it('cuts a leading separator', function()
|
||||
itp('cuts a leading separator', function()
|
||||
eq('file.txt', path_tail_with_sep('/file.txt'))
|
||||
eq('', path_tail_with_sep('/'))
|
||||
end)
|
||||
|
||||
it('returns the whole file name if there is no separator', function()
|
||||
itp('returns the whole file name if there is no separator', function()
|
||||
eq('file.txt', path_tail_with_sep('file.txt'))
|
||||
end)
|
||||
end)
|
||||
@@ -180,13 +181,13 @@ describe('path function', function()
|
||||
return eq(0, (ffi.C.strncmp((to_cstr(base)), pinvk, len)))
|
||||
end
|
||||
|
||||
it('returns the executable name of an invocation given a relative invocation', function()
|
||||
itp('returns the executable name of an invocation given a relative invocation', function()
|
||||
local invk, len = invocation_path_tail('directory/exe a b c')
|
||||
compare("exe a b c", invk, len)
|
||||
eq(3, len)
|
||||
end)
|
||||
|
||||
it('returns the executable name of an invocation given an absolute invocation', function()
|
||||
itp('returns the executable name of an invocation given an absolute invocation', function()
|
||||
if ffi.os == 'Windows' then
|
||||
local invk, len = invocation_path_tail('C:\\Users\\anyone\\Program Files\\z a b')
|
||||
compare('z a b', invk, len)
|
||||
@@ -198,18 +199,18 @@ describe('path function', function()
|
||||
end
|
||||
end)
|
||||
|
||||
it('does not count arguments to the executable as part of its path', function()
|
||||
itp('does not count arguments to the executable as part of its path', function()
|
||||
local invk, len = invocation_path_tail('exe a/b\\c')
|
||||
compare("exe a/b\\c", invk, len)
|
||||
eq(3, len)
|
||||
end)
|
||||
|
||||
it('only accepts whitespace as a terminator for the executable name', function()
|
||||
itp('only accepts whitespace as a terminator for the executable name', function()
|
||||
local invk, _ = invocation_path_tail('exe-a+b_c[]()|#!@$%^&*')
|
||||
eq('exe-a+b_c[]()|#!@$%^&*', (ffi.string(invk)))
|
||||
end)
|
||||
|
||||
it('is equivalent to path_tail when args do not contain a path separator', function()
|
||||
itp('is equivalent to path_tail when args do not contain a path separator', function()
|
||||
local ptail = path.path_tail(to_cstr("a/b/c x y z"))
|
||||
neq(NULL, ptail)
|
||||
local tail = ffi.string(ptail)
|
||||
@@ -217,7 +218,7 @@ describe('path function', function()
|
||||
eq(tail, ffi.string(invk))
|
||||
end)
|
||||
|
||||
it('is not equivalent to path_tail when args contain a path separator', function()
|
||||
itp('is not equivalent to path_tail when args contain a path separator', function()
|
||||
local ptail = path.path_tail(to_cstr("a/b/c x y/z"))
|
||||
neq(NULL, ptail)
|
||||
local invk, _ = invocation_path_tail("a/b/c x y/z")
|
||||
@@ -232,34 +233,34 @@ describe('path function', function()
|
||||
return ffi.string(res)
|
||||
end
|
||||
|
||||
it('returns', function()
|
||||
itp('returns', function()
|
||||
eq('directory/file.txt', path_next_component('some/directory/file.txt'))
|
||||
end)
|
||||
|
||||
it('returns empty string if given file contains no separator', function()
|
||||
itp('returns empty string if given file contains no separator', function()
|
||||
eq('', path_next_component('file.txt'))
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('path_shorten_fname', function()
|
||||
it('returns NULL if `full_path` is NULL', function()
|
||||
itp('returns NULL if `full_path` is NULL', function()
|
||||
local dir = to_cstr('some/directory/file.txt')
|
||||
eq(NULL, (path.path_shorten_fname(NULL, dir)))
|
||||
end)
|
||||
|
||||
it('returns NULL if the path and dir does not match', function()
|
||||
itp('returns NULL if the path and dir does not match', function()
|
||||
local dir = to_cstr('not/the/same')
|
||||
local full = to_cstr('as/this.txt')
|
||||
eq(NULL, (path.path_shorten_fname(full, dir)))
|
||||
end)
|
||||
|
||||
it('returns NULL if the path is not separated properly', function()
|
||||
itp('returns NULL if the path is not separated properly', function()
|
||||
local dir = to_cstr('some/very/long/')
|
||||
local full = to_cstr('some/very/long/directory/file.txt')
|
||||
eq(NULL, (path.path_shorten_fname(full, dir)))
|
||||
end)
|
||||
|
||||
it('shortens the filename if `dir_name` is the start of `full_path`', function()
|
||||
itp('shortens the filename if `dir_name` is the start of `full_path`', function()
|
||||
local full = to_cstr('some/very/long/directory/file.txt')
|
||||
local dir = to_cstr('some/very/long')
|
||||
eq('directory/file.txt', (ffi.string(path.path_shorten_fname(full, dir))))
|
||||
@@ -280,20 +281,20 @@ describe('path_shorten_fname_if_possible', function()
|
||||
end)
|
||||
|
||||
describe('path_shorten_fname_if_possible', function()
|
||||
it('returns shortened path if possible', function()
|
||||
itp('returns shortened path if possible', function()
|
||||
lfs.chdir('ut_directory')
|
||||
local full = to_cstr(lfs.currentdir() .. '/subdir/file.txt')
|
||||
eq('subdir/file.txt', (ffi.string(path.path_shorten_fname_if_possible(full))))
|
||||
end)
|
||||
|
||||
it('returns `full_path` if a shorter version is not possible', function()
|
||||
itp('returns `full_path` if a shorter version is not possible', function()
|
||||
local old = lfs.currentdir()
|
||||
lfs.chdir('ut_directory')
|
||||
local full = old .. '/subdir/file.txt'
|
||||
eq(full, (ffi.string(path.path_shorten_fname_if_possible(to_cstr(full)))))
|
||||
end)
|
||||
|
||||
it('returns NULL if `full_path` is NULL', function()
|
||||
itp('returns NULL if `full_path` is NULL', function()
|
||||
eq(NULL, (path.path_shorten_fname_if_possible(NULL)))
|
||||
end)
|
||||
end)
|
||||
@@ -330,13 +331,13 @@ describe('more path function', function()
|
||||
buffer = cstr(length, '')
|
||||
end)
|
||||
|
||||
it('fails if given filename is NULL', function()
|
||||
itp('fails if given filename is NULL', function()
|
||||
local force_expansion = 1
|
||||
local result = path.vim_FullName(NULL, buffer, length, force_expansion)
|
||||
eq(FAIL, result)
|
||||
end)
|
||||
|
||||
it('fails safely if given length is wrong #5737', function()
|
||||
itp('fails safely if given length is wrong #5737', function()
|
||||
local force_expansion = 1
|
||||
local filename = 'foo/bar/bazzzzzzz/buz/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/a'
|
||||
local too_short_len = 8
|
||||
@@ -347,7 +348,7 @@ describe('more path function', function()
|
||||
eq(FAIL, result)
|
||||
end)
|
||||
|
||||
it('uses the filename if the filename is a URL', function()
|
||||
itp('uses the filename if the filename is a URL', function()
|
||||
local force_expansion = 1
|
||||
local filename = 'http://www.neovim.org'
|
||||
local result = vim_FullName(filename, buffer, length, force_expansion)
|
||||
@@ -355,7 +356,7 @@ describe('more path function', function()
|
||||
eq(OK, result)
|
||||
end)
|
||||
|
||||
it('fails and uses filename if given filename contains non-existing directory', function()
|
||||
itp('fails and uses filename if given filename contains non-existing directory', function()
|
||||
local force_expansion = 1
|
||||
local filename = 'non_existing_dir/test.file'
|
||||
local result = vim_FullName(filename, buffer, length, force_expansion)
|
||||
@@ -363,7 +364,7 @@ describe('more path function', function()
|
||||
eq(FAIL, result)
|
||||
end)
|
||||
|
||||
it('concatenates given filename if it does not contain a slash', function()
|
||||
itp('concatenates given filename if it does not contain a slash', function()
|
||||
local force_expansion = 1
|
||||
local result = vim_FullName('test.file', buffer, length, force_expansion)
|
||||
local expected = lfs.currentdir() .. '/test.file'
|
||||
@@ -371,7 +372,7 @@ describe('more path function', function()
|
||||
eq(OK, result)
|
||||
end)
|
||||
|
||||
it('concatenates given filename if it is a directory but does not contain a\n slash', function()
|
||||
itp('concatenates given filename if it is a directory but does not contain a\n slash', function()
|
||||
local force_expansion = 1
|
||||
local result = vim_FullName('..', buffer, length, force_expansion)
|
||||
local expected = lfs.currentdir() .. '/..'
|
||||
@@ -381,7 +382,7 @@ describe('more path function', function()
|
||||
|
||||
-- Is it possible for every developer to enter '..' directory while running
|
||||
-- the unit tests? Which other directory would be better?
|
||||
it('enters given directory (instead of just concatenating the strings) if possible and if path contains a slash', function()
|
||||
itp('enters given directory (instead of just concatenating the strings) if possible and if path contains a slash', function()
|
||||
local force_expansion = 1
|
||||
local result = vim_FullName('../test.file', buffer, length, force_expansion)
|
||||
local old_dir = lfs.currentdir()
|
||||
@@ -392,7 +393,7 @@ describe('more path function', function()
|
||||
eq(OK, result)
|
||||
end)
|
||||
|
||||
it('just copies the path if it is already absolute and force=0', function()
|
||||
itp('just copies the path if it is already absolute and force=0', function()
|
||||
local force_expansion = 0
|
||||
local absolute_path = '/absolute/path'
|
||||
local result = vim_FullName(absolute_path, buffer, length, force_expansion)
|
||||
@@ -400,7 +401,7 @@ describe('more path function', function()
|
||||
eq(OK, result)
|
||||
end)
|
||||
|
||||
it('fails and uses filename when the path is relative to HOME', function()
|
||||
itp('fails and uses filename when the path is relative to HOME', function()
|
||||
local force_expansion = 1
|
||||
local absolute_path = '~/home.file'
|
||||
local result = vim_FullName(absolute_path, buffer, length, force_expansion)
|
||||
@@ -408,14 +409,14 @@ describe('more path function', function()
|
||||
eq(FAIL, result)
|
||||
end)
|
||||
|
||||
it('works with some "normal" relative path with directories', function()
|
||||
itp('works with some "normal" relative path with directories', function()
|
||||
local force_expansion = 1
|
||||
local result = vim_FullName('unit-test-directory/test.file', buffer, length, force_expansion)
|
||||
eq(OK, result)
|
||||
eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer)))
|
||||
end)
|
||||
|
||||
it('does not modify the given filename', function()
|
||||
itp('does not modify the given filename', function()
|
||||
local force_expansion = 1
|
||||
local filename = to_cstr('unit-test-directory/test.file')
|
||||
-- Don't use the wrapper here but pass a cstring directly to the c
|
||||
@@ -426,7 +427,7 @@ describe('more path function', function()
|
||||
eq(OK, result)
|
||||
end)
|
||||
|
||||
it('works with directories that have one path component', function()
|
||||
itp('works with directories that have one path component', function()
|
||||
local force_expansion = 1
|
||||
local filename = to_cstr('/tmp')
|
||||
local result = path.vim_FullName(filename, buffer, length, force_expansion)
|
||||
@@ -446,12 +447,12 @@ describe('more path function', function()
|
||||
after_each(function() lfs.rmdir('CamelCase') end)
|
||||
|
||||
if ffi.os == 'Windows' or ffi.os == 'OSX' then
|
||||
it('Corrects the case of file names in Mac and Windows', function()
|
||||
itp('Corrects the case of file names in Mac and Windows', function()
|
||||
eq('CamelCase', fix_case('camelcase'))
|
||||
eq('CamelCase', fix_case('cAMELcASE'))
|
||||
end)
|
||||
else
|
||||
it('does nothing on Linux', function()
|
||||
itp('does nothing on Linux', function()
|
||||
eq('camelcase', fix_case('camelcase'))
|
||||
eq('cAMELcASE', fix_case('cAMELcASE'))
|
||||
end)
|
||||
@@ -459,41 +460,41 @@ describe('more path function', function()
|
||||
end)
|
||||
|
||||
describe('append_path', function()
|
||||
it('joins given paths with a slash', function()
|
||||
itp('joins given paths with a slash', function()
|
||||
local path1 = cstr(100, 'path1')
|
||||
local to_append = to_cstr('path2')
|
||||
eq(OK, (path.append_path(path1, to_append, 100)))
|
||||
eq("path1/path2", (ffi.string(path1)))
|
||||
end)
|
||||
|
||||
it('joins given paths without adding an unnecessary slash', function()
|
||||
itp('joins given paths without adding an unnecessary slash', function()
|
||||
local path1 = cstr(100, 'path1/')
|
||||
local to_append = to_cstr('path2')
|
||||
eq(OK, path.append_path(path1, to_append, 100))
|
||||
eq("path1/path2", (ffi.string(path1)))
|
||||
end)
|
||||
|
||||
it('fails and uses filename if there is not enough space left for to_append', function()
|
||||
itp('fails and uses filename if there is not enough space left for to_append', function()
|
||||
local path1 = cstr(11, 'path1/')
|
||||
local to_append = to_cstr('path2')
|
||||
eq(FAIL, (path.append_path(path1, to_append, 11)))
|
||||
end)
|
||||
|
||||
it('does not append a slash if to_append is empty', function()
|
||||
itp('does not append a slash if to_append is empty', function()
|
||||
local path1 = cstr(6, 'path1')
|
||||
local to_append = to_cstr('')
|
||||
eq(OK, (path.append_path(path1, to_append, 6)))
|
||||
eq('path1', (ffi.string(path1)))
|
||||
end)
|
||||
|
||||
it('does not append unnecessary dots', function()
|
||||
itp('does not append unnecessary dots', function()
|
||||
local path1 = cstr(6, 'path1')
|
||||
local to_append = to_cstr('.')
|
||||
eq(OK, (path.append_path(path1, to_append, 6)))
|
||||
eq('path1', (ffi.string(path1)))
|
||||
end)
|
||||
|
||||
it('copies to_append to path, if path is empty', function()
|
||||
itp('copies to_append to path, if path is empty', function()
|
||||
local path1 = cstr(7, '')
|
||||
local to_append = to_cstr('/path2')
|
||||
eq(OK, (path.append_path(path1, to_append, 7)))
|
||||
@@ -507,15 +508,15 @@ describe('more path function', function()
|
||||
return path.path_is_absolute_path(filename)
|
||||
end
|
||||
|
||||
it('returns true if filename starts with a slash', function()
|
||||
itp('returns true if filename starts with a slash', function()
|
||||
eq(OK, path_is_absolute_path('/some/directory/'))
|
||||
end)
|
||||
|
||||
it('returns true if filename starts with a tilde', function()
|
||||
itp('returns true if filename starts with a tilde', function()
|
||||
eq(OK, path_is_absolute_path('~/in/my/home~/directory'))
|
||||
end)
|
||||
|
||||
it('returns false if filename starts not with slash nor tilde', function()
|
||||
itp('returns false if filename starts not with slash nor tilde', function()
|
||||
eq(FAIL, path_is_absolute_path('not/in/my/home~/directory'))
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user