From d763d2fe7aae1c531c72c1d542cad2b19719929b Mon Sep 17 00:00:00 2001 From: FlorianGit Date: Thu, 9 Nov 2017 21:31:17 +0100 Subject: Viml: Make filter and map handle null list correct filter('v:_null_list, 'v:val') should return v:_null_list and a similar statement should hold for map. Changes after review * Test inserted in legacy test suite has been removed by reverting the commit adding it. * Change the fix to tv_copy the argument before returning. * Readd the two tests on crashes, and modified their expected return value. * Move the test from 'incorrect behaviour' section to 'correct behaviour section' * Add analogous tests for v:_null_dict Always copy list or dictionary to return variable If the type of input is correct (i.e. either a list or a dictionary), this should also be returned. --- test/functional/eval/null_spec.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 6fd30caec9..b67158eb22 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -42,14 +42,6 @@ describe('NULL', function() describe('list', function() -- Incorrect behaviour - -- FIXME map() should not return 0 without error - null_expr_test('does not crash map()', 'map(L, "v:val")', 0, 0) - -- FIXME map() should not return 0 without error - null_expr_test('does not crash filter()', 'filter(L, "1")', 0, 0) - -- FIXME map() should at least return L - null_expr_test('makes map() return v:_null_list', 'map(L, "v:val") is# L', 0, 0) - -- FIXME filter() should at least return L - null_expr_test('makes filter() return v:_null_list', 'map(L, "1") is# L', 0, 0) -- FIXME add() should not return 1 at all null_expr_test('does not crash add()', 'add(L, 0)', 0, 1) null_expr_test('does not crash extend()', 'extend(L, [1])', 'E742: Cannot change value of extend() argument', 0) @@ -111,6 +103,8 @@ describe('NULL', function() null_expr_test('does not crash line()', 'line(L)', 0, 0) null_expr_test('does not crash count()', 'count(L, 1)', 0, 0) null_expr_test('does not crash cursor()', 'cursor(L)', 'E474: Invalid argument', -1) + null_expr_test('does not crash map()', 'map(L, "v:val")', 0, {}) + null_expr_test('does not crash filter()', 'filter(L, "1")', 0, {}) null_expr_test('is empty', 'empty(L)', 0, 1) null_expr_test('does not crash get()', 'get(L, 1, 10)', 0, 10) null_expr_test('has zero length', 'len(L)', 0, 0) @@ -126,6 +120,8 @@ describe('NULL', function() null_expr_test('is equal to itself', 'L == L', 0, 1) null_expr_test('is not not equal to itself', 'L != L', 0, 0) null_expr_test('counts correctly', 'count([L], L)', 0, 1) + null_expr_test('makes map() return v:_null_list', 'map(L, "v:val") is# L', 0, 1) + null_expr_test('makes filter() return v:_null_list', 'filter(L, "1") is# L', 0, 1) end) describe('dict', function() it('does not crash when indexing NULL dict', function() @@ -134,5 +130,9 @@ describe('NULL', function() end) null_expr_test('makes extend error out', 'extend(D, {})', 'E742: Cannot change value of extend() argument', 0) null_expr_test('makes extend do nothing', 'extend({1: 2}, D)', 0, {['1']=2}) + null_expr_test('does not crash map()', 'map(D, "v:val")', 0, {}) + null_expr_test('does not crash filter()', 'filter(D, "1")', 0, {}) + null_expr_test('makes map() return v:_null_dict', 'map(D, "v:val") is# D', 0, 1) + null_expr_test('makes filter() return v:_null_dict', 'filter(D, "1") is# D', 0, 1) end) end) -- cgit From 274f32d42e61e6f6c76b9ca499f5b79f256a481a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Dec 2017 03:39:51 +0300 Subject: *: Start hiding list implementation Most of files, except for eval.c and eval/* were only processed by perl. --- test/functional/eval/null_spec.lua | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index b67158eb22..992bc6b39f 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -42,10 +42,6 @@ describe('NULL', function() describe('list', function() -- Incorrect behaviour - -- FIXME add() should not return 1 at all - null_expr_test('does not crash add()', 'add(L, 0)', 0, 1) - null_expr_test('does not crash extend()', 'extend(L, [1])', 'E742: Cannot change value of extend() argument', 0) - null_expr_test('does not crash extend() (second position)', 'extend([1], L)', 0, {1}) -- FIXME should be accepted by inputlist() null_expr_test('is accepted as an empty list by inputlist()', '[feedkeys("\\n"), inputlist(L)]', 'E686: Argument of inputlist() must be a List', {0, 0}) @@ -53,18 +49,12 @@ describe('NULL', function() null_expr_test('is accepted as an empty list by writefile()', ('[writefile(L, "%s"), readfile("%s")]'):format(tmpfname, tmpfname), 'E484: Can\'t open file ' .. tmpfname, {0, {}}) - -- FIXME should give error message - null_expr_test('does not crash remove()', 'remove(L, 0)', 0, 0) -- FIXME should return 0 null_expr_test('is accepted by setqflist()', 'setqflist(L)', 0, -1) -- FIXME should return 0 null_expr_test('is accepted by setloclist()', 'setloclist(1, L)', 0, -1) -- FIXME should return 0 null_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, -1) - -- FIXME should return empty list or error out - null_expr_test('is accepted by sort()', 'sort(L)', 0, 0) - -- FIXME Should return 1 - null_expr_test('is accepted by sort()', 'sort(L) is L', 0, 0) -- FIXME should not error out null_test('is accepted by :cexpr', 'cexpr L', 'Vim(cexpr):E777: String or List expected') -- FIXME should not error out @@ -80,13 +70,6 @@ describe('NULL', function() -- FIXME Should return 1 null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) - -- Crashes - - -- null_expr_test('does not crash setreg', 'setreg("x", L)', 0, 0) - -- null_expr_test('does not crash setline', 'setline(1, L)', 0, 0) - -- null_expr_test('does not crash system()', 'system("cat", L)', 0, '') - -- null_expr_test('does not crash systemlist()', 'systemlist("cat", L)', 0, {}) - -- Correct behaviour null_expr_test('does not crash append()', 'append(1, L)', 0, 0, function() eq({''}, curbufmeths.get_lines(0, -1, false)) @@ -122,6 +105,22 @@ describe('NULL', function() null_expr_test('counts correctly', 'count([L], L)', 0, 1) null_expr_test('makes map() return v:_null_list', 'map(L, "v:val") is# L', 0, 1) null_expr_test('makes filter() return v:_null_list', 'filter(L, "1") is# L', 0, 1) + null_test('is treated by :let as empty list', ':let [l] = L', 'Vim(let):E688: More targets than List items') + -- FIXME fix test results + null_expr_test('does not crash add()', 'add(L, 0)', 0, 1) + null_expr_test('makes insert() error out', 'insert(L, 1)', '', nil) + null_expr_test('does not crash remove()', 'remove(L, 0)', 0, 0) + null_expr_test('makes reverse() error out', 'reverse(L)', '', nil) + null_expr_test('is accepted by sort()', 'sort(L)', 0, 0) + null_expr_test('makes sort() return itself', 'sort(L) is L', 0, 0) + null_expr_test('does not crash extend()', 'extend(L, [1])', 'E742: Cannot change value of extend() argument', 0) + null_expr_test('does not crash extend() (second position)', 'extend([1], L)', 0, {1}) + null_expr_test('makes join() return empty string', 'join(L, "")', 0, '') + null_expr_test('makes msgpackdump() return empty list', 'msgpackdump(L)', 0, {}) + null_expr_test('does not crash system()', 'system("cat", L)', 0, '') + null_expr_test('does not crash setreg', 'setreg("x", L)', 0, 0) + null_expr_test('does not crash systemlist()', 'systemlist("cat", L)', 0, {}) + null_expr_test('does not crash setline', 'setline(1, L)', 0, 0) end) describe('dict', function() it('does not crash when indexing NULL dict', function() -- cgit From 21745d72b8c24c7f19dea5d53384da4875c43e74 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Dec 2017 03:50:52 +0300 Subject: eval: Fix inputlist() --- test/functional/eval/null_spec.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 992bc6b39f..20f9c70a41 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -42,9 +42,6 @@ describe('NULL', function() describe('list', function() -- Incorrect behaviour - -- FIXME should be accepted by inputlist() - null_expr_test('is accepted as an empty list by inputlist()', - '[feedkeys("\\n"), inputlist(L)]', 'E686: Argument of inputlist() must be a List', {0, 0}) -- FIXME should be accepted by writefile(), return {0, {}} null_expr_test('is accepted as an empty list by writefile()', ('[writefile(L, "%s"), readfile("%s")]'):format(tmpfname, tmpfname), @@ -106,6 +103,7 @@ describe('NULL', function() null_expr_test('makes map() return v:_null_list', 'map(L, "v:val") is# L', 0, 1) null_expr_test('makes filter() return v:_null_list', 'filter(L, "1") is# L', 0, 1) null_test('is treated by :let as empty list', ':let [l] = L', 'Vim(let):E688: More targets than List items') + null_expr_test('is accepted as an empty list by inputlist()', '[feedkeys("\\n"), inputlist(L)]', 0, 0) -- FIXME fix test results null_expr_test('does not crash add()', 'add(L, 0)', 0, 1) null_expr_test('makes insert() error out', 'insert(L, 1)', '', nil) -- cgit From 5c1ddb5078c90f69c7225a7b2e74ccb914dcdd6a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Dec 2017 03:54:21 +0300 Subject: eval: Fix writefile() --- test/functional/eval/null_spec.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 20f9c70a41..7452185208 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -42,10 +42,6 @@ describe('NULL', function() describe('list', function() -- Incorrect behaviour - -- FIXME should be accepted by writefile(), return {0, {}} - null_expr_test('is accepted as an empty list by writefile()', - ('[writefile(L, "%s"), readfile("%s")]'):format(tmpfname, tmpfname), - 'E484: Can\'t open file ' .. tmpfname, {0, {}}) -- FIXME should return 0 null_expr_test('is accepted by setqflist()', 'setqflist(L)', 0, -1) -- FIXME should return 0 @@ -104,6 +100,9 @@ describe('NULL', function() null_expr_test('makes filter() return v:_null_list', 'filter(L, "1") is# L', 0, 1) null_test('is treated by :let as empty list', ':let [l] = L', 'Vim(let):E688: More targets than List items') null_expr_test('is accepted as an empty list by inputlist()', '[feedkeys("\\n"), inputlist(L)]', 0, 0) + null_expr_test('is accepted as an empty list by writefile()', + ('[writefile(L, "%s"), readfile("%s")]'):format(tmpfname, tmpfname), + 0, {0, {}}) -- FIXME fix test results null_expr_test('does not crash add()', 'add(L, 0)', 0, 1) null_expr_test('makes insert() error out', 'insert(L, 1)', '', nil) -- cgit From ac4bbf55f6d6b9b252dd90fe800626850022b690 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Dec 2017 22:04:43 +0300 Subject: *: Hide list implementation in other files as well --- test/functional/eval/null_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional/eval') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 7452185208..d85f5297d2 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -118,6 +118,8 @@ describe('NULL', function() null_expr_test('does not crash setreg', 'setreg("x", L)', 0, 0) null_expr_test('does not crash systemlist()', 'systemlist("cat", L)', 0, {}) null_expr_test('does not crash setline', 'setline(1, L)', 0, 0) + null_test('does not make Neovim crash when v:oldfiles gets assigned to that', ':let v:oldfiles = L|oldfiles', 0) + -- FIXME Add test for complete(, L) end) describe('dict', function() it('does not crash when indexing NULL dict', function() -- cgit From f572bd7e4e15a99cc19244a4411c6a596309f489 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Dec 2017 22:24:11 +0300 Subject: eval,functests: Fix tests and complete() and setline() behaviour --- test/functional/eval/null_spec.lua | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index d85f5297d2..3ab9e746a4 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -67,6 +67,9 @@ describe('NULL', function() null_expr_test('does not crash append()', 'append(1, L)', 0, 0, function() eq({''}, curbufmeths.get_lines(0, -1, false)) end) + null_expr_test('does not crash setline()', 'setline(1, L)', 0, 0, function() + eq({''}, curbufmeths.get_lines(0, -1, false)) + end) null_expr_test('is identical to itself', 'L is L', 0, 1) null_expr_test('can be sliced', 'L[:]', 0, {}) null_expr_test('can be copied', 'copy(L)', 0, {}) @@ -99,17 +102,20 @@ describe('NULL', function() null_expr_test('makes map() return v:_null_list', 'map(L, "v:val") is# L', 0, 1) null_expr_test('makes filter() return v:_null_list', 'filter(L, "1") is# L', 0, 1) null_test('is treated by :let as empty list', ':let [l] = L', 'Vim(let):E688: More targets than List items') - null_expr_test('is accepted as an empty list by inputlist()', '[feedkeys("\\n"), inputlist(L)]', 0, 0) + null_expr_test('is accepted as an empty list by inputlist()', '[feedkeys("\\n"), inputlist(L)]', + 'Type number and or click with mouse (empty cancels): ', {0, 0}) null_expr_test('is accepted as an empty list by writefile()', ('[writefile(L, "%s"), readfile("%s")]'):format(tmpfname, tmpfname), 0, {0, {}}) - -- FIXME fix test results null_expr_test('does not crash add()', 'add(L, 0)', 0, 1) - null_expr_test('makes insert() error out', 'insert(L, 1)', '', nil) - null_expr_test('does not crash remove()', 'remove(L, 0)', 0, 0) - null_expr_test('makes reverse() error out', 'reverse(L)', '', nil) - null_expr_test('is accepted by sort()', 'sort(L)', 0, 0) - null_expr_test('makes sort() return itself', 'sort(L) is L', 0, 0) + null_expr_test('makes insert() error out', 'insert(L, 1)', + 'E742: Cannot change value of insert() argument', 0) + null_expr_test('does not crash remove()', 'remove(L, 0)', + 'E742: Cannot change value of remove() argument', 0) + null_expr_test('makes reverse() error out', 'reverse(L)', + 'E742: Cannot change value of reverse() argument', 0) + null_expr_test('makes sort() error out', 'sort(L)', + 'E742: Cannot change value of sort() argument', 0) null_expr_test('does not crash extend()', 'extend(L, [1])', 'E742: Cannot change value of extend() argument', 0) null_expr_test('does not crash extend() (second position)', 'extend([1], L)', 0, {1}) null_expr_test('makes join() return empty string', 'join(L, "")', 0, '') @@ -117,9 +123,12 @@ describe('NULL', function() null_expr_test('does not crash system()', 'system("cat", L)', 0, '') null_expr_test('does not crash setreg', 'setreg("x", L)', 0, 0) null_expr_test('does not crash systemlist()', 'systemlist("cat", L)', 0, {}) - null_expr_test('does not crash setline', 'setline(1, L)', 0, 0) null_test('does not make Neovim crash when v:oldfiles gets assigned to that', ':let v:oldfiles = L|oldfiles', 0) - -- FIXME Add test for complete(, L) + null_expr_test('does not make complete() crash or error out', + 'execute(":normal i\\=complete(1, L)[-1]\\n")', + '', '\n', function() + eq({''}, curbufmeths.get_lines(0, -1, false)) + end) end) describe('dict', function() it('does not crash when indexing NULL dict', function() -- cgit From 5008205a3e1eef61396e457e5091eb1341b98278 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Dec 2017 22:28:18 +0300 Subject: eval: Fix setmatches(), setqflist() and setloclist() --- test/functional/eval/null_spec.lua | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 3ab9e746a4..30c6d3d450 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -42,12 +42,6 @@ describe('NULL', function() describe('list', function() -- Incorrect behaviour - -- FIXME should return 0 - null_expr_test('is accepted by setqflist()', 'setqflist(L)', 0, -1) - -- FIXME should return 0 - null_expr_test('is accepted by setloclist()', 'setloclist(1, L)', 0, -1) - -- FIXME should return 0 - null_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, -1) -- FIXME should not error out null_test('is accepted by :cexpr', 'cexpr L', 'Vim(cexpr):E777: String or List expected') -- FIXME should not error out @@ -129,6 +123,9 @@ describe('NULL', function() '', '\n', function() eq({''}, curbufmeths.get_lines(0, -1, false)) end) + null_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, 0) + null_expr_test('is accepted by setqflist()', 'setqflist(L)', 0, 0) + null_expr_test('is accepted by setloclist()', 'setloclist(1, L)', 0, 0) end) describe('dict', function() it('does not crash when indexing NULL dict', function() -- cgit From 83f77c80c084a0390b5a6efd364b33620c9f3d10 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Dec 2017 22:33:05 +0300 Subject: quickfix: Fix :cexpr and :lexpr --- test/functional/eval/null_spec.lua | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 30c6d3d450..3f3217649b 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -40,14 +40,6 @@ describe('NULL', function() end) end describe('list', function() - -- Incorrect behaviour - - -- FIXME should not error out - null_test('is accepted by :cexpr', 'cexpr L', 'Vim(cexpr):E777: String or List expected') - -- FIXME should not error out - null_test('is accepted by :lexpr', 'lexpr L', 'Vim(lexpr):E777: String or List expected') - null_test('is accepted by :for', 'for x in L|throw x|endfor', 0) - -- Subjectable behaviour -- FIXME Should return 1 @@ -58,6 +50,7 @@ describe('NULL', function() null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) -- Correct behaviour + null_test('is accepted by :for', 'for x in L|throw x|endfor', 0) null_expr_test('does not crash append()', 'append(1, L)', 0, 0, function() eq({''}, curbufmeths.get_lines(0, -1, false)) end) @@ -126,6 +119,8 @@ describe('NULL', function() null_expr_test('is accepted by setmatches()', 'setmatches(L)', 0, 0) null_expr_test('is accepted by setqflist()', 'setqflist(L)', 0, 0) null_expr_test('is accepted by setloclist()', 'setloclist(1, L)', 0, 0) + null_test('is accepted by :cexpr', 'cexpr L', 0) + null_test('is accepted by :lexpr', 'lexpr L', 0) end) describe('dict', function() it('does not crash when indexing NULL dict', function() -- cgit From 0b03ac2cb2399a850bb71d8c0a76d0893bf503cb Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Dec 2017 22:34:32 +0300 Subject: functests: Mark islocked("v:_null_list") behaviour correct It is the same for other VAR_FIXED lists. --- test/functional/eval/null_spec.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 3f3217649b..1c1dd6fd79 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -46,10 +46,9 @@ describe('NULL', function() null_expr_test('is equal to empty list', 'L == []', 0, 0) -- FIXME Should return 1 null_expr_test('is equal to empty list (reverse order)', '[] == L', 0, 0) - -- FIXME Should return 1 - null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) -- Correct behaviour + null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) null_test('is accepted by :for', 'for x in L|throw x|endfor', 0) null_expr_test('does not crash append()', 'append(1, L)', 0, 0, function() eq({''}, curbufmeths.get_lines(0, -1, false)) -- cgit From d11884db497114bc8ac5e33964ed81165f8a50fe Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Dec 2017 23:02:19 +0300 Subject: eval: Fix uniq() crash in legacy test 055 --- test/functional/eval/null_spec.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/functional/eval') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 1c1dd6fd79..64be8fcd11 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -102,6 +102,8 @@ describe('NULL', function() 'E742: Cannot change value of reverse() argument', 0) null_expr_test('makes sort() error out', 'sort(L)', 'E742: Cannot change value of sort() argument', 0) + null_expr_test('makes uniq() error out', 'uniq(L)', + 'E742: Cannot change value of uniq() argument', 0) null_expr_test('does not crash extend()', 'extend(L, [1])', 'E742: Cannot change value of extend() argument', 0) null_expr_test('does not crash extend() (second position)', 'extend([1], L)', 0, {1}) null_expr_test('makes join() return empty string', 'join(L, "")', 0, '') -- cgit From 622d355ab46b4d9282de9db6f25701882dd8f4ab Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 10 Dec 2017 23:16:00 +0300 Subject: functests: Add some more NULL tests --- test/functional/eval/null_spec.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/functional/eval') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 64be8fcd11..14b2d964d5 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -40,6 +40,11 @@ describe('NULL', function() end) end describe('list', function() + -- Incorrect behaviour + -- FIXME Should error out with different message + null_test('makes :unlet act as if it is not a list', ':unlet L[0]', + 'Vim(unlet):E689: Can only index a List or Dictionary') + -- Subjectable behaviour -- FIXME Should return 1 @@ -48,6 +53,9 @@ describe('NULL', function() null_expr_test('is equal to empty list (reverse order)', '[] == L', 0, 0) -- Correct behaviour + null_expr_test('can be indexed with error message for empty list', 'L[0]', + 'E684: list index out of range: 0\nE15: Invalid expression: L[0]', nil) + null_expr_test('can be splice-indexed', 'L[:]', 0, {}) null_expr_test('is not locked', 'islocked("v:_null_list")', 0, 0) null_test('is accepted by :for', 'for x in L|throw x|endfor', 0) null_expr_test('does not crash append()', 'append(1, L)', 0, 0, function() -- cgit From ceb45a08858837319c8ea67b1aaeceaeb24c8510 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 11 Dec 2017 01:43:36 +0300 Subject: *: Fix test failures --- test/functional/eval/msgpack_functions_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/msgpack_functions_spec.lua b/test/functional/eval/msgpack_functions_spec.lua index b241635dfe..258d6ee059 100644 --- a/test/functional/eval/msgpack_functions_spec.lua +++ b/test/functional/eval/msgpack_functions_spec.lua @@ -628,7 +628,7 @@ describe('msgpackdump() function', function() it('fails to dump a recursive (key) map in a special dict', function() command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []}') command('call add(todump._VAL, [todump, 0])') - eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 1', + eq('Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0', exc_exec('call msgpackdump([todump])')) end) -- cgit From 1a961b57505f57130012fe4fcfda0e8009c8da45 Mon Sep 17 00:00:00 2001 From: ZyX Date: Mon, 11 Dec 2017 10:34:58 +0300 Subject: eval: Fix add() --- test/functional/eval/null_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/null_spec.lua b/test/functional/eval/null_spec.lua index 14b2d964d5..afe999e1fa 100644 --- a/test/functional/eval/null_spec.lua +++ b/test/functional/eval/null_spec.lua @@ -101,7 +101,8 @@ describe('NULL', function() null_expr_test('is accepted as an empty list by writefile()', ('[writefile(L, "%s"), readfile("%s")]'):format(tmpfname, tmpfname), 0, {0, {}}) - null_expr_test('does not crash add()', 'add(L, 0)', 0, 1) + null_expr_test('makes add() error out', 'add(L, 0)', + 'E742: Cannot change value of add() argument', 1) null_expr_test('makes insert() error out', 'insert(L, 1)', 'E742: Cannot change value of insert() argument', 0) null_expr_test('does not crash remove()', 'remove(L, 0)', -- cgit From c8a5d6181b19009e170a3497a30ce35cf288bddf Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 15 Dec 2017 02:39:46 +0300 Subject: *: Fix some problems found during review Still missing: problems in window.c, it should be possible to construct a test for them. --- test/functional/eval/interrupt_spec.lua | 61 +++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 test/functional/eval/interrupt_spec.lua (limited to 'test/functional/eval') diff --git a/test/functional/eval/interrupt_spec.lua b/test/functional/eval/interrupt_spec.lua new file mode 100644 index 0000000000..7f4ca95317 --- /dev/null +++ b/test/functional/eval/interrupt_spec.lua @@ -0,0 +1,61 @@ +local helpers = require('test.functional.helpers')(after_each) + +local command = helpers.command +local meths = helpers.meths +local clear = helpers.clear +local sleep = helpers.sleep +local wait = helpers.wait +local feed = helpers.feed +local eq = helpers.eq + +local dur +local min_dur = 8 +local len = 131072 + +describe('List support code', function() + if not pending('does not actually allows interrupting with just got_int', function() end) then return end + -- The following tests are confirmed to work with os_breakcheck() just before + -- `if (got_int) {break;}` in tv_list_copy and list_join_inner() and not to + -- work without. + setup(function() + clear() + dur = 0 + while true do + command(([[ + let rt = reltime() + let bl = range(%u) + let dur = reltimestr(reltime(rt)) + ]]):format(len)) + dur = tonumber(meths.get_var('dur')) + if dur >= min_dur then + -- print(('Using len %u, dur %g'):format(len, dur)) + break + else + len = len * 2 + end + end + end) + it('allows interrupting copy', function() + feed(':let t_rt = reltime():let t_bl = copy(bl)') + sleep(min_dur / 16 * 1000) + feed('') + wait() + command('let t_dur = reltimestr(reltime(t_rt))') + local t_dur = tonumber(meths.get_var('t_dur')) + if t_dur >= dur / 8 then + eq(nil, ('Took too long to cancel: %g >= %g'):format(t_dur, dur / 8)) + end + end) + it('allows interrupting join', function() + feed(':let t_rt = reltime():let t_j = join(bl)') + sleep(min_dur / 16 * 1000) + feed('') + wait() + command('let t_dur = reltimestr(reltime(t_rt))') + local t_dur = tonumber(meths.get_var('t_dur')) + print(('t_dur: %g'):format(t_dur)) + if t_dur >= dur / 8 then + eq(nil, ('Took too long to cancel: %g >= %g'):format(t_dur, dur / 8)) + end + end) +end) -- cgit From fb07391ce46b8bff90ef7ef073b75919a307e64c Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 15 Dec 2017 11:38:34 +0300 Subject: window: Fix matchaddpos() and enhance error reporting --- test/functional/eval/match_functions_spec.lua | 95 +++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) (limited to 'test/functional/eval') diff --git a/test/functional/eval/match_functions_spec.lua b/test/functional/eval/match_functions_spec.lua index 3150d89f62..0dc78de55e 100644 --- a/test/functional/eval/match_functions_spec.lua +++ b/test/functional/eval/match_functions_spec.lua @@ -1,9 +1,12 @@ local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') local eq = helpers.eq local clear = helpers.clear local funcs = helpers.funcs +local meths = helpers.meths local command = helpers.command +local exc_exec = helpers.exc_exec before_each(clear) @@ -59,3 +62,95 @@ describe('matchadd()', function() }}, funcs.getmatches()) end) end) + +describe('matchaddpos()', function() + it('errors out on invalid input', function() + command('hi clear PreProc') + eq('Vim(let):E5030: Empty list at position 0', + exc_exec('let val = matchaddpos("PreProc", [[]])')) + eq('Vim(let):E5030: Empty list at position 1', + exc_exec('let val = matchaddpos("PreProc", [1, v:_null_list])')) + eq('Vim(let):E5031: List or number required at position 1', + exc_exec('let val = matchaddpos("PreProc", [1, v:_null_dict])')) + end) + it('works with 0 lnum', function() + command('hi clear PreProc') + eq(4, funcs.matchaddpos('PreProc', {1}, 3, 4)) + eq({{ + group='PreProc', + pos1 = {1}, + priority=3, + id=4, + }}, funcs.getmatches()) + funcs.matchdelete(4) + eq(4, funcs.matchaddpos('PreProc', {{0}, 1}, 3, 4)) + eq({{ + group='PreProc', + pos1 = {1}, + priority=3, + id=4, + }}, funcs.getmatches()) + funcs.matchdelete(4) + eq(4, funcs.matchaddpos('PreProc', {0, 1}, 3, 4)) + eq({{ + group='PreProc', + pos1 = {1}, + priority=3, + id=4, + }}, funcs.getmatches()) + end) + it('works with negative numbers', function() + command('hi clear PreProc') + eq(4, funcs.matchaddpos('PreProc', {-10, 1}, 3, 4)) + eq({{ + group='PreProc', + pos1 = {1}, + priority=3, + id=4, + }}, funcs.getmatches()) + funcs.matchdelete(4) + eq(4, funcs.matchaddpos('PreProc', {{-10}, 1}, 3, 4)) + eq({{ + group='PreProc', + pos1 = {1}, + priority=3, + id=4, + }}, funcs.getmatches()) + funcs.matchdelete(4) + eq(4, funcs.matchaddpos('PreProc', {{2, -1}, 1}, 3, 4)) + eq({{ + group='PreProc', + pos1 = {1}, + priority=3, + id=4, + }}, funcs.getmatches()) + funcs.matchdelete(4) + eq(4, funcs.matchaddpos('PreProc', {{2, 0, -1}, 1}, 3, 4)) + eq({{ + group='PreProc', + pos1 = {1}, + priority=3, + id=4, + }}, funcs.getmatches()) + end) + it('works with zero length', function() + local screen = Screen.new(40, 5) + screen:attach() + funcs.setline(1, 'abcdef') + command('hi PreProc guifg=Red') + eq(4, funcs.matchaddpos('PreProc', {{1, 2, 0}}, 3, 4)) + eq({{ + group='PreProc', + pos1 = {1, 2, 0}, + priority=3, + id=4, + }}, funcs.getmatches()) + screen:expect([[ + ^a{1:b}cdef | + {2:~ }| + {2:~ }| + {2:~ }| + | + ]], {[1] = {foreground = Screen.colors.Red}, [2] = {bold = true, foreground = Screen.colors.Blue1}}) + end) +end) -- cgit From 023631463cfe776f71492b8d853c473d0c547647 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 16 Dec 2017 16:14:53 +0300 Subject: functests: Fix linter error --- test/functional/eval/match_functions_spec.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/match_functions_spec.lua b/test/functional/eval/match_functions_spec.lua index 0dc78de55e..7989b22b5e 100644 --- a/test/functional/eval/match_functions_spec.lua +++ b/test/functional/eval/match_functions_spec.lua @@ -4,7 +4,6 @@ local Screen = require('test.functional.ui.screen') local eq = helpers.eq local clear = helpers.clear local funcs = helpers.funcs -local meths = helpers.meths local command = helpers.command local exc_exec = helpers.exc_exec -- cgit From 8d58012786b837380e6006d38580852d9506fbc8 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 24 Oct 2017 17:38:18 -0400 Subject: test: use unix fileformat to test NULs on systemlist --- test/functional/eval/system_spec.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 7e213e2156..96212bf538 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -442,11 +442,13 @@ describe('systemlist()', function() describe('with output containing NULs', function() local fname = 'Xtest' - before_each(create_file_with_nuls(fname)) + before_each(function() + command('set ff=unix') + create_file_with_nuls(fname)() + end) after_each(delete_file(fname)) it('replaces NULs by newline characters', function() - if helpers.pending_win32(pending) then return end eq({'part1\npart2\npart3'}, eval('systemlist("cat '..fname..'")')) end) end) -- cgit From d4485f7cc0e4bab7d8ca41590956fa96d31f6aab Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Mon, 6 Nov 2017 21:00:19 -0500 Subject: win: test: check non-shell system() --- test/functional/eval/system_spec.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 96212bf538..74c3b77d91 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -89,7 +89,9 @@ describe('system()', function() end) it('does NOT run in shell', function() - if not iswin() then + if iswin() then + eq("%PATH%\n", eval("system(['powershell', '-NoProfile', '-NoLogo', '-ExecutionPolicy', 'RemoteSigned', '-Command', 'echo', '%PATH%'])")) + else eq("* $PATH %PATH%\n", eval("system(['echo', '*', '$PATH', '%PATH%'])")) end end) -- cgit From ab1e11e44fd17ffbd4c1fdb26c2b03de3c6831ae Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Wed, 3 Jan 2018 00:18:34 -0500 Subject: test: win: yes is unavailable on Windows --- test/functional/eval/system_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional/eval') diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 74c3b77d91..e2b12b6bc9 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -187,6 +187,7 @@ describe('system()', function() end) it('`yes` and is interrupted with CTRL-C', function() + if helpers.pending_win32(pending) then return end feed(':call system("yes")') screen:expect([[ | -- cgit From f8f7f9d5f5aead86541ffcd12e291b6dfb6811e5 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 15 Jan 2018 23:14:20 +0100 Subject: vim-patch:8.0.0151,3,4 #7389 vim-patch:8.0.0151 Problem: To pass buffer content to system() and systemlist() one has to first create a string or list. Solution: Allow passing a buffer number. (LemonBoy, closes vim/vim#1240) https://github.com/vim/vim/commit/12c4492dd35e0cd83c8816be2ec849b836109882 vim-patch:8.0.0153 Problem: system() test fails on MS-Windows. Solution: Deal when extra space and CR. https://github.com/vim/vim/commit/9d9c35651712b88c81f1ae11091de1fd0bbbd35c vim-patch:8.0.0154 Problem: system() test fails on OS/X. Solution: Deal with leading spaces. https://github.com/vim/vim/commit/31f19ce0a052f7c76d44a9a190e468c79cf5d56d --- test/functional/eval/system_spec.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index e2b12b6bc9..4d1630042b 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -5,6 +5,7 @@ local eq, call, clear, eval, feed_command, feed, nvim = helpers.eq, helpers.call, helpers.clear, helpers.eval, helpers.feed_command, helpers.feed, helpers.nvim local command = helpers.command +local exc_exec = helpers.exc_exec local iswin = helpers.iswin local Screen = require('test.functional.ui.screen') @@ -274,9 +275,12 @@ describe('system()', function() end) end) - describe('input passed as Number', function() - it('stringifies the input', function() - eq('1', eval('system("cat", 1)')) + describe('Number input', function() + it('is treated as a buffer id', function() + command("put ='text in buffer 1'") + eq('\ntext in buffer 1\n', eval('system("cat", 1)')) + eq('Vim(echo):E86: Buffer 42 does not exist', + exc_exec('echo system("cat", 42)')) end) end) -- cgit From 514a51ef3e63362d9d96f23930bbde5cd8581da8 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Mon, 15 Jan 2018 22:28:41 -0500 Subject: get_buffer_lines: Return a string, when requested, on invalid input Closes #7859 --- test/functional/eval/getline_spec.lua | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/functional/eval/getline_spec.lua (limited to 'test/functional/eval') diff --git a/test/functional/eval/getline_spec.lua b/test/functional/eval/getline_spec.lua new file mode 100644 index 0000000000..8082745ec0 --- /dev/null +++ b/test/functional/eval/getline_spec.lua @@ -0,0 +1,39 @@ +local helpers = require('test.functional.helpers')(after_each) + +local call = helpers.call +local clear = helpers.clear +local eq = helpers.eq +local expect = helpers.expect + +describe('getline', function() + before_each(function() + clear() + call('setline', 1, {'a', 'b', 'c'}) + expect([[ + a + b + c]]) + end) + + it('returns empty string for invalid line', function() + eq('', call('getline', -1)) + eq('', call('getline', 0)) + eq('', call('getline', 4)) + end) + + it('returns empty list for invalid range', function() + eq({}, call('getline', 2, 1)) + eq({}, call('getline', -1, 1)) + eq({}, call('getline', 4, 4)) + end) + + it('returns value of valid line', function() + eq('b', call('getline', 2)) + eq('a', call('getline', '.')) + end) + + it('returns value of valid range', function() + eq({'a', 'b'}, call('getline', 1, 2)) + eq({'a', 'b', 'c'}, call('getline', 1, 4)) + end) +end) -- cgit From 15119f943ab8c2d089f45969da06b6b58b4d0036 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 23 Jan 2018 21:33:44 +0100 Subject: test: system(): fix test For the test to be valid it should actually send input. ref #3529 ref #5241 --- test/functional/eval/system_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 4d1630042b..66d569416e 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -251,7 +251,7 @@ describe('system()', function() end) it('to backgrounded command does not crash', function() -- This is indeterminate, just exercise the codepath. May get E5677. - feed_command('call system("cat - &")') + feed_command('call system("cat - &", "input")') local v_errnum = string.match(eval("v:errmsg"), "^E%d*:") if v_errnum then eq("E5677:", v_errnum) -- cgit From 3ff92ba1ee54a9400aac143f4d98d356dc6a8321 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Tue, 23 Jan 2018 17:56:50 -0500 Subject: eval: save_tv_as_string: Correctly handle an empty string When tv_get_string_chk returns a non-NULL value, we have a valid string. Propagating an error state (*len = -1, NULL return) for an empty string is invalid. Closes #6554 --- test/functional/eval/system_spec.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'test/functional/eval') diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 66d569416e..77e7424452 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -258,6 +258,9 @@ describe('system()', function() end eq(2, eval("1+1")) -- Still alive? end) + it('works with an empty string', function() + eq("test\n", eval('system("echo test", "")')) + end) end) describe('passing a lot of input', function() -- cgit From 499c9a15531b7a0e9736a395e8d401ceab3d24d2 Mon Sep 17 00:00:00 2001 From: George Zhao Date: Wed, 24 Jan 2018 18:01:14 +0800 Subject: test/win: fix some environment assumptions #7912 fix #7909 fix #7910 --- test/functional/eval/hostname_spec.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/hostname_spec.lua b/test/functional/eval/hostname_spec.lua index 6d5b64b929..6112cf64e3 100644 --- a/test/functional/eval/hostname_spec.lua +++ b/test/functional/eval/hostname_spec.lua @@ -1,7 +1,9 @@ local helpers = require('test.functional.helpers')(after_each) +local eq = helpers.eq local ok = helpers.ok local call = helpers.call local clear = helpers.clear +local iswin = helpers.iswin describe('hostname()', function() before_each(clear) @@ -11,7 +13,8 @@ describe('hostname()', function() ok(string.len(actual) > 0) if call('executable', 'hostname') == 1 then local expected = string.gsub(call('system', 'hostname'), '[\n\r]', '') - helpers.eq(expected, actual) + eq((iswin() and expected:upper() or expected), + (iswin() and actual:upper() or actual)) end end) end) -- cgit From afbdafffc2980c2879393ef03fc3edac49282ea7 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 9 Jan 2018 01:06:59 +0100 Subject: test: fnamemodify() --- test/functional/eval/fnamemodify_spec.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/functional/eval/fnamemodify_spec.lua (limited to 'test/functional/eval') diff --git a/test/functional/eval/fnamemodify_spec.lua b/test/functional/eval/fnamemodify_spec.lua new file mode 100644 index 0000000000..4f86626a1e --- /dev/null +++ b/test/functional/eval/fnamemodify_spec.lua @@ -0,0 +1,21 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear +local eq = helpers.eq +local iswin = helpers.iswin +local fnamemodify = helpers.funcs.fnamemodify + +describe('fnamemodify()', function() + before_each(clear) + + it('works', function() + if iswin() then + eq([[C:\]], fnamemodify([[\]], ':p:h')) + eq([[C:\]], fnamemodify([[\]], ':p')) + eq([[C:/]], fnamemodify([[/]], ':p:h')) + eq([[C:/]], fnamemodify([[/]], ':p')) + else + eq('/', fnamemodify([[/]], ':p:h')) + eq('/', fnamemodify([[/]], ':p')) + end + end) +end) -- cgit From a619c3fcf92e45e27066c472c3c9a0a1a2901b4d Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 11 Jan 2018 11:05:15 -0500 Subject: test: win: add tests for shellslash --- test/functional/eval/fnamemodify_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/eval') diff --git a/test/functional/eval/fnamemodify_spec.lua b/test/functional/eval/fnamemodify_spec.lua index 4f86626a1e..f3705d6c99 100644 --- a/test/functional/eval/fnamemodify_spec.lua +++ b/test/functional/eval/fnamemodify_spec.lua @@ -3,6 +3,7 @@ local clear = helpers.clear local eq = helpers.eq local iswin = helpers.iswin local fnamemodify = helpers.funcs.fnamemodify +local command = helpers.command describe('fnamemodify()', function() before_each(clear) @@ -11,6 +12,11 @@ describe('fnamemodify()', function() if iswin() then eq([[C:\]], fnamemodify([[\]], ':p:h')) eq([[C:\]], fnamemodify([[\]], ':p')) + eq([[C:\]], fnamemodify([[/]], ':p:h')) + eq([[C:\]], fnamemodify([[/]], ':p')) + command('set shellslash') + eq([[C:/]], fnamemodify([[\]], ':p:h')) + eq([[C:/]], fnamemodify([[\]], ':p')) eq([[C:/]], fnamemodify([[/]], ':p:h')) eq([[C:/]], fnamemodify([[/]], ':p')) else -- cgit From 534abe4aafc2fb75a100c6193a8fdf5bfa0838dc Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 11 Jan 2018 17:31:29 -0500 Subject: test: win: get current network drive via io.popen --- test/functional/eval/fnamemodify_spec.lua | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/fnamemodify_spec.lua b/test/functional/eval/fnamemodify_spec.lua index f3705d6c99..21e670c41c 100644 --- a/test/functional/eval/fnamemodify_spec.lua +++ b/test/functional/eval/fnamemodify_spec.lua @@ -9,16 +9,22 @@ describe('fnamemodify()', function() before_each(clear) it('works', function() + local drive_f = io.popen('cd', 'r') + local drive = string.gsub(drive_f:read('*a'), '[\n\r]', '') + drive_f:close() + if iswin() then - eq([[C:\]], fnamemodify([[\]], ':p:h')) - eq([[C:\]], fnamemodify([[\]], ':p')) - eq([[C:\]], fnamemodify([[/]], ':p:h')) - eq([[C:\]], fnamemodify([[/]], ':p')) + local root = drive..[[\]] + eq(root, fnamemodify([[\]], ':p:h')) + eq(root, fnamemodify([[\]], ':p')) + eq(root, fnamemodify([[/]], ':p:h')) + eq(root, fnamemodify([[/]], ':p')) command('set shellslash') - eq([[C:/]], fnamemodify([[\]], ':p:h')) - eq([[C:/]], fnamemodify([[\]], ':p')) - eq([[C:/]], fnamemodify([[/]], ':p:h')) - eq([[C:/]], fnamemodify([[/]], ':p')) + root = drive..[[/]] + eq(root, fnamemodify([[\]], ':p:h')) + eq(root, fnamemodify([[\]], ':p')) + eq(root, fnamemodify([[/]], ':p:h')) + eq(root, fnamemodify([[/]], ':p')) else eq('/', fnamemodify([[/]], ':p:h')) eq('/', fnamemodify([[/]], ':p')) -- cgit From eb59dd654759c3ecde7bea22e2651713e29d0912 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 11 Jan 2018 19:16:39 -0500 Subject: fixup: get network drive only, not entire path --- test/functional/eval/fnamemodify_spec.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/fnamemodify_spec.lua b/test/functional/eval/fnamemodify_spec.lua index 21e670c41c..2225c5da7c 100644 --- a/test/functional/eval/fnamemodify_spec.lua +++ b/test/functional/eval/fnamemodify_spec.lua @@ -9,11 +9,10 @@ describe('fnamemodify()', function() before_each(clear) it('works', function() - local drive_f = io.popen('cd', 'r') - local drive = string.gsub(drive_f:read('*a'), '[\n\r]', '') - drive_f:close() - if iswin() then + local drive_f = io.popen('for %P in (%CD%) do @echo %~dP', 'r') + local drive = string.gsub(drive_f:read('*a'), '[\n\r]', '') + drive_f:close() local root = drive..[[\]] eq(root, fnamemodify([[\]], ':p:h')) eq(root, fnamemodify([[\]], ':p')) -- cgit From 5a39d2d00e398b404b4db7ec45b2f490d5bb845e Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 13 Jan 2018 08:25:11 -0500 Subject: test: fnamemodify with :8 filename modifier --- test/functional/eval/fnamemodify_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional/eval') diff --git a/test/functional/eval/fnamemodify_spec.lua b/test/functional/eval/fnamemodify_spec.lua index 2225c5da7c..52dfe1a55f 100644 --- a/test/functional/eval/fnamemodify_spec.lua +++ b/test/functional/eval/fnamemodify_spec.lua @@ -4,10 +4,19 @@ local eq = helpers.eq local iswin = helpers.iswin local fnamemodify = helpers.funcs.fnamemodify local command = helpers.command +local write_file = helpers.write_file describe('fnamemodify()', function() + setup(function() + write_file('Xtest-fnamemodify.txt', [[foobar]]) + end) + before_each(clear) + teardown(function() + os.remove('Xtest-fnamemodify.txt') + end) + it('works', function() if iswin() then local drive_f = io.popen('for %P in (%CD%) do @echo %~dP', 'r') @@ -29,4 +38,8 @@ describe('fnamemodify()', function() eq('/', fnamemodify([[/]], ':p')) end end) + + it(':8 works', function() + eq('Xtest-fnamemodify.txt', fnamemodify([[Xtest-fnamemodify.txt]], ':8')) + end) end) -- cgit From 41b3c7850f839b46affe35bf2de92bc18113b0f7 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Mon, 29 Jan 2018 00:05:25 -0500 Subject: test: use helpers.pathroot() to avoid a syscall --- test/functional/eval/fnamemodify_spec.lua | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/fnamemodify_spec.lua b/test/functional/eval/fnamemodify_spec.lua index 52dfe1a55f..fe6b50a544 100644 --- a/test/functional/eval/fnamemodify_spec.lua +++ b/test/functional/eval/fnamemodify_spec.lua @@ -18,24 +18,18 @@ describe('fnamemodify()', function() end) it('works', function() + local root = helpers.pathroot() + eq(root, fnamemodify([[/]], ':p:h')) + eq(root, fnamemodify([[/]], ':p')) if iswin() then - local drive_f = io.popen('for %P in (%CD%) do @echo %~dP', 'r') - local drive = string.gsub(drive_f:read('*a'), '[\n\r]', '') - drive_f:close() - local root = drive..[[\]] eq(root, fnamemodify([[\]], ':p:h')) eq(root, fnamemodify([[\]], ':p')) - eq(root, fnamemodify([[/]], ':p:h')) - eq(root, fnamemodify([[/]], ':p')) command('set shellslash') - root = drive..[[/]] + root = string.sub(root, 1, -2)..'/' eq(root, fnamemodify([[\]], ':p:h')) eq(root, fnamemodify([[\]], ':p')) eq(root, fnamemodify([[/]], ':p:h')) eq(root, fnamemodify([[/]], ':p')) - else - eq('/', fnamemodify([[/]], ':p:h')) - eq('/', fnamemodify([[/]], ':p')) end end) -- cgit From 5d2dd2ebe28c31f223d77355a8f9d40adfb41c82 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Wed, 27 Sep 2017 13:38:24 -0500 Subject: win: has("wsl") on Windows Subsystem for Linux #7330 Per CMAKE docs, CMAKE_HOST_SYSTEM_VERSION is the result of `uname -r`: https://cmake.org/cmake/help/v3.4/variable/CMAKE_HOST_SYSTEM_VERSION.html?highlight=uname A numeric version string for the system. On systems that support uname, this variable is set to the output of uname -r. On other systems this is set to major-minor version numbers. On Windows it is something like "6.1", so it won't match ".*-Microsoft". Closes #7329 --- test/functional/eval/has_spec.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'test/functional/eval') diff --git a/test/functional/eval/has_spec.lua b/test/functional/eval/has_spec.lua index 78c4e08fde..a3af2d1a20 100644 --- a/test/functional/eval/has_spec.lua +++ b/test/functional/eval/has_spec.lua @@ -57,4 +57,10 @@ describe('has()', function() eq(0, funcs.has("unnamedplus")) end end) + + it('"wsl"', function() + if 1 == funcs.has('win32') or 1 == funcs.has('mac') then + eq(0, funcs.has('wsl')) + end + end) end) -- cgit From 648fed975eb8ddde9c5cbc0f859d06deebf80dd9 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 31 Jan 2018 10:25:51 +0100 Subject: os_system(): do not set up input stream for empty string #7951 Test failure: test/functional/eval/system_spec.lua: "works with an empty string" E5677: Error writing input to shell-command: EPIPE ref https://github.com/neovim/neovim/pull/6558#issuecomment-361061035 ref #6554 --- test/functional/eval/system_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional/eval') diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 77e7424452..7fe79d4351 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -260,6 +260,7 @@ describe('system()', function() end) it('works with an empty string', function() eq("test\n", eval('system("echo test", "")')) + eq(2, eval("1+1")) -- Still alive? end) end) -- cgit From f8010ea3eca77961312afeb96234678447ce17e4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 1 Feb 2018 03:12:37 +0100 Subject: test: robust cleanup, unique filenames #7950 (#7950) Use unique filenames to avoid test conflicts. Use read_file() instead of io.popen(), to ensures the file is closed. Use helpers.rmdir(), it is far more robust than lfs. closes #7911 --- test/functional/eval/buf_functions_spec.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/buf_functions_spec.lua b/test/functional/eval/buf_functions_spec.lua index db50874c53..7de58766b9 100644 --- a/test/functional/eval/buf_functions_spec.lua +++ b/test/functional/eval/buf_functions_spec.lua @@ -14,6 +14,7 @@ local curbufmeths = helpers.curbufmeths local curwinmeths = helpers.curwinmeths local curtabmeths = helpers.curtabmeths local get_pathsep = helpers.get_pathsep +local rmdir = helpers.rmdir local fname = 'Xtest-functional-eval-buf_functions' local fname2 = fname .. '.2' @@ -61,7 +62,7 @@ describe('bufname() function', function() lfs.mkdir(dirname) end) after_each(function() - lfs.rmdir(dirname) + rmdir(dirname) end) it('returns expected buffer name', function() eq('', funcs.bufname('%')) -- Buffer has no name yet @@ -143,7 +144,7 @@ describe('bufwinnr() function', function() lfs.mkdir(dirname) end) after_each(function() - lfs.rmdir(dirname) + rmdir(dirname) end) it('returns expected window number', function() eq(1, funcs.bufwinnr('%')) -- cgit From 4e7d85e6356d88944a60c447a9754b8b37407c12 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 21 Jan 2018 19:58:19 +0100 Subject: shell: update `execute('!cmd')` test to new behavior And similarly nvim_command_output test --- test/functional/eval/execute_spec.lua | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/execute_spec.lua b/test/functional/eval/execute_spec.lua index 91966ed3dd..c866359520 100644 --- a/test/functional/eval/execute_spec.lua +++ b/test/functional/eval/execute_spec.lua @@ -1,4 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) +local global_helpers = require('test.helpers') local eq = helpers.eq local eval = helpers.eval local clear = helpers.clear @@ -9,6 +10,7 @@ local funcs = helpers.funcs local Screen = require('test.functional.ui.screen') local command = helpers.command local feed = helpers.feed +local uname = global_helpers.uname describe('execute()', function() before_each(clear) @@ -118,9 +120,11 @@ describe('execute()', function() feed('') end) - -- This matches Vim behavior. - it('does not capture shell-command output', function() - eq('\n:!echo "foo"\13\n', funcs.execute('!echo "foo"')) + -- This deviates from vim behavior, but is consistent + -- with how nvim currently displays the output. + it('does capture shell-command output', function() + local win_lf = (uname() == 'Windows' and '\13') or '' + eq('\n:!echo foo\r\n\nfoo'..win_lf..'\n', funcs.execute('!echo foo')) end) describe('{silent} argument', function() -- cgit From 352a51e8313d05c4701f468a79540a2410c77b23 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 10 May 2017 15:04:49 +0200 Subject: test: :! print binary data, control chars closes #5442 closes #4142 ref #6618 ref #4376 ref #7844 ref #2958 ref #4338 --- test/functional/eval/execute_spec.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/execute_spec.lua b/test/functional/eval/execute_spec.lua index c866359520..183884a51e 100644 --- a/test/functional/eval/execute_spec.lua +++ b/test/functional/eval/execute_spec.lua @@ -1,5 +1,4 @@ local helpers = require('test.functional.helpers')(after_each) -local global_helpers = require('test.helpers') local eq = helpers.eq local eval = helpers.eval local clear = helpers.clear @@ -10,7 +9,7 @@ local funcs = helpers.funcs local Screen = require('test.functional.ui.screen') local command = helpers.command local feed = helpers.feed -local uname = global_helpers.uname +local iswin = helpers.iswin describe('execute()', function() before_each(clear) @@ -123,7 +122,7 @@ describe('execute()', function() -- This deviates from vim behavior, but is consistent -- with how nvim currently displays the output. it('does capture shell-command output', function() - local win_lf = (uname() == 'Windows' and '\13') or '' + local win_lf = iswin() and '\13' or '' eq('\n:!echo foo\r\n\nfoo'..win_lf..'\n', funcs.execute('!echo foo')) end) -- cgit From c03a847884c017a78e099beaa1b252e5f940c8e0 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 3 Oct 2017 17:39:17 -0400 Subject: win: enable backtick_expansion and shell output tests --- test/functional/eval/backtick_expansion_spec.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/backtick_expansion_spec.lua b/test/functional/eval/backtick_expansion_spec.lua index 81e8e295fa..b1b44cfa8b 100644 --- a/test/functional/eval/backtick_expansion_spec.lua +++ b/test/functional/eval/backtick_expansion_spec.lua @@ -21,11 +21,19 @@ describe("backtick expansion", function() end) it("with default 'shell'", function() - if helpers.pending_win32(pending) then return end -- Need win32 shell fixes - command(":silent args `echo ***2`") + if helpers.iswin() then + command(":silent args `dir /b *2`") + else + command(":silent args `echo ***2`") + end eq({ "file2", }, eval("argv()")) - command(":silent args `echo */*4`") - eq({ "subdir/file4", }, eval("argv()")) + if helpers.iswin() then + command(":silent args `dir /s/b *4`") + eq({ "subdir\\file4", }, eval("map(argv(), 'fnamemodify(v:val, \":.\")')")) + else + command(":silent args `echo */*4`") + eq({ "subdir/file4", }, eval("argv()")) + end end) it("with shell=fish", function() -- cgit From 6e5cb0debd23693175bd05409d3f1af4015567df Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 13 Feb 2018 13:45:49 +0100 Subject: ui: refactor ui options --- test/functional/eval/api_functions_spec.lua | 3 ++- test/functional/eval/msgpack_functions_spec.lua | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/api_functions_spec.lua b/test/functional/eval/api_functions_spec.lua index fea4a87a26..6f440c7d82 100644 --- a/test/functional/eval/api_functions_spec.lua +++ b/test/functional/eval/api_functions_spec.lua @@ -106,7 +106,8 @@ describe('api functions', function() it('have metadata accessible with api_info()', function() local api_keys = eval("sort(keys(api_info()))") - eq({'error_types', 'functions', 'types', 'ui_events', 'version'}, api_keys) + eq({'error_types', 'functions', 'types', + 'ui_events', 'ui_options', 'version'}, api_keys) end) it('are highlighted by vim.vim syntax file', function() diff --git a/test/functional/eval/msgpack_functions_spec.lua b/test/functional/eval/msgpack_functions_spec.lua index 258d6ee059..a8a413f68b 100644 --- a/test/functional/eval/msgpack_functions_spec.lua +++ b/test/functional/eval/msgpack_functions_spec.lua @@ -463,7 +463,8 @@ describe('msgpackparse() function', function() eval(cmd) eval(cmd) -- do it again (try to force segfault) local api_info = eval(cmd) -- do it again - eq({'error_types', 'functions', 'types', 'ui_events', 'version'}, api_info) + eq({'error_types', 'functions', 'types', + 'ui_events', 'ui_options', 'version'}, api_info) end) it('fails when called with no arguments', function() -- cgit From 795da343bbf99c4b77d10cd5035c29df23f113ae Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 17 Feb 2018 02:25:51 -0500 Subject: test: win: emulate yes with for loop --- test/functional/eval/system_spec.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 7fe79d4351..446afefb59 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -188,8 +188,9 @@ describe('system()', function() end) it('`yes` and is interrupted with CTRL-C', function() - if helpers.pending_win32(pending) then return end - feed(':call system("yes")') + feed(':call system("' .. (iswin() + and 'for /L %I in (1,0,2) do @echo y' + or 'yes') .. '")') screen:expect([[ | ~ | @@ -204,8 +205,11 @@ describe('system()', function() ~ | ~ | ~ | - :call system("yes") | - ]]) +]] .. (iswin() + and [[ + :call system("for /L %I in (1,0,2) do @echo y") |]] + or [[ + :call system("yes") |]])) feed('') screen:expect([[ ^ | -- cgit From 131aad953c007d382cbff1d2560471b29975da87 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 30 Sep 2017 21:31:31 -0400 Subject: win: defaults: 'shellcmdflag', 'shellxquote' #7343 closes #7698 Wrapping a command in double-quotes allows cmd.exe to safely dequote the entire command as if the user entered the entire command in an interactive prompt. This reduces the need to escape nested and uneven double quotes. The `/s` flag of cmd.exe makes the behaviour more reliable: :set shellcmdflag=/s\ /c Before this patch, cmd.exe cannot use cygwin echo.exe (as opposed to cmd.exe `echo` builtin) even if it is wrapped in double quotes. Example: :: internal echo > cmd /s /c " echo foo\:bar" " foo\:bar" :: cygwin echo.exe > cmd /s /c " "echo" foo\:bar" " foo:bar --- test/functional/eval/system_spec.lua | 40 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/system_spec.lua b/test/functional/eval/system_spec.lua index 446afefb59..201426c40b 100644 --- a/test/functional/eval/system_spec.lua +++ b/test/functional/eval/system_spec.lua @@ -120,33 +120,47 @@ describe('system()', function() end end) - describe('executes shell function if passed a string', function() + describe('executes shell function', function() local screen before_each(function() - clear() - screen = Screen.new() - screen:attach() + clear() + screen = Screen.new() + screen:attach() end) after_each(function() - screen:detach() + screen:detach() end) if iswin() then + local function test_more() + eq('root = true', eval([[get(split(system('"more" ".editorconfig"'), "\n"), 0, '')]])) + end + local function test_shell_unquoting() + eval([[system('"ping" "-n" "1" "127.0.0.1"')]]) + eq(0, eval('v:shell_error')) + eq('"a b"\n', eval([[system('cmd /s/c "cmd /s/c "cmd /s/c "echo "a b""""')]])) + eq('"a b"\n', eval([[system('powershell -NoProfile -NoLogo -ExecutionPolicy RemoteSigned -Command echo ''\^"a b\^"''')]])) + end + it('with shell=cmd.exe', function() command('set shell=cmd.exe') eq('""\n', eval([[system('echo ""')]])) eq('"a b"\n', eval([[system('echo "a b"')]])) eq('a \nb\n', eval([[system('echo a & echo b')]])) eq('a \n', eval([[system('echo a 2>&1')]])) + test_more() eval([[system('cd "C:\Program Files"')]]) eq(0, eval('v:shell_error')) + test_shell_unquoting() end) it('with shell=cmd', function() command('set shell=cmd') eq('"a b"\n', eval([[system('echo "a b"')]])) + test_more() + test_shell_unquoting() end) it('with shell=$COMSPEC', function() @@ -154,6 +168,8 @@ describe('system()', function() if comspecshell == 'cmd.exe' then command('set shell=$COMSPEC') eq('"a b"\n', eval([[system('echo "a b"')]])) + test_more() + test_shell_unquoting() else pending('$COMSPEC is not cmd.exe: ' .. comspecshell) end @@ -187,7 +203,7 @@ describe('system()', function() ]]) end) - it('`yes` and is interrupted with CTRL-C', function() + it('`yes` interrupted with CTRL-C', function() feed(':call system("' .. (iswin() and 'for /L %I in (1,0,2) do @echo y' or 'yes') .. '")') @@ -239,6 +255,8 @@ describe('system()', function() end end) it('to backgrounded command does not crash', function() + -- cmd.exe doesn't background a command with & + if iswin() then return end -- This is indeterminate, just exercise the codepath. May get E5677. feed_command('call system("echo -n echoed &")') local v_errnum = string.match(eval("v:errmsg"), "^E%d*:") @@ -254,6 +272,8 @@ describe('system()', function() eq("input", eval('system("cat -", "input")')) end) it('to backgrounded command does not crash', function() + -- cmd.exe doesn't background a command with & + if iswin() then return end -- This is indeterminate, just exercise the codepath. May get E5677. feed_command('call system("cat - &", "input")') local v_errnum = string.match(eval("v:errmsg"), "^E%d*:") @@ -299,7 +319,7 @@ describe('system()', function() after_each(delete_file(fname)) it('replaces NULs by SOH characters', function() - eq('part1\001part2\001part3\n', eval('system("cat '..fname..'")')) + eq('part1\001part2\001part3\n', eval([[system('"cat" "]]..fname..[["')]])) end) end) @@ -366,7 +386,7 @@ describe('systemlist()', function() end end) - describe('exectues shell function', function() + describe('executes shell function', function() local screen before_each(function() @@ -399,7 +419,7 @@ describe('systemlist()', function() ]]) end) - it('`yes` and is interrupted with CTRL-C', function() + it('`yes` interrupted with CTRL-C', function() feed(':call systemlist("yes | xargs")') screen:expect([[ | @@ -464,7 +484,7 @@ describe('systemlist()', function() after_each(delete_file(fname)) it('replaces NULs by newline characters', function() - eq({'part1\npart2\npart3'}, eval('systemlist("cat '..fname..'")')) + eq({'part1\npart2\npart3'}, eval([[systemlist('"cat" "]]..fname..[["')]])) end) end) -- cgit From 98e71123900fbdf26a16a43297a1f58118cde41b Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 31 Mar 2018 11:12:27 +0200 Subject: msg: do not scroll entire screen (#8088) --- test/functional/eval/execute_spec.lua | 16 +++++++++++----- test/functional/eval/input_spec.lua | 25 +++++++++++++------------ 2 files changed, 24 insertions(+), 17 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/execute_spec.lua b/test/functional/eval/execute_spec.lua index 183884a51e..925e311c7d 100644 --- a/test/functional/eval/execute_spec.lua +++ b/test/functional/eval/execute_spec.lua @@ -106,16 +106,22 @@ describe('execute()', function() end) it('does not corrupt the command display #5422', function() - local screen = Screen.new(70, 5) + local screen = Screen.new(70, 7) screen:attach() feed(':echo execute("hi ErrorMsg")') screen:expect([[ - ~ | - ~ | + | + {1:~ }| + {1:~ }| + {2: }| :echo execute("hi ErrorMsg") | ErrorMsg xxx ctermfg=15 ctermbg=1 guifg=White guibg=Red | - Press ENTER or type command to continue^ | - ]]) + {3:Press ENTER or type command to continue}^ | + ]], { + [1] = {bold = true, foreground = Screen.colors.Blue1}, + [2] = {bold = true, reverse = true}, + [3] = {bold = true, foreground = Screen.colors.SeaGreen4}, + }) feed('') end) diff --git a/test/functional/eval/input_spec.lua b/test/functional/eval/input_spec.lua index 1e6b107c60..777f49462d 100644 --- a/test/functional/eval/input_spec.lua +++ b/test/functional/eval/input_spec.lua @@ -58,6 +58,7 @@ before_each(function() RBP2={background=Screen.colors.Yellow}, RBP3={background=Screen.colors.Green}, RBP4={background=Screen.colors.Blue}, + SEP={bold = true, reverse = true}, }) end) @@ -65,9 +66,9 @@ describe('input()', function() it('works with multiline prompts', function() feed([[:call input("Test\nFoo")]]) screen:expect([[ + | {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {SEP: }| Test | Foo^ | ]]) @@ -75,9 +76,9 @@ describe('input()', function() it('works with multiline prompts and :echohl', function() feed([[:echohl Test | call input("Test\nFoo")]]) screen:expect([[ + | {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {SEP: }| {T:Test} | {T:Foo}^ | ]]) @@ -242,17 +243,17 @@ describe('input()', function() it('is not hidden by :silent', function() feed([[:silent call input('Foo: ')]]) screen:expect([[ + | {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {SEP: }| Foo: ^ | | ]]) feed('Bar') screen:expect([[ + | {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {SEP: }| Foo: Bar^ | | ]]) @@ -263,9 +264,9 @@ describe('inputdialog()', function() it('works with multiline prompts', function() feed([[:call inputdialog("Test\nFoo")]]) screen:expect([[ + | {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {SEP: }| Test | Foo^ | ]]) @@ -273,9 +274,9 @@ describe('inputdialog()', function() it('works with multiline prompts and :echohl', function() feed([[:echohl Test | call inputdialog("Test\nFoo")]]) screen:expect([[ + | {EOB:~ }| - {EOB:~ }| - {EOB:~ }| + {SEP: }| {T:Test} | {T:Foo}^ | ]]) -- cgit From 9f598e57656fe072114b9f1e73d3051423e13234 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 8 Apr 2018 13:06:26 +0200 Subject: serverstop(): return FALSE for invalid address --- test/functional/eval/server_spec.lua | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/server_spec.lua b/test/functional/eval/server_spec.lua index 393616838e..edd63fe83c 100644 --- a/test/functional/eval/server_spec.lua +++ b/test/functional/eval/server_spec.lua @@ -11,21 +11,21 @@ local function clear_serverlist() end end -describe('serverstart(), serverstop()', function() +describe('server', function() before_each(clear) - it('sets $NVIM_LISTEN_ADDRESS on first invocation', function() + it('serverstart() sets $NVIM_LISTEN_ADDRESS on first invocation', function() -- Unset $NVIM_LISTEN_ADDRESS command('let $NVIM_LISTEN_ADDRESS = ""') local s = eval('serverstart()') assert(s ~= nil and s:len() > 0, "serverstart() returned empty") eq(s, eval('$NVIM_LISTEN_ADDRESS')) - command("call serverstop('"..s.."')") + eq(1, eval("serverstop('"..s.."')")) eq('', eval('$NVIM_LISTEN_ADDRESS')) end) - it('sets v:servername _only_ on nvim startup unless all servers are stopped', + it('serverstart() sets v:servername at startup or if all servers were stopped', function() local initial_server = meths.get_vvar('servername') assert(initial_server ~= nil and initial_server:len() > 0, @@ -38,11 +38,11 @@ describe('serverstart(), serverstop()', function() neq(initial_server, s) -- serverstop() does _not_ modify v:servername... - funcs.serverstop(s) + eq(1, funcs.serverstop(s)) eq(initial_server, meths.get_vvar('servername')) -- ...unless we stop _all_ servers. - funcs.serverstop(funcs.serverlist()[1]) + eq(1, funcs.serverstop(funcs.serverlist()[1])) eq('', meths.get_vvar('servername')) -- v:servername will take the next available server. @@ -53,9 +53,9 @@ describe('serverstart(), serverstop()', function() eq(servername, meths.get_vvar('servername')) end) - it('serverstop() ignores invalid input', function() - command("call serverstop('')") - command("call serverstop('bogus-socket-name')") + it('serverstop() returns false for invalid input', function() + eq(0, eval("serverstop('')")) + eq(0, eval("serverstop('bogus-socket-name')")) end) it('parses endpoints correctly', function() @@ -120,7 +120,7 @@ describe('serverlist()', function() -- The new servers should be at the end of the list. for i = 1, #servs do eq(servs[i], new_servs[i + n]) - command("call serverstop('"..servs[i].."')") + eq(1, eval("serverstop('"..servs[i].."')")) end -- After serverstop() the servers should NOT be in the list. eq(n, eval('len(serverlist())')) -- cgit From 507bda1c95cdac2886f64e59aa6bbf85c3fac389 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 8 Apr 2018 17:20:25 +0200 Subject: server: introduce --listen, deprecate $NVIM_LISTEN_ADDRESS --- test/functional/eval/server_spec.lua | 38 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/server_spec.lua b/test/functional/eval/server_spec.lua index edd63fe83c..a2644498f2 100644 --- a/test/functional/eval/server_spec.lua +++ b/test/functional/eval/server_spec.lua @@ -1,14 +1,14 @@ - local helpers = require('test.functional.helpers')(after_each) local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval local command = helpers.command local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths +local ok = helpers.ok local os_name = helpers.os_name local function clear_serverlist() - for _, server in pairs(funcs.serverlist()) do - funcs.serverstop(server) - end + for _, server in pairs(funcs.serverlist()) do + funcs.serverstop(server) + end end describe('server', function() @@ -96,16 +96,12 @@ describe('server', function() funcs.serverstart('127.0.0.1:65536') -- invalid port eq({}, funcs.serverlist()) end) -end) -describe('serverlist()', function() - before_each(clear) - - it('returns the list of servers', function() + it('serverlist() returns the list of servers', function() -- There should already be at least one server. local n = eval('len(serverlist())') - -- Add a few + -- Add some servers. local servs = (os_name() == 'windows' and { [[\\.\pipe\Xtest-pipe0934]], [[\\.\pipe\Xtest-pipe4324]] } or { [[Xtest-pipe0934]], [[Xtest-pipe4324]] }) @@ -126,3 +122,25 @@ describe('serverlist()', function() eq(n, eval('len(serverlist())')) end) end) + +describe('startup --listen', function() + it('validates', function() + clear() + + local cmd = { unpack(helpers.nvim_argv) } + table.insert(cmd, '--listen') + eq('nvim: Argument missing after: "--listen"', + string.match(funcs.system(cmd), '.-n"')) + + cmd = { unpack(helpers.nvim_argv) } + table.insert(cmd, '--listen2') + eq('nvim: Garbage after option argument: "--listen2"', + string.match(funcs.system(cmd), '.-2"')) + end) + + it('sets v:servername, overrides $NVIM_LISTEN_ADDRESS', function() + clear({ env={ NVIM_LISTEN_ADDRESS='Xtest-env-pipe' }, + args={ '--listen', 'Xtest-listen-pipe' } }) + eq('Xtest-listen-pipe', meths.get_vvar('servername')) + end) +end) -- cgit From 704ba4151e7f67999510ee0ac19fdabb595d530c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 11 Apr 2018 00:01:43 +0200 Subject: server: init v:servername if $NVIM_LISTEN_ADDRESS is invalid Before this change, if $NVIM_LISTEN_ADDRESS was invalid, v:servername was left empty. --- test/functional/eval/server_spec.lua | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'test/functional/eval') diff --git a/test/functional/eval/server_spec.lua b/test/functional/eval/server_spec.lua index a2644498f2..4e4aed864b 100644 --- a/test/functional/eval/server_spec.lua +++ b/test/functional/eval/server_spec.lua @@ -2,8 +2,9 @@ local helpers = require('test.functional.helpers')(after_each) local eq, neq, eval = helpers.eq, helpers.neq, helpers.eval local command = helpers.command local clear, funcs, meths = helpers.clear, helpers.funcs, helpers.meths +local iswin = helpers.iswin local ok = helpers.ok -local os_name = helpers.os_name +local matches = helpers.matches local function clear_serverlist() for _, server in pairs(funcs.serverlist()) do @@ -25,7 +26,15 @@ describe('server', function() eq('', eval('$NVIM_LISTEN_ADDRESS')) end) - it('serverstart() sets v:servername at startup or if all servers were stopped', + it('sets new v:servername if $NVIM_LISTEN_ADDRESS is invalid', function() + clear({env={NVIM_LISTEN_ADDRESS='.'}}) + eq('.', eval('$NVIM_LISTEN_ADDRESS')) + local servers = funcs.serverlist() + eq(1, #servers) + ok(string.len(servers[1]) > 4) -- Like /tmp/nvim…/… or \\.\pipe\… + end) + + it('sets v:servername at startup or if all servers were stopped', function() local initial_server = meths.get_vvar('servername') assert(initial_server ~= nil and initial_server:len() > 0, @@ -46,9 +55,8 @@ describe('server', function() eq('', meths.get_vvar('servername')) -- v:servername will take the next available server. - local servername = (os_name() == 'windows' - and [[\\.\pipe\Xtest-functional-server-pipe]] - or 'Xtest-functional-server-socket') + local servername = (iswin() and [[\\.\pipe\Xtest-functional-server-pipe]] + or 'Xtest-functional-server-socket') funcs.serverstart(servername) eq(servername, meths.get_vvar('servername')) end) @@ -102,7 +110,7 @@ describe('server', function() local n = eval('len(serverlist())') -- Add some servers. - local servs = (os_name() == 'windows' + local servs = (iswin() and { [[\\.\pipe\Xtest-pipe0934]], [[\\.\pipe\Xtest-pipe4324]] } or { [[Xtest-pipe0934]], [[Xtest-pipe4324]] }) for _, s in ipairs(servs) do @@ -129,18 +137,18 @@ describe('startup --listen', function() local cmd = { unpack(helpers.nvim_argv) } table.insert(cmd, '--listen') - eq('nvim: Argument missing after: "--listen"', - string.match(funcs.system(cmd), '.-n"')) + matches('nvim.*: Argument missing after: "%-%-listen"', funcs.system(cmd)) cmd = { unpack(helpers.nvim_argv) } table.insert(cmd, '--listen2') - eq('nvim: Garbage after option argument: "--listen2"', - string.match(funcs.system(cmd), '.-2"')) + matches('nvim.*: Garbage after option argument: "%-%-listen2"', funcs.system(cmd)) end) it('sets v:servername, overrides $NVIM_LISTEN_ADDRESS', function() + local addr = (iswin() and [[\\.\pipe\Xtest-listen-pipe]] + or 'Xtest-listen-pipe') clear({ env={ NVIM_LISTEN_ADDRESS='Xtest-env-pipe' }, - args={ '--listen', 'Xtest-listen-pipe' } }) - eq('Xtest-listen-pipe', meths.get_vvar('servername')) + args={ '--listen', addr } }) + eq(addr, meths.get_vvar('servername')) end) end) -- cgit