diff options
-rw-r--r-- | appveyor.yml | 2 | ||||
-rw-r--r-- | src/nvim/macros.h | 4 | ||||
-rw-r--r-- | test/benchmark/bench_re_freeze_spec.lua | 21 | ||||
-rw-r--r-- | test/functional/ex_cmds/file_spec.lua | 35 | ||||
-rw-r--r-- | test/functional/ex_cmds/recover_spec.lua | 41 | ||||
-rw-r--r-- | test/functional/helpers.lua | 34 | ||||
-rw-r--r-- | test/functional/normal/lang_spec.lua | 6 | ||||
-rw-r--r-- | test/functional/spell/spellfile_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/ui/inccommand_spec.lua | 24 | ||||
-rw-r--r-- | test/functional/ui/screen.lua | 19 |
10 files changed, 110 insertions, 80 deletions
diff --git a/appveyor.yml b/appveyor.yml index 8027aee166..edb679d223 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,7 +7,7 @@ build_script: - call ci\build.bat cache: - C:\msys64\var\cache\pacman\pkg -> ci\build.bat -- .deps -> third-party/** +- .deps -> third-party\** artifacts: - path: build/Neovim.zip - path: build/bin/nvim.exe diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 22fd48de9d..9131f8be84 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -120,8 +120,10 @@ /* mch_open_rw(): invoke os_open() with third argument for user R/W. */ #if defined(UNIX) /* open in rw------- mode */ # define mch_open_rw(n, f) os_open((n), (f), (mode_t)0600) +#elif defined(WIN32) +# define mch_open_rw(n, f) os_open((n), (f), S_IREAD | S_IWRITE) #else -# define mch_open_rw(n, f) os_open((n), (f), 0) +# define mch_open_rw(n, f) os_open((n), (f), 0) #endif # define REPLACE_NORMAL(s) (((s) & REPLACE_FLAG) && !((s) & VREPLACE_FLAG)) diff --git a/test/benchmark/bench_re_freeze_spec.lua b/test/benchmark/bench_re_freeze_spec.lua index 53041b042b..ea41953014 100644 --- a/test/benchmark/bench_re_freeze_spec.lua +++ b/test/benchmark/bench_re_freeze_spec.lua @@ -1,8 +1,8 @@ -- Test for benchmarking RE engine. -local helpers = require('test.functional.helpers') +local helpers = require('test.functional.helpers')(after_each) local insert, source = helpers.insert, helpers.source -local clear, execute, wait = helpers.clear, helpers.execute, helpers.wait +local clear, command = helpers.clear, helpers.command -- Temporary file for gathering benchmarking results for each regexp engine. local result_file = 'benchmark.out' @@ -31,7 +31,7 @@ describe('regexp search', function() clear() source(measure_script) insert('" Benchmark_results:') - execute('write! ' .. result_file) + command('write! ' .. result_file) end) -- At the end of the test run we just print the contents of the result file @@ -46,22 +46,19 @@ describe('regexp search', function() it('is working with regexpengine=0', function() local regexpengine = 0 - execute(string.format(measure_cmd, regexpengine)) - execute('write') - wait() + command(string.format(measure_cmd, regexpengine)) + command('write') end) it('is working with regexpengine=1', function() local regexpengine = 1 - execute(string.format(measure_cmd, regexpengine)) - execute('write') - wait() + command(string.format(measure_cmd, regexpengine)) + command('write') end) it('is working with regexpengine=2', function() local regexpengine = 2 - execute(string.format(measure_cmd, regexpengine)) - execute('write') - wait() + command(string.format(measure_cmd, regexpengine)) + command('write') end) end) diff --git a/test/functional/ex_cmds/file_spec.lua b/test/functional/ex_cmds/file_spec.lua new file mode 100644 index 0000000000..771c283134 --- /dev/null +++ b/test/functional/ex_cmds/file_spec.lua @@ -0,0 +1,35 @@ +local helpers = require('test.functional.helpers')(after_each) +local lfs = require('lfs') +local clear = helpers.clear +local command = helpers.command +local eq = helpers.eq +local funcs = helpers.funcs +local rmdir = helpers.rmdir + +describe(':file', function() + local swapdir = lfs.currentdir()..'/Xtest-file_spec' + before_each(function() + clear() + rmdir(swapdir) + lfs.mkdir(swapdir) + end) + after_each(function() + command('%bwipeout!') + rmdir(swapdir) + end) + + it("rename does not lose swapfile #6487", function() + local testfile = 'test-file_spec' + local testfile_renamed = testfile..'-renamed' + -- Note: `set swapfile` *must* go after `set directory`: otherwise it may + -- attempt to create a swapfile in different directory. + command('set directory^='..swapdir..'//') + command('set swapfile fileformat=unix undolevels=-1') + + command('edit! '..testfile) + -- Before #6487 this gave "E301: Oops, lost the swap file !!!" on Windows. + command('file '..testfile_renamed) + eq(testfile_renamed..'.swp', + string.match(funcs.execute('swapname'), '[^%%]+$')) + end) +end) diff --git a/test/functional/ex_cmds/recover_spec.lua b/test/functional/ex_cmds/recover_spec.lua index 36bf85015a..cb68c29b9a 100644 --- a/test/functional/ex_cmds/recover_spec.lua +++ b/test/functional/ex_cmds/recover_spec.lua @@ -1,12 +1,11 @@ --- Tests for :recover - local helpers = require('test.functional.helpers')(after_each) local lfs = require('lfs') local feed_command, eq, clear, eval, feed, expect, source = helpers.feed_command, helpers.eq, helpers.clear, helpers.eval, helpers.feed, helpers.expect, helpers.source - -if helpers.pending_win32(pending) then return end +local command = helpers.command +local ok = helpers.ok +local rmdir = helpers.rmdir describe(':recover', function() before_each(clear) @@ -23,30 +22,29 @@ describe(':preserve', function() local swapdir = lfs.currentdir()..'/testdir_recover_spec' before_each(function() clear() - helpers.rmdir(swapdir) + rmdir(swapdir) lfs.mkdir(swapdir) end) after_each(function() - helpers.rmdir(swapdir) + command('%bwipeout!') + rmdir(swapdir) end) it("saves to custom 'directory' and (R)ecovers (issue #1836)", function() local testfile = 'testfile_recover_spec' + -- Put swapdir at the start of the 'directory' list. #1836 -- Note: `set swapfile` *must* go after `set directory`: otherwise it may -- attempt to create a swapfile in different directory. local init = [[ - set directory^=]]..swapdir..[[// + set directory^=]]..swapdir:gsub([[\]], [[\\]])..[[// set swapfile fileformat=unix undolevels=-1 ]] source(init) - feed_command('set swapfile fileformat=unix undolevels=-1') - -- Put swapdir at the start of the 'directory' list. #1836 - feed_command('set directory^='..swapdir..'//') - feed_command('edit '..testfile) + command('edit! '..testfile) feed('isometext<esc>') - feed_command('preserve') - source('redir => g:swapname | swapname | redir END') + command('preserve') + source('redir => g:swapname | silent swapname | redir END') local swappath1 = eval('g:swapname') @@ -59,19 +57,20 @@ describe(':preserve', function() source(init) -- Use the "SwapExists" event to choose the (R)ecover choice at the dialog. - feed_command('autocmd SwapExists * let v:swapchoice = "r"') - feed_command('silent edit '..testfile) - source('redir => g:swapname | swapname | redir END') + command('autocmd SwapExists * let v:swapchoice = "r"') + command('silent edit! '..testfile) + source('redir => g:swapname | silent swapname | redir END') local swappath2 = eval('g:swapname') + expect('sometext') -- swapfile from session 1 should end in .swp - assert(testfile..'.swp' == string.match(swappath1, '[^%%]+$')) - + eq(testfile..'.swp', string.match(swappath1, '[^%%]+$')) -- swapfile from session 2 should end in .swo - assert(testfile..'.swo' == string.match(swappath2, '[^%%]+$')) - - expect('sometext') + eq(testfile..'.swo', string.match(swappath2, '[^%%]+$')) + -- Verify that :swapname was not truncated (:help 'shortmess'). + ok(nil == string.find(swappath1, '%.%.%.')) + ok(nil == string.find(swappath2, '%.%.%.')) end) end) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 13b06e7f1b..7edb2381e8 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -32,20 +32,15 @@ local nvim_set = 'set shortmess+=I background=light noswapfile noautoindent' ..' belloff= noshowcmd noruler nomore' local nvim_argv = {nvim_prog, '-u', 'NONE', '-i', 'NONE', '-N', '--cmd', nvim_set, '--embed'} - -local mpack = require('mpack') - -local tmpname = global_helpers.tmpname -local uname = global_helpers.uname - --- Formulate a path to the directory containing nvim. We use this to --- help run test executables. It helps to keep the tests working, even --- when the build is not in the default location. +-- Directory containing nvim. local nvim_dir = nvim_prog:gsub("[/\\][^/\\]+$", "") if nvim_dir == nvim_prog then nvim_dir = "." end +local mpack = require('mpack') +local tmpname = global_helpers.tmpname +local uname = global_helpers.uname local prepend_argv if os.getenv('VALGRIND') then @@ -430,21 +425,27 @@ end local function do_rmdir(path) if lfs.attributes(path, 'mode') ~= 'directory' then - return nil + return -- Don't complain. end for file in lfs.dir(path) do if file ~= '.' and file ~= '..' then local abspath = path..'/'..file if lfs.attributes(abspath, 'mode') == 'directory' then - local ret = do_rmdir(abspath) -- recurse - if not ret then - return nil - end + do_rmdir(abspath) -- recurse else local ret, err = os.remove(abspath) if not ret then - error('os.remove: '..err) - return nil + if not session then + error('os.remove: '..err) + else + -- Try Nvim delete(): it handles `readonly` attribute on Windows, + -- and avoids Lua cross-version/platform incompatibilities. + if -1 == nvim_call('delete', abspath) then + local hint = (os_name() == 'windows' + and ' (hint: try :%bwipeout! before rmdir())' or '') + error('delete() failed'..hint..': '..abspath) + end + end end end end @@ -453,7 +454,6 @@ local function do_rmdir(path) if not ret then error('lfs.rmdir('..path..'): '..err) end - return ret end local function rmdir(path) diff --git a/test/functional/normal/lang_spec.lua b/test/functional/normal/lang_spec.lua index 464b85d684..1da1d4679d 100644 --- a/test/functional/normal/lang_spec.lua +++ b/test/functional/normal/lang_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) local clear, insert, eq = helpers.clear, helpers.insert, helpers.eq -local execute, expect = helpers.execute, helpers.expect +local command, expect = helpers.command, helpers.expect local feed, eval = helpers.feed, helpers.eval local exc_exec = helpers.exc_exec @@ -32,7 +32,7 @@ describe('gu and gU', function() end before_each(function() - execute('lang ctype tr_TR.UTF-8') + command('lang ctype tr_TR.UTF-8') end) it('with default casemap', function() @@ -46,7 +46,7 @@ describe('gu and gU', function() end) it('with casemap=""', function() - execute('set casemap=') + command('set casemap=') -- expect Turkish locale behavior insert("iI") feed("VgU") diff --git a/test/functional/spell/spellfile_spec.lua b/test/functional/spell/spellfile_spec.lua index e7cd10d2ac..afd2c1bce4 100644 --- a/test/functional/spell/spellfile_spec.lua +++ b/test/functional/spell/spellfile_spec.lua @@ -5,6 +5,7 @@ local eq = helpers.eq local clear = helpers.clear local meths = helpers.meths local exc_exec = helpers.exc_exec +local rmdir = helpers.rmdir local write_file = helpers.write_file local testdir = 'Xtest-functional-spell-spellfile.d' @@ -12,11 +13,12 @@ local testdir = 'Xtest-functional-spell-spellfile.d' describe('spellfile', function() before_each(function() clear() + rmdir(testdir) lfs.mkdir(testdir) lfs.mkdir(testdir .. '/spell') end) after_each(function() - lfs.rmdir(testdir) + rmdir(testdir) end) -- ┌ Magic string (#VIMSPELLMAGIC) -- │ ┌ Spell file version (#VIMSPELLVERSION) diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index b7a33cb64d..a7be1a9dc8 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local clear = helpers.clear +local command = helpers.command local curbufmeths = helpers.curbufmeths local eq = helpers.eq local eval = helpers.eval @@ -21,9 +22,9 @@ local default_text = [[ local function common_setup(screen, inccommand, text) if screen then - feed_command("syntax on") - feed_command("set nohlsearch") - feed_command("hi Substitute guifg=red guibg=yellow") + command("syntax on") + command("set nohlsearch") + command("hi Substitute guifg=red guibg=yellow") screen:attach() screen:set_default_attr_ids({ [1] = {foreground = Screen.colors.Fuchsia}, @@ -46,7 +47,7 @@ local function common_setup(screen, inccommand, text) }) end - feed_command("set inccommand=" .. (inccommand and inccommand or "")) + command("set inccommand=" .. (inccommand and inccommand or "")) if text then insert(text) @@ -456,7 +457,7 @@ describe(":substitute, 'inccommand' preserves undo", function() insert("X") feed("IY<esc>") feed(":%s/tw/MO/<esc>") - -- execute("undo") here would cause "Press ENTER". + -- feed_command("undo") here would cause "Press ENTER". feed("u") expect(default_text:gsub("Inc", "XInc")) feed("u") @@ -514,7 +515,7 @@ describe(":substitute, 'inccommand' preserves undo", function() feed("Ay<esc>") feed("Az<esc>") feed(":%s/tw/AR<esc>") - -- using execute("undo") here will result in a "Press ENTER" prompt + -- feed_command("undo") here would cause "Press ENTER". feed("u") expect(default_text:gsub("lines", "linesxy")) feed("u") @@ -603,7 +604,7 @@ describe(":substitute, 'inccommand' preserves undo", function() feed_command("set undolevels=-1") feed(":%s/tw/MO/g<enter>") - -- using execute("undo") here will result in a "Press ENTER" prompt + -- feed_command("undo") here will result in a "Press ENTER" prompt feed("u") if case == "split" then screen:expect([[ @@ -804,7 +805,6 @@ describe(":substitute, inccommand=split", function() it('does not show split window for :s/', function() feed("2gg") feed(":s/tw") - wait() screen:expect([[ Inc substitution on | two lines | @@ -1291,14 +1291,14 @@ describe("'inccommand' and :cnoremap", function() it('work with remapped characters', function() for _, case in pairs(cases) do refresh(case) - local command = "%s/lines/LINES/g" + local cmd = "%s/lines/LINES/g" - for i = 1, string.len(command) do - local c = string.sub(command, i, i) + for i = 1, string.len(cmd) do + local c = string.sub(cmd, i, i) feed_command("cnoremap ".. c .. " " .. c) end - feed_command(command) + feed_command(cmd) expect([[ Inc substitution on two LINES diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 2f2cc85dab..afbcd222c7 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -284,18 +284,13 @@ function Screen:wait(check, timeout) if failure_after_success then print([[ -Warning: Screen changes have been received after the expected state was seen. -This is probably due to an indeterminism in the test. Try adding -`wait()` (or even a separate `screen:expect(...)`) at a point of possible -indeterminism, typically in between a `feed()` or `execute()` which is non- -synchronous, and a synchronous api call. - -Note that sometimes a `wait` can trigger redraws and consequently generate more -indeterminism. If adding `wait` calls seems to increase the frequency of these -messages, try removing every `wait` call in the test. - -If everything else fails, use Screen:redraw_debug to help investigate what is - causing the problem. + +Warning: Screen changes were received after the expected state. This indicates +indeterminism in the test. Try adding wait() (or screen:expect(...)) between +asynchronous (feed(), nvim_input()) and synchronous API calls. + - Use Screen:redraw_debug() to investigate the problem. + - wait() can trigger redraws and consequently generate more indeterminism. + In that case try removing every wait(). ]]) local tb = debug.traceback() local index = string.find(tb, '\n%s*%[C]') |