From 9d6bffd517e4b262b85c27a4ff620a2b1aae4a68 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Thu, 17 Jan 2019 14:20:23 +0100 Subject: tests: fix Test_help_tagjump() The Vim version of Test_help_tagjump() tests for `:help sm?le` here. That command got removed from Nvim, so the test was changed to check against `:help sp?it` instead. The new test already handled the case that on Win `:h split` would jump to the entry for split() and on all other systems to the entry for :split. Then this commit happened: bb3aa824b lua/stdlib: vim.inspect, string functions Since then `:h split` would jump to split() for macOS as well! I'm not sure why. Anyway, instead of adding another check for has('mac'), we change the test once more to be more akin to the original test. Instead of testing for :smile, which is exclusive to Vim, we check against :checkhealth, which is exclusive to Nvim. --- src/nvim/testdir/test_help_tagjump.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/testdir/test_help_tagjump.vim b/src/nvim/testdir/test_help_tagjump.vim index c873487b92..a6494c531c 100644 --- a/src/nvim/testdir/test_help_tagjump.vim +++ b/src/nvim/testdir/test_help_tagjump.vim @@ -28,9 +28,9 @@ func Test_help_tagjump() call assert_true(getline('.') =~ '\*quotestar\*') helpclose - help sp?it + help ch?ckhealth call assert_equal("help", &filetype) - call assert_true(getline('.') =~ '\*'.(has('win32') ? 'split()' : ':split').'\*') + call assert_true(getline('.') =~ '\*:checkhealth\*') helpclose help :? -- cgit From 0afd452ef19ed08db8e74d72c0316bc40ac9c9bd Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Wed, 16 Jan 2019 21:20:38 +0100 Subject: tests: load-adjust timer tests (oldtest) --- src/nvim/testdir/load.vim | 30 ++++++++++++++++++++++++++++++ src/nvim/testdir/test_autocmd.vim | 6 ++++-- src/nvim/testdir/test_lambda.vim | 16 +++++++++++----- src/nvim/testdir/test_timers.vim | 13 +++++++++---- 4 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 src/nvim/testdir/load.vim (limited to 'src') diff --git a/src/nvim/testdir/load.vim b/src/nvim/testdir/load.vim new file mode 100644 index 0000000000..2e01338dd0 --- /dev/null +++ b/src/nvim/testdir/load.vim @@ -0,0 +1,30 @@ +function! s:load_factor() abort + let timeout = 200 + let times = [] + + for _ in range(5) + let g:val = 0 + call timer_start(timeout, {-> nvim_set_var('val', 1)}) + let start = reltime() + while 1 + sleep 10m + if g:val == 1 + let g:waited_in_ms = float2nr(reltimefloat(reltime(start)) * 1000) + break + endif + endwhile + call insert(times, g:waited_in_ms, 0) + endfor + + let longest = max(times) + let factor = (longest + 50.0) / timeout + + return factor +endfunction + +" Compute load factor only once. +let s:load_factor = s:load_factor() + +function! LoadAdjust(num) abort + return float2nr(ceil(a:num * s:load_factor)) +endfunction diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 253d6750ed..f1fb8e67b9 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -18,6 +18,8 @@ func Test_vim_did_enter() endfunc if has('timers') + source load.vim + func ExitInsertMode(id) call feedkeys("\") endfunc @@ -29,7 +31,7 @@ if has('timers') let g:triggered = 0 au CursorHoldI * let g:triggered += 1 set updatetime=20 - call timer_start(100, 'ExitInsertMode') + call timer_start(LoadAdjust(100), 'ExitInsertMode') call feedkeys('a', 'x!') call assert_equal(1, g:triggered) au! CursorHoldI @@ -40,7 +42,7 @@ if has('timers') let g:triggered = 0 au CursorHoldI * let g:triggered += 1 set updatetime=20 - call timer_start(100, 'ExitInsertMode') + call timer_start(LoadAdjust(100), 'ExitInsertMode') " CursorHoldI does not trigger after CTRL-X call feedkeys("a\", 'x!') call assert_equal(0, g:triggered) diff --git a/src/nvim/testdir/test_lambda.vim b/src/nvim/testdir/test_lambda.vim index 6e07c874b4..ada25da4a8 100644 --- a/src/nvim/testdir/test_lambda.vim +++ b/src/nvim/testdir/test_lambda.vim @@ -23,6 +23,8 @@ function! Test_lambda_with_timer() return endif + source load.vim + let s:n = 0 let s:timer_id = 0 function! s:Foo() @@ -31,15 +33,19 @@ function! Test_lambda_with_timer() endfunction call s:Foo() - sleep 210ms + sleep 210m " do not collect lambda call test_garbagecollect_now() - let m = s:n - sleep 230ms + let m = LoadAdjust(s:n) + sleep 230m call timer_stop(s:timer_id) + + let n = LoadAdjust(s:n) + let nine = LoadAdjust(9) + call assert_true(m > 1) - call assert_true(s:n > m + 1) - call assert_true(s:n < 9) + call assert_true(n > m + 1) + call assert_true(n < nine) endfunction function! Test_lambda_with_partial() diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index cdfdd473b9..62ddad5dce 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -5,6 +5,7 @@ if !has('timers') endif source shared.vim +source load.vim func MyHandler(timer) let g:val += 1 @@ -14,13 +15,17 @@ func MyHandlerWithLists(lists, timer) let x = string(a:lists) endfunc +func s:assert_inrange(lower, upper, actual) + return assert_inrange(a:lower, LoadAdjust(a:upper), a:actual) +endfunc + func Test_oneshot() let g:val = 0 let timer = timer_start(50, 'MyHandler') let slept = WaitFor('g:val == 1') call assert_equal(1, g:val) if has('reltime') - call assert_inrange(40, 120, slept) + call s:assert_inrange(40, 120, slept) else call assert_inrange(20, 120, slept) endif @@ -32,7 +37,7 @@ func Test_repeat_three() let slept = WaitFor('g:val == 3') call assert_equal(3, g:val) if has('reltime') - call assert_inrange(120, 250, slept) + call s:assert_inrange(120, 250, slept) else call assert_inrange(80, 200, slept) endif @@ -58,7 +63,7 @@ func Test_with_partial_callback() let slept = WaitFor('g:val == 1') call assert_equal(1, g:val) if has('reltime') - call assert_inrange(40, 130, slept) + call s:assert_inrange(40, 130, slept) else call assert_inrange(20, 100, slept) endif @@ -121,7 +126,7 @@ func Test_paused() let slept = WaitFor('g:val == 1') call assert_equal(1, g:val) if has('reltime') - call assert_inrange(0, 140, slept) + call s:assert_inrange(0, 140, slept) else call assert_inrange(0, 10, slept) endif -- cgit