diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-04-24 22:45:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-24 22:45:03 +0200 |
commit | 8f346a322bc18949ae256203ffa801d7ba1dd1c0 (patch) | |
tree | 1867d48970c48dd7bccf827def7e2b196b1c2661 /test/unit/os | |
parent | 8dc3eca49ba4203fb28ae4d70f3bfac35442199a (diff) | |
download | rneovim-8f346a322bc18949ae256203ffa801d7ba1dd1c0.tar.gz rneovim-8f346a322bc18949ae256203ffa801d7ba1dd1c0.tar.bz2 rneovim-8f346a322bc18949ae256203ffa801d7ba1dd1c0.zip |
test/fs: sanity check for literal "~" directory (#6579)
If the CWD contains a directory with the literal name "~" then the tests
will have bogus failures.
Diffstat (limited to 'test/unit/os')
-rw-r--r-- | test/unit/os/fs_spec.lua | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua index 860ebfdbcb..23eb05b4b8 100644 --- a/test/unit/os/fs_spec.lua +++ b/test/unit/os/fs_spec.lua @@ -35,7 +35,6 @@ for i = 0, 255 do end local fcontents = s:rep(16) -local buffer = "" local directory = nil local absolute_executable = nil local executable_name = nil @@ -65,7 +64,11 @@ local function os_getperm(filename) return tonumber(perm) end -describe('fs function', function() +describe('fs.c', function() + local function os_isdir(name) + return fs.os_isdir(to_cstr(name)) + end + before_each(function() lfs.mkdir('unit-test-directory'); @@ -91,32 +94,37 @@ describe('fs function', function() end) describe('os_dirname', function() - local length - - local function os_dirname(buf, len) - return fs.os_dirname(buf, len) - end - - before_each(function() - length = (string.len(lfs.currentdir())) + 1 - buffer = cstr(length, '') + itp('returns OK and writes current directory to the buffer', function() + local length = string.len(lfs.currentdir()) + 1 + local buf = cstr(length, '') + eq(OK, fs.os_dirname(buf, length)) + eq(lfs.currentdir(), ffi.string(buf)) end) - itp('returns OK and writes current directory into the buffer if it is large\n enough', function() - eq(OK, (os_dirname(buffer, length))) - eq(lfs.currentdir(), (ffi.string(buffer))) - end) - - -- What kind of other failing cases are possible? itp('returns FAIL if the buffer is too small', function() - local buf = cstr((length - 1), '') - eq(FAIL, (os_dirname(buf, (length - 1)))) + local length = string.len(lfs.currentdir()) + 1 + local buf = cstr(length - 1, '') + eq(FAIL, fs.os_dirname(buf, length - 1)) end) end) - local function os_isdir(name) - return fs.os_isdir((to_cstr(name))) - end + describe('os_chdir', function() + itp('fails with path="~"', function() + eq(false, os_isdir('~')) -- sanity check: no literal "~" directory. + local length = 4096 + local expected_cwd = cstr(length, '') + local cwd = cstr(length, '') + eq(OK, fs.os_dirname(expected_cwd, length)) + + -- os_chdir returns 0 for success, not OK (1). + neq(0, fs.os_chdir('~')) -- fail + neq(0, fs.os_chdir('~/')) -- fail + + eq(OK, fs.os_dirname(cwd, length)) + -- CWD did not change. + eq(ffi.string(expected_cwd), ffi.string(cwd)) + end) + end) describe('os_isdir', function() itp('returns false if an empty string is given', function() |