From 8ebd15a54dba474ee634e0087bb460ca6e7d8428 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 18 May 2017 13:21:14 +0100 Subject: Add commands to run ALEFix, and some tests to cover functionality so far. Add a simple autopep8 function. --- test/test_ale_fix.vader | 109 ++++++++++++++++++++++++++++ test/test_ale_toggle.vader | 3 +- test/test_eslint_executable_detection.vader | 8 +- 3 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 test/test_ale_fix.vader (limited to 'test') diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader new file mode 100644 index 00000000..50e0e065 --- /dev/null +++ b/test/test_ale_fix.vader @@ -0,0 +1,109 @@ +Before: + Save g:ale_fixers, &shell + let g:ale_run_synchronously = 1 + let g:ale_fixers = { + \ 'testft': [], + \} + let &shell = '/bin/bash' + + function AddCarets(buffer, lines) abort + " map() is applied to the original lines here. + " This way, we can ensure that defensive copies are made. + return map(a:lines, '''^'' . v:val') + endfunction + + function AddDollars(buffer, lines) abort + return map(a:lines, '''$'' . v:val') + endfunction + + function DoNothing(buffer, lines) abort + return 0 + endfunction + + function CatLine(buffer, lines) abort + return {'command': 'cat - <(echo d)'} + endfunction + + function ReplaceWithTempFile(buffer, lines) abort + return {'command': 'echo x > %t', 'read_temporary_file': 1} + endfunction + +After: + Restore + unlet! g:ale_run_synchronously + unlet! g:ale_emulate_job_failure + delfunction AddCarets + delfunction AddDollars + delfunction DoNothing + delfunction CatLine + delfunction ReplaceWithTempFile + +Given testft (A file with three lines): + a + b + c + +Execute(ALEFix should complain when there are no functions to call): + AssertThrows ALEFix + AssertEqual 'Vim(echoerr):No fixers have been defined for filetype: testft', g:vader_exception + +Execute(ALEFix should apply simple functions): + let g:ale_fixers.testft = ['AddCarets'] + ALEFix + +Expect(The first function should be used): + ^a + ^b + ^c + +Execute(ALEFix should apply simple functions in a chain): + let g:ale_fixers.testft = ['AddCarets', 'AddDollars'] + ALEFix + +Expect(Both functions should be used): + $^a + $^b + $^c + +Execute(ALEFix should allow 0 to be returned to skip functions): + let g:ale_fixers.testft = ['DoNothing', 'AddDollars'] + ALEFix + +Expect(Only the second function should be applied): + $a + $b + $c + +Execute(ALEFix should allow commands to be run): + let g:ale_fixers.testft = ['CatLine'] + ALEFix + +Expect(An extra line should be added): + a + b + c + d + +Execute(ALEFix should allow temporary files to be read): + let g:ale_fixers.testft = ['ReplaceWithTempFile'] + ALEFix + +Expect(The line we wrote to the temporary file should be used here): + x + +Execute(ALEFix should allow jobs and simple functions to be combined): + let g:ale_fixers.testft = ['ReplaceWithTempFile', 'AddDollars'] + ALEFix + +Expect(The lines from the temporary file should be modified): + $x + +Execute(ALEFix should skip commands when jobs fail to run): + let g:ale_emulate_job_failure = 1 + let g:ale_fixers.testft = ['CatLine', 'AddDollars'] + ALEFix + +Expect(Only the second function should be applied): + $a + $b + $c diff --git a/test/test_ale_toggle.vader b/test/test_ale_toggle.vader index 5d27c864..3546ad71 100644 --- a/test/test_ale_toggle.vader +++ b/test/test_ale_toggle.vader @@ -11,6 +11,7 @@ Before: \ 'valid': 1, \}] let g:expected_groups = [ + \ 'ALEBufferFixGroup', \ 'ALECleanupGroup', \ 'ALECursorGroup', \ 'ALEHighlightBufferGroup', @@ -101,7 +102,7 @@ Execute(ALEToggle should reset everything and then run again): AssertEqual [], getloclist(0) AssertEqual [], ale#sign#FindCurrentSigns(bufnr('%')) AssertEqual [], getmatches() - AssertEqual ['ALECleanupGroup', 'ALEHighlightBufferGroup'], ParseAuGroups() + AssertEqual ['ALEBufferFixGroup', 'ALECleanupGroup', 'ALEHighlightBufferGroup'], ParseAuGroups() " Toggle ALE on, everything should be set up and run again. ALEToggle diff --git a/test/test_eslint_executable_detection.vader b/test/test_eslint_executable_detection.vader index e963ae1c..03bb89e8 100644 --- a/test/test_eslint_executable_detection.vader +++ b/test/test_eslint_executable_detection.vader @@ -20,7 +20,7 @@ Execute(create-react-app directories should be detected correctly): AssertEqual \ g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js', - \ ale_linters#javascript#eslint#GetExecutable(bufnr('')) + \ ale#handlers#eslint#GetExecutable(bufnr('')) :q @@ -31,7 +31,7 @@ Execute(use-global should override create-react-app detection): AssertEqual \ 'eslint_d', - \ ale_linters#javascript#eslint#GetExecutable(bufnr('')) + \ ale#handlers#eslint#GetExecutable(bufnr('')) :q @@ -40,7 +40,7 @@ Execute(other app directories should be detected correctly): AssertEqual \ g:dir . '/eslint-test-files/node_modules/.bin/eslint', - \ ale_linters#javascript#eslint#GetExecutable(bufnr('')) + \ ale#handlers#eslint#GetExecutable(bufnr('')) :q @@ -51,6 +51,6 @@ Execute(use-global should override other app directories): AssertEqual \ 'eslint_d', - \ ale_linters#javascript#eslint#GetExecutable(bufnr('')) + \ ale#handlers#eslint#GetExecutable(bufnr('')) :q -- cgit v1.2.3 From 05bab00c3c9878229e8b3cb8df3dc66a7ad9ee7f Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 18 May 2017 17:26:17 +0100 Subject: Allow strings to be used for selecting a single fix function for g:ale_fixers too --- test/test_ale_fix.vader | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test') diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader index 50e0e065..95a37c6b 100644 --- a/test/test_ale_fix.vader +++ b/test/test_ale_fix.vader @@ -107,3 +107,12 @@ Expect(Only the second function should be applied): $a $b $c + +Execute(ALEFix should handle strings for selecting a single function): + let g:ale_fixers.testft = 'AddCarets' + ALEFix + +Expect(The first function should be used): + ^a + ^b + ^c -- cgit v1.2.3 From 0b743389e526caa7c9065405917da84f83a59b17 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 18 May 2017 17:50:20 +0100 Subject: Send modified lines to jobs, not the file contents --- test/test_ale_fix.vader | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader index 95a37c6b..8ec7896d 100644 --- a/test/test_ale_fix.vader +++ b/test/test_ale_fix.vader @@ -98,6 +98,16 @@ Execute(ALEFix should allow jobs and simple functions to be combined): Expect(The lines from the temporary file should be modified): $x +Execute(ALEFix should send lines modified by functions to jobs): + let g:ale_fixers.testft = ['AddDollars', 'CatLine'] + ALEFix + +Expect(The lines should first be modified by the function, then the job): + $a + $b + $c + d + Execute(ALEFix should skip commands when jobs fail to run): let g:ale_emulate_job_failure = 1 let g:ale_fixers.testft = ['CatLine', 'AddDollars'] -- cgit v1.2.3 From 1f4d1800e0040d7d36d1c19e15c5f0e570122273 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 18 May 2017 23:50:06 +0100 Subject: Allow function aliases to be registered for fixing problems, and add some more argument checking for fixing problems --- test/test_ale_fix.vader | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test') diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader index 8ec7896d..a872f38e 100644 --- a/test/test_ale_fix.vader +++ b/test/test_ale_fix.vader @@ -37,6 +37,7 @@ After: delfunction DoNothing delfunction CatLine delfunction ReplaceWithTempFile + call ale#fix#registry#ResetToDefaults() Given testft (A file with three lines): a @@ -126,3 +127,18 @@ Expect(The first function should be used): ^a ^b ^c + +Execute(ALEFix should complain for missing functions): + let g:ale_fixers.testft = ['XXX', 'YYY'] + AssertThrows ALEFix + AssertEqual 'Vim(echoerr):Invalid fixers used: [''XXX'', ''YYY'']', g:vader_exception + +Execute(ALEFix should use functions from the registry): + call ale#fix#registry#Add('add_carets', 'AddCarets', [], 'Add some carets') + let g:ale_fixers.testft = ['add_carets'] + ALEFix + +Expect(The registry function should be used): + ^a + ^b + ^c -- cgit v1.2.3 From 4214832ae263086d1aa1f565067d00e9ed1b820e Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 19 May 2017 09:49:00 +0100 Subject: Remove the code for checking if functions exist. It breaks autoload functions --- test/test_ale_fix.vader | 5 ----- 1 file changed, 5 deletions(-) (limited to 'test') diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader index a872f38e..8e61aefe 100644 --- a/test/test_ale_fix.vader +++ b/test/test_ale_fix.vader @@ -128,11 +128,6 @@ Expect(The first function should be used): ^b ^c -Execute(ALEFix should complain for missing functions): - let g:ale_fixers.testft = ['XXX', 'YYY'] - AssertThrows ALEFix - AssertEqual 'Vim(echoerr):Invalid fixers used: [''XXX'', ''YYY'']', g:vader_exception - Execute(ALEFix should use functions from the registry): call ale#fix#registry#Add('add_carets', 'AddCarets', [], 'Add some carets') let g:ale_fixers.testft = ['add_carets'] -- cgit v1.2.3 From e6b132c915f11e7ff4962f14bfeba1bd77cd5f9f Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 19 May 2017 09:53:28 +0100 Subject: Fix an off-by-one bug in ALEFix --- test/test_ale_fix.vader | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader index 8e61aefe..71fd84fe 100644 --- a/test/test_ale_fix.vader +++ b/test/test_ale_fix.vader @@ -28,6 +28,9 @@ Before: return {'command': 'echo x > %t', 'read_temporary_file': 1} endfunction + function RemoveLastLine(buffer, lines) abort + return ['a', 'b'] + endfunction After: Restore unlet! g:ale_run_synchronously @@ -37,6 +40,7 @@ After: delfunction DoNothing delfunction CatLine delfunction ReplaceWithTempFile + delfunction RemoveLastLine call ale#fix#registry#ResetToDefaults() Given testft (A file with three lines): @@ -137,3 +141,11 @@ Expect(The registry function should be used): ^a ^b ^c + +Execute(ALEFix should be able to remove the last line for files): + let g:ale_fixers.testft = ['RemoveLastLine'] + ALEFix + +Expect(There should be only two lines): + a + b -- cgit v1.2.3 From 74691269ce7050e6c13053bd884af9c05b630c1e Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 19 May 2017 15:24:21 +0100 Subject: Run a lint cycle after fixing problems --- test/test_ale_fix.vader | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader index 71fd84fe..04657e9e 100644 --- a/test/test_ale_fix.vader +++ b/test/test_ale_fix.vader @@ -1,5 +1,6 @@ Before: - Save g:ale_fixers, &shell + Save g:ale_fixers, &shell, g:ale_enabled + let g:ale_enabled = 0 let g:ale_run_synchronously = 1 let g:ale_fixers = { \ 'testft': [], @@ -31,6 +32,7 @@ Before: function RemoveLastLine(buffer, lines) abort return ['a', 'b'] endfunction + After: Restore unlet! g:ale_run_synchronously -- cgit v1.2.3 From ed097cfcbd5c52835c27632f1e3ac52d2fe0b11a Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 19 May 2017 15:44:52 +0100 Subject: Allow funcref values and lambdas for ALEFix --- test/test_ale_fix.vader | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader index 04657e9e..49d0d2db 100644 --- a/test/test_ale_fix.vader +++ b/test/test_ale_fix.vader @@ -151,3 +151,27 @@ Execute(ALEFix should be able to remove the last line for files): Expect(There should be only two lines): a b + +Execute(ALEFix should accept funcrefs): + let g:ale_fixers.testft = [function('RemoveLastLine')] + ALEFix + +Expect(There should be only two lines): + a + b + +Execute(ALEFix should accept lambdas): + if has('nvim') + " NeoVim 0.1.7 can't interpret lambdas correctly, so just set the lines + " to make the test pass. + call setline(1, ['a', 'b', 'c', 'd']) + else + let g:ale_fixers.testft = [{buffer, lines -> lines + ['d']}] + ALEFix + endif + +Expect(There should be an extra line): + a + b + c + d -- cgit v1.2.3 From 59d9f5d458036bb6a2fbb0d3c3e301f4717eb916 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sat, 20 May 2017 16:00:05 +0100 Subject: Allow b:ale_fixers to be used --- test/test_ale_fix.vader | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test') diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader index 49d0d2db..23c61f9b 100644 --- a/test/test_ale_fix.vader +++ b/test/test_ale_fix.vader @@ -37,6 +37,7 @@ After: Restore unlet! g:ale_run_synchronously unlet! g:ale_emulate_job_failure + unlet! b:ale_fixers delfunction AddCarets delfunction AddDollars delfunction DoNothing @@ -175,3 +176,12 @@ Expect(There should be an extra line): b c d + +Execute(ALEFix should user buffer-local fixer settings): + let g:ale_fixers.testft = ['AddCarets', 'AddDollars'] + let b:ale_fixers = {'testft': ['RemoveLastLine']} + ALEFix + +Expect(There should be only two lines): + a + b -- cgit v1.2.3 From 3530180a73ec53c6c029926173c34e0d78a8ac70 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sat, 20 May 2017 18:56:44 +0100 Subject: Suggest functions for fixing issues for ALEFix --- test/test_ale_fix.vader | 2 +- test/test_ale_fix_suggest.vader | 75 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 test/test_ale_fix_suggest.vader (limited to 'test') diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader index 23c61f9b..dfe79443 100644 --- a/test/test_ale_fix.vader +++ b/test/test_ale_fix.vader @@ -53,7 +53,7 @@ Given testft (A file with three lines): Execute(ALEFix should complain when there are no functions to call): AssertThrows ALEFix - AssertEqual 'Vim(echoerr):No fixers have been defined for filetype: testft', g:vader_exception + AssertEqual 'Vim(echoerr):No fixers have been defined. Try :ALEFixSuggest', g:vader_exception Execute(ALEFix should apply simple functions): let g:ale_fixers.testft = ['AddCarets'] diff --git a/test/test_ale_fix_suggest.vader b/test/test_ale_fix_suggest.vader new file mode 100644 index 00000000..9a7aecbf --- /dev/null +++ b/test/test_ale_fix_suggest.vader @@ -0,0 +1,75 @@ +Before: + call ale#fix#registry#Clear() + + function GetSuggestions() + redir => l:output + silent ALEFixSuggest + redir END + + return split(l:output, "\n") + endfunction + +After: + call ale#fix#registry#ResetToDefaults() + delfunction GetSuggestions + +Execute(ALEFixSuggest should return something sensible with no suggestions): + AssertEqual + \ [ + \ 'There is nothing in the registry to suggest.', + \ ], + \ GetSuggestions() + +Execute(ALEFixSuggest output should be correct for only generic handlers): + call ale#fix#registry#Add('zed', 'XYZ', [], 'Zedify things.') + call ale#fix#registry#Add('alpha', 'XYZ', [], 'Alpha things.') + + AssertEqual + \ [ + \ 'Try the following generic fixers:', + \ '', + \ '''alpha'' - Alpha things.', + \ '''zed'' - Zedify things.', + \ '', + \ 'See :help ale-fix-configuration', + \ ], + \ GetSuggestions() + +Execute(ALEFixSuggest output should be correct for only filetype handlers): + let &filetype = 'testft2.testft' + + call ale#fix#registry#Add('zed', 'XYZ', ['testft2'], 'Zedify things.') + call ale#fix#registry#Add('alpha', 'XYZ', ['testft'], 'Alpha things.') + + AssertEqual + \ [ + \ 'Try the following fixers appropriate for the filetype:', + \ '', + \ '''alpha'' - Alpha things.', + \ '''zed'' - Zedify things.', + \ '', + \ 'See :help ale-fix-configuration', + \ ], + \ GetSuggestions() + +Execute(ALEFixSuggest should suggest filetype and generic handlers): + let &filetype = 'testft2.testft' + + call ale#fix#registry#Add('zed', 'XYZ', ['testft2'], 'Zedify things.') + call ale#fix#registry#Add('alpha', 'XYZ', ['testft'], 'Alpha things.') + call ale#fix#registry#Add('generic', 'XYZ', [], 'Generic things.') + + AssertEqual + \ [ + \ 'Try the following fixers appropriate for the filetype:', + \ '', + \ '''alpha'' - Alpha things.', + \ '''zed'' - Zedify things.', + \ '', + \ 'Try the following generic fixers:', + \ '', + \ '''generic'' - Generic things.', + \ '', + \ 'See :help ale-fix-configuration', + \ ], + \ GetSuggestions() -- cgit v1.2.3