From ea72d66b6d4e3f0dc04d12fba08fe29e7e637b72 Mon Sep 17 00:00:00 2001 From: Tarik Graba Date: Thu, 11 Feb 2021 20:35:25 +0100 Subject: [PATCH] Verilator current file search path (#3500) * Simplify verilator linter using ale command format strings * Verilator Linter: Restructure linter command tests * Verilator Linter: adds to the handler test the returned filename * Verilator Linter: add the current file path to the search path * Verilator Linter: Add the search path to the tests Co-authored-by: TG --- ale_linters/verilog/verilator.vim | 20 +++++----------- .../test_verilator_command_callback.vader | 14 +++++++++++ test/handler/test_verilator_handler.vader | 20 +++++++++------- test/test_verilog_verilator_options.vader | 24 ------------------- 4 files changed, 32 insertions(+), 46 deletions(-) create mode 100644 test/command_callback/test_verilator_command_callback.vader delete mode 100644 test/test_verilog_verilator_options.vader diff --git a/ale_linters/verilog/verilator.vim b/ale_linters/verilog/verilator.vim index 029dd4c9..006e310d 100644 --- a/ale_linters/verilog/verilator.vim +++ b/ale_linters/verilog/verilator.vim @@ -7,16 +7,11 @@ if !exists('g:ale_verilog_verilator_options') endif function! ale_linters#verilog#verilator#GetCommand(buffer) abort - let l:filename = ale#util#Tempname() . '_verilator_linted.v' - - " Create a special filename, so we can detect it in the handler. - call ale#command#ManageFile(a:buffer, l:filename) - let l:lines = getbufline(a:buffer, 1, '$') - call ale#util#Writefile(a:buffer, l:lines, l:filename) - + " the path to the current file is systematically added to the search path return 'verilator --lint-only -Wall -Wno-DECLFILENAME ' + \ . '-I%s:h ' \ . ale#Var(a:buffer, 'verilog_verilator_options') .' ' - \ . ale#Escape(l:filename) + \ . '%t' endfunction function! ale_linters#verilog#verilator#Handle(buffer, lines) abort @@ -34,7 +29,7 @@ function! ale_linters#verilog#verilator#Handle(buffer, lines) abort " " to stay compatible with old versions of the tool, the column number is " optional in the researched pattern - let l:pattern = '^%\(Warning\|Error\)[^:]*:\([^:]\+\):\(\d\+\):\(\d\+\)\?:\? \(.\+\)$' + let l:pattern = '^%\(Warning\|Error\)[^:]*:\s*\([^:]\+\):\(\d\+\):\(\d\+\)\?:\? \(.\+\)$' let l:output = [] for l:match in ale#util#GetMatches(a:lines, l:pattern) @@ -42,17 +37,14 @@ function! ale_linters#verilog#verilator#Handle(buffer, lines) abort \ 'lnum': str2nr(l:match[3]), \ 'text': l:match[5], \ 'type': l:match[1] is# 'Error' ? 'E' : 'W', + \ 'filename': l:match[2], \} if !empty(l:match[4]) let l:item.col = str2nr(l:match[4]) endif - let l:file = l:match[2] - - if l:file =~# '_verilator_linted.v' - call add(l:output, l:item) - endif + call add(l:output, l:item) endfor return l:output diff --git a/test/command_callback/test_verilator_command_callback.vader b/test/command_callback/test_verilator_command_callback.vader new file mode 100644 index 00000000..b65f3459 --- /dev/null +++ b/test/command_callback/test_verilator_command_callback.vader @@ -0,0 +1,14 @@ +Before: + call ale#assert#SetUpLinterTest('verilog', 'verilator') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The default verilator command should be correct): + AssertLinter 'verilator', 'verilator --lint-only -Wall -Wno-DECLFILENAME -I%s:h %t' + +Execute(verilator options should be configurable): + " Additional args for the linter + let g:ale_verilog_verilator_options = '-sv --default-language "1800-2012"' + + AssertLinter 'verilator', 'verilator --lint-only -Wall -Wno-DECLFILENAME -I%s:h -sv --default-language "1800-2012" %t' diff --git a/test/handler/test_verilator_handler.vader b/test/handler/test_verilator_handler.vader index 5e51b5c9..59ec1361 100644 --- a/test/handler/test_verilator_handler.vader +++ b/test/handler/test_verilator_handler.vader @@ -11,17 +11,19 @@ Execute (The verilator handler should parse legacy messages with only line numbe \ { \ 'lnum': 3, \ 'type': 'E', - \ 'text': 'syntax error, unexpected IDENTIFIER' + \ 'text': 'syntax error, unexpected IDENTIFIER', + \ 'filename': 'foo.v' \ }, \ { \ 'lnum': 10, \ 'type': 'W', - \ 'text': 'Blocking assignments (=) in sequential (flop or latch) block; suggest delayed assignments (<=).' + \ 'text': 'Blocking assignments (=) in sequential (flop or latch) block; suggest delayed assignments (<=).', + \ 'filename': 'bar.v' \ }, \ ], \ ale_linters#verilog#verilator#Handle(bufnr(''), [ - \ '%Error: foo_verilator_linted.v:3: syntax error, unexpected IDENTIFIER', - \ '%Warning-BLKSEQ: bar_verilator_linted.v:10: Blocking assignments (=) in sequential (flop or latch) block; suggest delayed assignments (<=).', + \ '%Error: foo.v:3: syntax error, unexpected IDENTIFIER', + \ '%Warning-BLKSEQ: bar.v:10: Blocking assignments (=) in sequential (flop or latch) block; suggest delayed assignments (<=).', \ ]) @@ -32,17 +34,19 @@ Execute (The verilator handler should parse new format messages with line and co \ 'lnum': 3, \ 'col' : 1, \ 'type': 'E', - \ 'text': 'syntax error, unexpected endmodule, expecting ;' + \ 'text': 'syntax error, unexpected endmodule, expecting ;', + \ 'filename': 'bar.v' \ }, \ { \ 'lnum': 4, \ 'col' : 6, \ 'type': 'W', - \ 'text': 'Signal is not used: r' + \ 'text': 'Signal is not used: r', + \ 'filename': 'foo.v' \ }, \ ], \ ale_linters#verilog#verilator#Handle(bufnr(''), [ - \ '%Error: bar_verilator_linted.v:3:1: syntax error, unexpected endmodule, expecting ;', - \ '%Warning-UNUSED: foo_verilator_linted.v:4:6: Signal is not used: r', + \ '%Error: bar.v:3:1: syntax error, unexpected endmodule, expecting ;', + \ '%Warning-UNUSED: foo.v:4:6: Signal is not used: r', \ ]) diff --git a/test/test_verilog_verilator_options.vader b/test/test_verilog_verilator_options.vader deleted file mode 100644 index 3ebabfcc..00000000 --- a/test/test_verilog_verilator_options.vader +++ /dev/null @@ -1,24 +0,0 @@ -Before: - Save g:ale_verilog_verilator_options - let g:ale_verilog_verilator_options = '' - -After: - Restore - call ale#linter#Reset() - -Execute(Set Verilog Verilator linter additional options to `-sv --default-language "1800-2012"`): - runtime! ale_linters/verilog/verilator.vim - - " Additional args for the linter - let g:ale_verilog_verilator_options = '-sv --default-language "1800-2012"' - - call ale#Queue(0) - - let g:run_cmd = ale_linters#verilog#verilator#GetCommand(bufnr('')) - let g:matched = match(g:run_cmd, '\s' . g:ale_verilog_verilator_options . '\s') - - " match returns -1 if not found - AssertNotEqual - \ g:matched , - \ -1 , - \ 'Additionnal arguments not found in the run command'