From ce2bfa88eb3dbfe1e2d0f6dd8b0781cb61c15cc1 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 22 Jun 2017 12:37:08 +0100 Subject: [PATCH] Fix #676 - Fix handling of Perl errors --- ale_linters/perl/perl.vim | 2 +- autoload/ale/path.vim | 7 +++++++ test/handler/test_perl_handler.vader | 14 ++++++++++++++ test/test_path_equality.vader | 6 ++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/ale_linters/perl/perl.vim b/ale_linters/perl/perl.vim index 53c91d3..f4b35ab 100644 --- a/ale_linters/perl/perl.vim +++ b/ale_linters/perl/perl.vim @@ -27,7 +27,7 @@ function! ale_linters#perl#perl#Handle(buffer, lines) abort let l:text = l:match[1] let l:type = 'E' - if l:match[2][-len(l:basename):] ==# l:basename + if ale#path#IsBufferPath(a:buffer, l:match[2]) \&& l:text !=# 'BEGIN failed--compilation aborted' call add(l:output, { \ 'lnum': l:line, diff --git a/autoload/ale/path.vim b/autoload/ale/path.vim index 0365cee..e8a5de2 100644 --- a/autoload/ale/path.vim +++ b/autoload/ale/path.vim @@ -65,6 +65,13 @@ endfunction " Given a buffer number and a relative or absolute path, return 1 if the " two paths represent the same file on disk. function! ale#path#IsBufferPath(buffer, complex_filename) abort + " If the path is one of many different names for stdin, we have a match. + if a:complex_filename ==# '-' + \|| a:complex_filename ==# 'stdin' + \|| a:complex_filename[:0] ==# '<' + return 1 + endif + let l:test_filename = simplify(a:complex_filename) if l:test_filename[:1] ==# './' diff --git a/test/handler/test_perl_handler.vader b/test/handler/test_perl_handler.vader index 2961b26..b8b7b6c 100644 --- a/test/handler/test_perl_handler.vader +++ b/test/handler/test_perl_handler.vader @@ -23,3 +23,17 @@ Execute(The Perl linter should ignore errors from other files): \ 'Compilation failed in require at ' . b:path . '/bar.pl line 2.', \ 'BEGIN failed--compilation aborted at ' . b:path . '/bar.pl line 2.', \ ]) + +Execute(The Perl linter should complain about failing to locate modules): + AssertEqual + \ [ + \ { + \ 'lnum': '23', + \ 'type': 'E', + \ 'text': 'Can''t locate JustOneDb.pm in @INC (you may need to install the JustOneDb module) (@INC contains: /home/local/sean/work/PostgreSQL/6616/../../../../lib /home/local/sean/work/PostgreSQL/6616/lib lib /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .)', + \ }, + \ ], + \ ale_linters#perl#perl#Handle(bufnr(''), [ + \ 'Can''t locate JustOneDb.pm in @INC (you may need to install the JustOneDb module) (@INC contains: /home/local/sean/work/PostgreSQL/6616/../../../../lib /home/local/sean/work/PostgreSQL/6616/lib lib /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18 /usr/local/lib/site_perl .) at - line 23.', + \ 'BEGIN failed--compilation aborted at - line 23.', + \ ]) diff --git a/test/test_path_equality.vader b/test/test_path_equality.vader index 5d92794..7043eb5 100644 --- a/test/test_path_equality.vader +++ b/test/test_path_equality.vader @@ -24,3 +24,9 @@ Execute(ale#path#IsBufferPath should match paths with redundant slashes): silent file! foo.txt Assert ale#path#IsBufferPath(bufnr(''), getcwd() . '////foo.txt'), 'No match for foo.txt' + +Execute(ale#path#IsBufferPath should accept various names for stdin): + Assert ale#path#IsBufferPath(bufnr(''), '-') + Assert ale#path#IsBufferPath(bufnr(''), 'stdin') + Assert ale#path#IsBufferPath(bufnr(''), '') + Assert ale#path#IsBufferPath(bufnr(''), '')