From 1250821ba817bffe14b25cd95421b122ba91dfc7 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 20 Jul 2026 18:11:52 +0200 Subject: [PATCH] test: drop `assert.is_true()` and friends --- test/assert.lua | 28 +----- test/functional/autocmd/filetype_spec.lua | 2 +- test/functional/harness/harness_spec.lua | 105 +++++++++++----------- test/functional/terminal/parser_spec.lua | 8 +- test/unit/garray_spec.lua | 8 +- test/unit/memory_spec.lua | 4 +- test/unit/os/env_spec.lua | 6 +- test/unit/os/fs_spec.lua | 90 +++++++++---------- test/unit/os/users_spec.lua | 4 +- test/unit/profile_spec.lua | 26 +++--- test/unit/tempfile_spec.lua | 6 +- 11 files changed, 131 insertions(+), 156 deletions(-) diff --git a/test/assert.lua b/test/assert.lua index 4ec1c610ae..5be7d21f00 100644 --- a/test/assert.lua +++ b/test/assert.lua @@ -5,7 +5,7 @@ local FORMAT_DEPTH = 100 --- @param value any --- @return string -local function format_value(value) +local function fmt(value) if type(value) == 'string' then return string.format('%q', value) end @@ -36,8 +36,8 @@ end local function comparison_message(expected, actual, comparator) return ('Expected values to be %s.\nExpected:\n%s\nActual:\n%s'):format( comparator, - format_value(expected), - format_value(actual) + fmt(expected), + fmt(actual) ) end @@ -63,30 +63,10 @@ function M.neq(expected, actual, context) not vim.deep_equal(expected, actual), actual, context, - ('Expected values to differ.\nValue:\n%s'):format(format_value(actual)) + ('Expected values to differ.\nValue:\n%s'):format(fmt(actual)) ) end ---- @param value any ---- @param context? any ---- @return any -function M.is_true(value, context) - return M.eq(true, value, context) -end - ---- @param value any ---- @param context? any ---- @return any -function M.is_false(value, context) - return M.eq(false, value, context) -end - --- TODO(lewis6991): remove these aliases -M.True = M.is_true -M.False = M.is_false -M.equals = M.eq -M.Equal = M.eq - return setmetatable(M, { --- @param condition any --- @param message? string diff --git a/test/functional/autocmd/filetype_spec.lua b/test/functional/autocmd/filetype_spec.lua index 72ce5cb836..4841377946 100644 --- a/test/functional/autocmd/filetype_spec.lua +++ b/test/functional/autocmd/filetype_spec.lua @@ -14,6 +14,6 @@ describe('autocmd FileType', function() command('let g:foo = 0') command('autocmd FileType help let g:foo = g:foo + 1') command('help help') - assert.eq(1, eval('g:foo')) + t.eq(1, eval('g:foo')) end) end) diff --git a/test/functional/harness/harness_spec.lua b/test/functional/harness/harness_spec.lua index 51e5b9ba26..8ef99f5db6 100644 --- a/test/functional/harness/harness_spec.lua +++ b/test/functional/harness/harness_spec.lua @@ -1,8 +1,7 @@ -- Black-box tests for the local Lua harness itself. These spawn a separate -- Nvim process instead of driving an embedded instance via testnvim. local t = require('test.testutil') -local describe, it, before_each, after_each, setup, teardown, pending, finally = - t.describe, t.it, t.before_each, t.after_each, t.setup, t.teardown, t.pending, t.finally +local describe, it, pending, finally = t.describe, t.it, t.pending, t.finally local uv = vim.uv local eq = t.eq @@ -19,6 +18,11 @@ local function mkdir(path) assert(t.mkdir(path), ('failed to create directory: %s'):format(path)) end +-- Prepended to each *_spec.lua fixture so it can use the test framework. +local spec_preamble = "local h = require('test.harness'); local eq = require('test.assert').eq; " + .. 'local describe, it, before_each, after_each, setup, teardown, pending, finally = ' + .. 'h.describe, h.it, h.before_each, h.after_each, h.setup, h.teardown, h.pending, h.finally; ' + ---@param suite_files table ---@return string local function write_suite(suite_files) @@ -26,6 +30,9 @@ local function write_suite(suite_files) mkdir(dir) for name, contents in pairs(suite_files) do + if name:match('_spec%.lua$') then + contents = spec_preamble .. contents + end t.write_file(dir .. '/' .. name, contents) end @@ -148,7 +155,7 @@ describe('test harness', function() describe('one', function() it('defines a preload entry', function() - assert.Equal('leak', require('leak_mod')) + eq('leak', require('leak_mod')) end) end) ]], @@ -156,7 +163,7 @@ describe('test harness', function() describe('two', function() it('does not see the preload entry from another file', function() local ok = pcall(require, 'leak_mod') - assert.False(ok) + assert(not ok) end) end) ]], @@ -173,9 +180,9 @@ describe('test harness', function() ['one_spec.lua'] = [[ describe('one', function() it('mutates package.loaded', function() - assert.Equal('file', require('loaded_mod').source) + eq('file', require('loaded_mod').source) package.loaded.loaded_mod = 'leak' - assert.Equal('leak', require('loaded_mod')) + eq('leak', require('loaded_mod')) end) end) ]], @@ -183,7 +190,7 @@ describe('test harness', function() describe('two', function() it('does not see package.loaded leaks from another file', function() local mod = require('loaded_mod') - assert.Equal('file', mod.source) + eq('file', mod.source) end) end) ]], @@ -200,7 +207,7 @@ describe('test harness', function() describe('one', function() it('mutates the environment', function() vim.uv.os_setenv(%q, 'leak') - assert.Equal('leak', vim.uv.os_getenv(%q)) + eq('leak', vim.uv.os_getenv(%q)) end) end) ]], @@ -211,7 +218,7 @@ describe('test harness', function() [[ describe('two', function() it('does not see environment leaks from another file', function() - assert.Equal(nil, vim.uv.os_getenv(%q)) + eq(nil, vim.uv.os_getenv(%q)) end) end) ]], @@ -228,14 +235,14 @@ describe('test harness', function() describe('one', function() it('mutates a global', function() _G.__harness_leak = 'leak' - assert.Equal('leak', _G.__harness_leak) + eq('leak', _G.__harness_leak) end) end) ]], ['two_spec.lua'] = [[ describe('two', function() it('does not see global leaks from another file', function() - assert.Equal(nil, _G.__harness_leak) + eq(nil, _G.__harness_leak) end) end) ]], @@ -250,14 +257,14 @@ describe('test harness', function() describe('one', function() it('mutates arg', function() _G.arg.__leak = 'leak' - assert.Equal('leak', _G.arg.__leak) + eq('leak', _G.arg.__leak) end) end) ]], ['two_spec.lua'] = [[ describe('two', function() it('does not see arg leaks from another file', function() - assert.Equal(nil, _G.arg.__leak) + eq(nil, _G.arg.__leak) end) end) ]], @@ -274,16 +281,16 @@ describe('test harness', function() ['one_spec.lua'] = [[ describe('one', function() it('mutates a helper-provided global', function() - assert.Equal('baseline', _G.helper_value) + eq('baseline', _G.helper_value) _G.helper_value = 'leak' - assert.Equal('leak', _G.helper_value) + eq('leak', _G.helper_value) end) end) ]], ['two_spec.lua'] = [[ describe('two', function() it('restores the helper baseline between files', function() - assert.Equal('baseline', _G.helper_value) + eq('baseline', _G.helper_value) end) end) ]], @@ -302,16 +309,16 @@ describe('test harness', function() ['one_spec.lua'] = [[ describe('one', function() it('mutates nested helper state in place', function() - assert.Equal('baseline', _G.helper_value.nested) + eq('baseline', _G.helper_value.nested) _G.helper_value.nested = 'leak' - assert.Equal('leak', _G.helper_value.nested) + eq('leak', _G.helper_value.nested) end) end) ]], ['two_spec.lua'] = [[ describe('two', function() it('keeps the same nested helper table', function() - assert.Equal('leak', _G.helper_value.nested) + eq('leak', _G.helper_value.nested) end) end) ]], @@ -334,14 +341,14 @@ describe('test harness', function() ['one_spec.lua'] = [[ describe('one', function() it('uses the helper-loaded module', function() - assert.Equal(1, require('helper_mod').loads) + eq(1, require('helper_mod').loads) end) end) ]], ['two_spec.lua'] = [[ describe('two', function() it('does not reload the helper module', function() - assert.Equal(1, require('helper_mod').loads) + eq(1, require('helper_mod').loads) end) end) ]], @@ -416,7 +423,7 @@ describe('test harness', function() describe('one', function() it('works', function() - assert.True(true) + assert(true) end) end) ]], @@ -425,7 +432,7 @@ describe('test harness', function() describe('two', function() it('works', function() - assert.True(true) + assert(true) end) end) ]], @@ -464,10 +471,8 @@ describe('test harness', function() end end - t.write_file( - left .. '/same_spec.lua', - string.format( - [[ + t.write_file(left .. '/same_spec.lua', spec_preamble .. string.format( + [[ local harness = require('test.harness') harness.on_suite_end(function() @@ -480,13 +485,10 @@ describe('test harness', function() it('works', function() end) end) ]], - marker - ) - ) - t.write_file( - right .. '/same_spec.lua', - string.format( - [[ + marker + )) + t.write_file(right .. '/same_spec.lua', spec_preamble .. string.format( + [[ local harness = require('test.harness') harness.on_suite_end(function() @@ -499,9 +501,8 @@ describe('test harness', function() it('works', function() end) end) ]], - marker - ) - ) + marker + )) assert_harness_passes(suite_dir) eq('left\nright\n', t.read_file(marker)) @@ -524,7 +525,7 @@ describe('test harness', function() describe('one', function() it('works', function() - assert.True(true) + assert(true) end) end) ]], @@ -568,7 +569,7 @@ describe('test harness', function() describe('one', function() it('works', function() - assert.True(true) + assert(true) end) end) ]], @@ -601,7 +602,7 @@ describe('test harness', function() ['one_spec.lua'] = [[ describe('one', function() it('works', function() - assert.True(true) + assert(true) end) end) ]], @@ -625,7 +626,7 @@ describe('test harness', function() describe('one', function() it('starts clean', function() - assert.Equal(nil, _G.__repeat_leak) + eq(nil, _G.__repeat_leak) end) end) ]], @@ -748,7 +749,7 @@ describe('test harness', function() describe('one', function() it('skipped', function() - assert.True(true) + assert(true) end) end) ]], @@ -757,7 +758,7 @@ describe('test harness', function() ['two_spec.lua'] = [[ describe('two', function() it('chosen', function() - assert.True(true) + assert(true) end) end) ]], @@ -900,25 +901,19 @@ describe('test harness', function() local suite_dir = t.tmpname(false) mkdir(suite_dir) - t.write_file( - suite_dir .. '/one_spec.lua', - [[ + t.write_file(suite_dir .. '/one_spec.lua', spec_preamble .. [[ describe('one', function() it('works', function() end) end) - ]] - ) + ]]) local blocked = suite_dir .. '/blocked' mkdir(blocked) - t.write_file( - blocked .. '/two_spec.lua', - [[ + t.write_file(blocked .. '/two_spec.lua', spec_preamble .. [[ describe('two', function() it('is hidden behind permissions', function() end) end) - ]] - ) + ]]) finally(function() assert(uv.fs_chmod(blocked, 448)) end) @@ -1079,7 +1074,7 @@ describe('test harness', function() ['one_spec.lua'] = [[ describe('one', function() it('equal fail', function() - assert.Equal(1, 2) + eq(1, 2) end) end) ]], @@ -1222,7 +1217,7 @@ describe('test harness', function() end) it('afterwrap', function() - assert.True(true) + assert(true) end) end) ]], diff --git a/test/functional/terminal/parser_spec.lua b/test/functional/terminal/parser_spec.lua index 208050d9f3..d2cfae0794 100644 --- a/test/functional/terminal/parser_spec.lua +++ b/test/functional/terminal/parser_spec.lua @@ -28,7 +28,7 @@ describe(':terminal', function() api.nvim_chan_send(chan, input) --- @type string local term_title = api.nvim_buf_get_var(0, 'term_title') - assert.Equal(term_title, 'This title set with OSC 2') + t.eq(term_title, 'This title set with OSC 2') assert_alive() end) @@ -40,7 +40,7 @@ describe(':terminal', function() api.nvim_chan_send(chan, input) --- @type string local term_title = api.nvim_buf_get_var(0, 'term_title') - assert.Equal(term_title, 'This title set with OSC 0') + t.eq(term_title, 'This title set with OSC 0') assert_alive() end) @@ -82,14 +82,14 @@ describe(':terminal', function() send_osc_with_terminator(BEL) --- @type string - assert.eq( + t.eq( { sequence = OSC_PREFIX .. '10;?', terminator = BEL }, exec_lua([[return _G.osc10_response]]) ) send_osc_with_terminator(ST) --- @type string - assert.eq( + t.eq( { sequence = OSC_PREFIX .. '10;?', terminator = ST }, exec_lua([[return _G.osc10_response]]) ) diff --git a/test/unit/garray_spec.lua b/test/unit/garray_spec.lua index 761f77ca62..ffd4f750ff 100644 --- a/test/unit/garray_spec.lua +++ b/test/unit/garray_spec.lua @@ -74,7 +74,7 @@ local ga_clear = function(garr) end local ga_clear_strings = function(garr) - assert.is_true(ga_itemsize(garr) == ffi.sizeof('char *')) + t.ok(ga_itemsize(garr) == ffi.sizeof('char *')) return garray.ga_clear_strings(garr) end @@ -104,7 +104,7 @@ end -- derived manipulators local ga_set_len = function(garr, len) - assert.is_true(len <= ga_maxlen(garr)) + t.ok(len <= ga_maxlen(garr)) garr[0].ga_len = len end @@ -115,7 +115,7 @@ end -- custom append functions -- not the C ga_append, which only works for bytes local ga_append_int = function(garr, it) - assert.is_true(ga_itemsize(garr) == ffi.sizeof('int')) + t.ok(ga_itemsize(garr) == ffi.sizeof('int')) ga_grow(garr, 1) local data = ga_data_as_ints(garr) data[ga_len(garr)] = it @@ -123,7 +123,7 @@ local ga_append_int = function(garr, it) end local ga_append_string = function(garr, it) - assert.is_true(ga_itemsize(garr) == ffi.sizeof('char *')) + t.ok(ga_itemsize(garr) == ffi.sizeof('char *')) -- make a non-garbage collected string and copy the lua string into it, -- TODO(aktau): we should probably call xmalloc here, though as long as -- xmalloc is based on malloc it should work. diff --git a/test/unit/memory_spec.lua b/test/unit/memory_spec.lua index fd21015200..2f5d8e7343 100644 --- a/test/unit/memory_spec.lua +++ b/test/unit/memory_spec.lua @@ -12,7 +12,7 @@ local cimp = cimport('stdlib.h', './src/nvim/memory.h') describe('xstrlcat()', function() local function test_xstrlcat(dst, src, dsize) - assert.is_true(dsize >= 1 + string.len(dst)) -- sanity check for tests + t.ok(dsize >= 1 + string.len(dst)) -- sanity check for tests local dst_cstr = cstr(dsize, dst) local src_cstr = to_cstr(src) eq(string.len(dst .. src), cimp.xstrlcat(dst_cstr, src_cstr, dsize)) @@ -20,7 +20,7 @@ describe('xstrlcat()', function() end local function test_xstrlcat_overlap(dst, src_idx, dsize) - assert.is_true(dsize >= 1 + string.len(dst)) -- sanity check for tests + t.ok(dsize >= 1 + string.len(dst)) -- sanity check for tests local dst_cstr = cstr(dsize, dst) local src_cstr = dst_cstr + src_idx -- pointer into `dst` (overlaps) eq(string.len(dst) + string.len(dst) - src_idx, cimp.xstrlcat(dst_cstr, src_cstr, dsize)) diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua index bf2f3af8e5..994e2cdf1f 100644 --- a/test/unit/os/env_spec.lua +++ b/test/unit/os/env_spec.lua @@ -255,7 +255,7 @@ describe('env.c', function() eq(OK, os_unsetenv(name)) neq(value, os_getenv(name)) -- Depending on the platform the var might be unset or set as '' - assert.True(os_getenv(name) == nil or os_getenv(name) == '') + t.ok(os_getenv(name) == nil or os_getenv(name) == '') if os_getenv(name) == nil then eq(false, os_env_exists(name, false)) end @@ -373,8 +373,8 @@ describe('env.c', function() local dst = cstr(256, '~' .. curuser) cimp.expand_env_esc(src, dst, 256, NULL, false, NULL) local len = string.len(ffi.string(dst)) - assert.True(len > 56) - assert.True(len < 256) + t.ok(len > 56) + t.ok(len < 256) end) itp('respects `dstlen` without expansion', function() diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua index d4333a7d7f..1d6ae312ec 100644 --- a/test/unit/os/fs_spec.lua +++ b/test/unit/os/fs_spec.lua @@ -247,12 +247,12 @@ describe('fs.c', function() end) itp('returns a perm > 0 when given an existing file', function() - assert.is_true((os_getperm('unit-test-directory')) > 0) + t.ok((os_getperm('unit-test-directory')) > 0) end) itp('returns S_IRUSR when the file is readable', function() local perm = os_getperm('unit-test-directory') - assert.is_true((bit_set(perm, ffi.C.kS_IRUSR))) + t.ok((bit_set(perm, ffi.C.kS_IRUSR))) end) end) @@ -262,11 +262,11 @@ describe('fs.c', function() perm = unset_bit(perm, ffi.C.kS_IXUSR) eq(OK, (os_setperm('unit-test-directory/test.file', perm))) perm = os_getperm('unit-test-directory/test.file') - assert.is_false((bit_set(perm, ffi.C.kS_IXUSR))) + assert(not (bit_set(perm, ffi.C.kS_IXUSR))) perm = set_bit(perm, ffi.C.kS_IXUSR) eq(OK, os_setperm('unit-test-directory/test.file', perm)) perm = os_getperm('unit-test-directory/test.file') - assert.is_true((bit_set(perm, ffi.C.kS_IXUSR))) + t.ok((bit_set(perm, ffi.C.kS_IXUSR))) end) itp('fails if given file does not exist', function() @@ -534,7 +534,7 @@ describe('fs.c', function() function() assert_file_does_not_exist(new_file) local fd = os_open(new_file, ffi.C.kO_CREAT, 0) - assert.is_true(0 <= fd) + t.ok(0 <= fd) eq(0, os_close(fd)) end ) @@ -542,7 +542,7 @@ describe('fs.c', function() itp('returns non-negative for O_CREAT on a existing file which then can be closed', function() assert_file_exists(existing_file) local fd = os_open(existing_file, ffi.C.kO_CREAT, 0) - assert.is_true(0 <= fd) + t.ok(0 <= fd) eq(0, os_close(fd)) end) @@ -573,7 +573,7 @@ describe('fs.c', function() 'returns a non-negative file descriptor for an existing file which then can be closed', function() local fd = os_open(existing_file, ffi.C.kO_RDWR, 0) - assert.is_true(0 <= fd) + t.ok(0 <= fd) eq(0, os_close(fd)) end ) @@ -916,26 +916,26 @@ describe('fs.c', function() describe('os_fileinfo', function() itp('returns false if path=NULL', function() local info = file_info_new() - assert.is_false((fs.os_fileinfo(nil, info))) + assert(not (fs.os_fileinfo(nil, info))) end) itp('returns false if given a non-existing file', function() local info = file_info_new() - assert.is_false((fs.os_fileinfo('/non-existent', info))) + assert(not (fs.os_fileinfo('/non-existent', info))) end) itp('returns true if given an existing file and fills FileInfo', function() local info = file_info_new() local path = 'unit-test-directory/test.file' - assert.is_true((fs.os_fileinfo(path, info))) - assert.is_true((has_fileinfo(info))) + t.ok((fs.os_fileinfo(path, info))) + t.ok((has_fileinfo(info))) end) itp('returns the FileInfo of the linked file, not the link', function() local info = file_info_new() local path = 'unit-test-directory/test_link.file' - assert.is_true((fs.os_fileinfo(path, info))) - assert.is_true((has_fileinfo(info))) + t.ok((fs.os_fileinfo(path, info))) + t.ok((has_fileinfo(info))) local mode = tonumber(info[0].stat.st_mode) return eq(ffi.C.kS_IFREG, (bit.band(mode, ffi.C.kS_IFMT))) end) @@ -944,21 +944,21 @@ describe('fs.c', function() describe('os_fileinfo_link', function() itp('returns false for non-existing file', function() local info = file_info_new() - assert.is_false((fs.os_fileinfo_link('/non-existent', info))) + assert(not (fs.os_fileinfo_link('/non-existent', info))) end) itp('returns true and fills FileInfo for existing file', function() local info = file_info_new() local path = 'unit-test-directory/test.file' - assert.is_true((fs.os_fileinfo_link(path, info))) - assert.is_true((has_fileinfo(info))) + t.ok((fs.os_fileinfo_link(path, info))) + t.ok((has_fileinfo(info))) end) itp('returns FileInfo of the link, not its target', function() local info = file_info_new() local link = 'unit-test-directory/test_link.file' - assert.is_true((fs.os_fileinfo_link(link, info))) - assert.is_true((has_fileinfo(info))) + t.ok((fs.os_fileinfo_link(link, info))) + t.ok((has_fileinfo(info))) local mode = tonumber(info[0].stat.st_mode) eq(ffi.C.kS_IFLNK, (bit.band(mode, ffi.C.kS_IFMT))) end) @@ -967,15 +967,15 @@ describe('fs.c', function() describe('os_fileinfo_fd', function() itp('returns false if given an invalid file descriptor', function() local info = file_info_new() - assert.is_false((fs.os_fileinfo_fd(-1, info))) + assert(not (fs.os_fileinfo_fd(-1, info))) end) itp('returns true if given a file descriptor and fills FileInfo', function() local info = file_info_new() local path = 'unit-test-directory/test.file' local fd = ffi.C.open(path, 0) - assert.is_true((fs.os_fileinfo_fd(fd, info))) - assert.is_true((has_fileinfo(info))) + t.ok((fs.os_fileinfo_fd(fd, info))) + t.ok((has_fileinfo(info))) ffi.C.close(fd) end) end) @@ -986,18 +986,18 @@ describe('fs.c', function() local file_info_2 = file_info_new() local path_1 = 'unit-test-directory/test.file' local path_2 = 'unit-test-directory/test_2.file' - assert.is_true((fs.os_fileinfo(path_1, file_info_1))) - assert.is_true((fs.os_fileinfo(path_2, file_info_2))) - assert.is_false((fs.os_fileinfo_id_equal(file_info_1, file_info_2))) + t.ok((fs.os_fileinfo(path_1, file_info_1))) + t.ok((fs.os_fileinfo(path_2, file_info_2))) + assert(not (fs.os_fileinfo_id_equal(file_info_1, file_info_2))) end) itp('returns true if file infos represent the same file', function() local file_info_1 = file_info_new() local file_info_2 = file_info_new() local path = 'unit-test-directory/test.file' - assert.is_true((fs.os_fileinfo(path, file_info_1))) - assert.is_true((fs.os_fileinfo(path, file_info_2))) - assert.is_true((fs.os_fileinfo_id_equal(file_info_1, file_info_2))) + t.ok((fs.os_fileinfo(path, file_info_1))) + t.ok((fs.os_fileinfo(path, file_info_2))) + t.ok((fs.os_fileinfo_id_equal(file_info_1, file_info_2))) end) itp('returns true if file infos represent the same file (symlink)', function() @@ -1005,9 +1005,9 @@ describe('fs.c', function() local file_info_2 = file_info_new() local path_1 = 'unit-test-directory/test.file' local path_2 = 'unit-test-directory/test_link.file' - assert.is_true((fs.os_fileinfo(path_1, file_info_1))) - assert.is_true((fs.os_fileinfo(path_2, file_info_2))) - assert.is_true((fs.os_fileinfo_id_equal(file_info_1, file_info_2))) + t.ok((fs.os_fileinfo(path_1, file_info_1))) + t.ok((fs.os_fileinfo(path_2, file_info_2))) + t.ok((fs.os_fileinfo_id_equal(file_info_1, file_info_2))) end) end) @@ -1016,7 +1016,7 @@ describe('fs.c', function() local info = file_info_new() local file_id = file_id_new() local path = 'unit-test-directory/test.file' - assert.is_true((fs.os_fileinfo(path, info))) + t.ok((fs.os_fileinfo(path, info))) fs.os_fileinfo_id(info, file_id) eq(info[0].stat.st_ino, file_id[0].inode) eq(info[0].stat.st_dev, file_id[0].device_id) @@ -1027,7 +1027,7 @@ describe('fs.c', function() itp('returns the inode from FileInfo', function() local info = file_info_new() local path = 'unit-test-directory/test.file' - assert.is_true((fs.os_fileinfo(path, info))) + t.ok((fs.os_fileinfo(path, info))) local inode = fs.os_fileinfo_inode(info) eq(info[0].stat.st_ino, inode) end) @@ -1042,7 +1042,7 @@ describe('fs.c', function() file:close() local size = uv.fs_stat(path).size local info = file_info_new() - assert.is_true(fs.os_fileinfo(path, info)) + t.ok(fs.os_fileinfo(path, info)) eq(size, fs.os_fileinfo_size(info)) end) end) @@ -1052,10 +1052,10 @@ describe('fs.c', function() local path = 'unit-test-directory/test.file' local path_link = 'unit-test-directory/test_hlink.file' local info = file_info_new() - assert.is_true(fs.os_fileinfo(path, info)) + t.ok(fs.os_fileinfo(path, info)) eq(1, fs.os_fileinfo_hardlinks(info)) uv.fs_link(path, path_link) - assert.is_true(fs.os_fileinfo(path, info)) + t.ok(fs.os_fileinfo(path, info)) eq(2, fs.os_fileinfo_hardlinks(info)) end) end) @@ -1065,7 +1065,7 @@ describe('fs.c', function() local path = 'unit-test-directory/test.file' local blksize = uv.fs_stat(path).blksize local info = file_info_new() - assert.is_true(fs.os_fileinfo(path, info)) + t.ok(fs.os_fileinfo(path, info)) if blksize then eq(blksize, fs.os_fileinfo_blocksize(info)) else @@ -1080,15 +1080,15 @@ describe('fs.c', function() describe('os_fileid', function() itp('returns false if given an non-existing file', function() local file_id = file_id_new() - assert.is_false((fs.os_fileid('/non-existent', file_id))) + assert(not (fs.os_fileid('/non-existent', file_id))) end) itp('returns true if given an existing file and fills file_id', function() local file_id = file_id_new() local path = 'unit-test-directory/test.file' - assert.is_true((fs.os_fileid(path, file_id))) - assert.is_true(0 < file_id[0].inode) - assert.is_true(0 < file_id[0].device_id) + t.ok((fs.os_fileid(path, file_id))) + t.ok(0 < file_id[0].inode) + t.ok(0 < file_id[0].device_id) end) end) @@ -1096,8 +1096,8 @@ describe('fs.c', function() itp('returns true if two FileIDs are equal', function() local file_id = file_id_new() local path = 'unit-test-directory/test.file' - assert.is_true((fs.os_fileid(path, file_id))) - assert.is_true((fs.os_fileid_equal(file_id, file_id))) + t.ok((fs.os_fileid(path, file_id))) + t.ok((fs.os_fileid_equal(file_id, file_id))) end) itp('returns false if two FileIDs are not equal', function() @@ -1105,9 +1105,9 @@ describe('fs.c', function() local file_id_2 = file_id_new() local path_1 = 'unit-test-directory/test.file' local path_2 = 'unit-test-directory/test_2.file' - assert.is_true((fs.os_fileid(path_1, file_id_1))) - assert.is_true((fs.os_fileid(path_2, file_id_2))) - assert.is_false((fs.os_fileid_equal(file_id_1, file_id_2))) + t.ok((fs.os_fileid(path_1, file_id_1))) + t.ok((fs.os_fileid(path_2, file_id_2))) + assert(not (fs.os_fileid_equal(file_id_1, file_id_2))) end) end) end) diff --git a/test/unit/os/users_spec.lua b/test/unit/os/users_spec.lua index 350a8ed783..0b4c6fe4cd 100644 --- a/test/unit/os/users_spec.lua +++ b/test/unit/os/users_spec.lua @@ -37,7 +37,7 @@ describe('users function', function() local ga_users = garray_new() eq(OK, users.os_get_usernames(ga_users)) local user_count = garray_get_len(ga_users) - assert.is_true(user_count > 0) + t.ok(user_count > 0) local current_username_found = false for i = 0, user_count - 1 do local name = ffi.string((garray_get_item(ga_users, i))) @@ -45,7 +45,7 @@ describe('users function', function() current_username_found = true end end - assert.is_true(current_username_found) + t.ok(current_username_found) end) end) diff --git a/test/unit/profile_spec.lua b/test/unit/profile_spec.lua index fd702693b7..7d7c2074d8 100644 --- a/test/unit/profile_spec.lua +++ b/test/unit/profile_spec.lua @@ -37,7 +37,7 @@ local function cmp_assert(v1, v2, op, opstr) if res == false then print(string.format('expected: %f %s %f', v1, opstr, v2)) end - assert.is_true(res) + t.ok(res) end local function lt(a, b) -- luacheck: ignore @@ -114,17 +114,17 @@ describe('profiling related functions', function() describe('profile_cmp', function() itp('can compare subsequent starts', function() local s1, s2 = profile_start(), profile_start() - assert.is_true(profile_cmp(s1, s2) > 0) - assert.is_true(profile_cmp(s2, s1) < 0) + t.ok(profile_cmp(s1, s2) > 0) + t.ok(profile_cmp(s2, s1) < 0) end) itp('can compare the zero element', function() - assert.is_true(profile_cmp(profile_zero(), profile_zero()) == 0) + t.ok(profile_cmp(profile_zero(), profile_zero()) == 0) end) itp('correctly orders divisions', function() local start = profile_start() - assert.is_true(profile_cmp(start, profile_divide(start, 10)) <= 0) + t.ok(profile_cmp(start, profile_divide(start, 10)) <= 0) end) end) @@ -145,8 +145,8 @@ describe('profiling related functions', function() -- res should be in the range [start - divisor, start + divisor] local start_min, start_max = profile_sub(start, divisor), profile_add(start, divisor) - assert.is_true(profile_cmp(start_min, res) >= 0) - assert.is_true(profile_cmp(start_max, res) <= 0) + t.ok(profile_cmp(start_min, res) >= 0) + t.ok(profile_cmp(start_max, res) <= 0) end) end) @@ -192,7 +192,7 @@ describe('profiling related functions', function() itp('sets a limit in the future otherwise', function() local future = profile_setlimit(1000) local now = profile_start() - assert.is_true(profile_cmp(future, now) < 0) + t.ok(profile_cmp(future, now) < 0) end) end) @@ -232,14 +232,14 @@ describe('profiling related functions', function() -- more or less the same goes for the microsecond part, if it doesn't -- start with 0, it's too slow. - assert.is_true(starts(us, '0')) + t.ok(starts(us, '0')) end) end) describe('profile_add', function() itp('adds profiling times', function() local start = profile_start() - assert.equals(start, profile_add(profile_zero(), start)) + t.eq(start, profile_add(profile_zero(), start)) end) end) @@ -247,16 +247,16 @@ describe('profiling related functions', function() itp('subtracts profiling times', function() -- subtracting zero does nothing local start = profile_start() - assert.equals(start, profile_sub(start, profile_zero())) + t.eq(start, profile_sub(start, profile_zero())) local start1, start2, start3 = profile_start(), profile_start(), profile_start() local cmp = profile_cmp(profile_sub(start2, start1), profile_sub(start3, start1)) -- t2 >= t1 => profile_cmp(t1, t2) >= 0 - assert.is_true(cmp >= 0) + t.ok(cmp >= 0) cmp = profile_cmp(profile_sub(start3, start1), profile_sub(start2, start1)) -- t2 <= t1 => profile_cmp(t1, t2) <= 0 - assert.is_true(cmp <= 0) + t.ok(cmp <= 0) end) end) end) diff --git a/test/unit/tempfile_spec.lua b/test/unit/tempfile_spec.lua index ec9b5357ce..44b1bdeda7 100644 --- a/test/unit/tempfile_spec.lua +++ b/test/unit/tempfile_spec.lua @@ -26,12 +26,12 @@ describe('tempfile related functions', function() describe('vim_gettempdir', function() itp('returns path to Nvim own temp directory', function() local dir = vim_gettempdir() - assert.True(dir ~= nil and dir:len() > 0) + t.ok(dir ~= nil and dir:len() > 0) -- os_file_is_writable returns 2 for a directory which we have rights -- to write into. eq(2, lib.os_file_is_writable(t.to_cstr(dir))) for entry in vim.fs.dir(dir) do - assert.True(entry == '.' or entry == '..') + t.ok(entry == '.' or entry == '..') end end) @@ -48,7 +48,7 @@ describe('tempfile related functions', function() itp('generate name of non-existing file', function() local file = vim_tempname() assert(file) - assert.False(lib.os_path_exists(file)) + assert(not lib.os_path_exists(file)) end) itp('generate different names on each call', function()