Konfekt | 3c2596a | 2024-11-30 11:32:49 +0100 | [diff] [blame] | 1 | " Vim compiler file |
| 2 | " Compiler: Pytest (Python testing framework) |
| 3 | " Maintainer: @Konfekt and @mgedmin |
| 4 | " Last Change: 2024 Nov 28 |
| 5 | |
| 6 | if exists("current_compiler") | finish | endif |
| 7 | let current_compiler = "pytest" |
| 8 | |
| 9 | let s:cpo_save = &cpo |
| 10 | set cpo&vim |
| 11 | |
| 12 | " CompilerSet makeprg=pytest |
| 13 | if has('unix') |
| 14 | execute $'CompilerSet makeprg=/usr/bin/env\ PYTHONWARNINGS=ignore\ pytest\ {escape(get(b:, 'pytest_makeprg_params', get(g:, 'pytest_makeprg_params', '--tb=short --quiet')), ' \|"')}' |
| 15 | elseif has('win32') |
| 16 | execute $'CompilerSet makeprg=set\ PYTHONWARNINGS=ignore\ &&\ pytest\ {escape(get(b:, 'pytest_makeprg_params', get(g:, 'pytest_makeprg_params', '--tb=short --quiet')), ' \|"')}' |
| 17 | else |
| 18 | CompilerSet makeprg=pytest\ --tb=short\ --quiet |
| 19 | execute $'CompilerSet makeprg=pytest\ {escape(get(b:, 'pytest_makeprg_params', get(g:, 'pytest_makeprg_params', '--tb=short --quiet')), ' \|"')}' |
| 20 | endif |
| 21 | |
| 22 | " Pytest syntax errors {{{2 |
| 23 | |
| 24 | " Reset error format so that sourcing .vimrc again and again doesn't grow it |
| 25 | " without bounds |
| 26 | setlocal errorformat& |
| 27 | |
| 28 | " For the record, the default errorformat is this: |
| 29 | " |
| 30 | " %*[^"]"%f"%*\D%l: %m |
| 31 | " "%f"%*\D%l: %m |
| 32 | " %-G%f:%l: (Each undeclared identifier is reported only once |
| 33 | " %-G%f:%l: for each function it appears in.) |
| 34 | " %-GIn file included from %f:%l:%c: |
| 35 | " %-GIn file included from %f:%l:%c\, |
| 36 | " %-GIn file included from %f:%l:%c |
| 37 | " %-GIn file included from %f:%l |
| 38 | " %-G%*[ ]from %f:%l:%c |
| 39 | " %-G%*[ ]from %f:%l: |
| 40 | " %-G%*[ ]from %f:%l\, |
| 41 | " %-G%*[ ]from %f:%l |
| 42 | " %f:%l:%c:%m |
| 43 | " %f(%l):%m |
| 44 | " %f:%l:%m |
| 45 | " "%f"\, line %l%*\D%c%*[^ ] %m |
| 46 | " %D%*\a[%*\d]: Entering directory %*[`']%f' |
| 47 | " %X%*\a[%*\d]: Leaving directory %*[`']%f' |
| 48 | " %D%*\a: Entering directory %*[`']%f' |
| 49 | " %X%*\a: Leaving directory %*[`']%f' |
| 50 | " %DMaking %*\a in %f |
| 51 | " %f|%l| %m |
| 52 | " |
| 53 | " and sometimes it misfires, so let's fix it up a bit |
| 54 | " (TBH I don't even know what compiler produces filename(lineno) so why even |
| 55 | " have it?) |
| 56 | setlocal errorformat-=%f(%l):%m |
| 57 | |
| 58 | " Sometimes Vim gets confused about ISO-8601 timestamps and thinks they're |
| 59 | " filenames; this is a big hammer that ignores anything filename-like on lines |
| 60 | " that start with at least two spaces, possibly preceded by a number and |
| 61 | " optional punctuation |
| 62 | setlocal errorformat^=%+G%\\d%#%.%\\=\ \ %.%# |
| 63 | |
| 64 | " Similar, but when the entire line starts with a date |
| 65 | setlocal errorformat^=%+G\\d\\d\\d\\d-\\d\\d-\\d\\d\ \\d\\d:\\d\\d%.%# |
| 66 | |
| 67 | " make: *** [Makefile:14: target] Error 1 |
| 68 | setlocal errorformat^=%+Gmake:\ ***\ %.%# |
| 69 | |
| 70 | " FAILED tests.py::test_with_params[YYYY-MM-DD:HH:MM:SS] - Exception: bla bla |
| 71 | setlocal errorformat^=%+GFAILED\ %.%# |
| 72 | |
| 73 | " AssertionError: assert ...YYYY-MM-DD:HH:MM:SS... |
| 74 | setlocal errorformat^=%+GAssertionError:\ %.%# |
| 75 | |
| 76 | " --- /path/to/file:before YYYY-MM-DD HH:MM:SS.ssssss |
| 77 | setlocal errorformat^=---%f:%m |
| 78 | |
| 79 | " +++ /path/to/file:before YYYY-MM-DD HH:MM:SS.ssssss |
| 80 | setlocal errorformat^=+++%f:%m |
| 81 | |
| 82 | " Sometimes pytest prepends an 'E' marker at the beginning of a traceback line |
| 83 | setlocal errorformat+=E\ %#File\ \"%f\"\\,\ line\ %l%.%# |
| 84 | |
| 85 | " Python tracebacks (unittest + doctest output) {{{2 |
| 86 | |
| 87 | " This collapses the entire traceback into just the last file+lineno, |
| 88 | " which is convenient when you want to jump to the line that failed (and not |
| 89 | " the top-level entry point), but it makes it impossible to see the full |
| 90 | " traceback, which sucks. |
| 91 | ""setlocal errorformat+= |
| 92 | "" \File\ \"%f\"\\,\ line\ %l%.%#, |
| 93 | "" \%C\ %.%#, |
| 94 | "" \%-A\ \ File\ \"unittest%.py\"\\,\ line\ %.%#, |
| 95 | "" \%-A\ \ File\ \"%f\"\\,\ line\ 0%.%#, |
| 96 | "" \%A\ \ File\ \"%f\"\\,\ line\ %l%.%#, |
| 97 | "" \%Z%[%^\ ]%\\@=%m |
| 98 | setlocal errorformat+=File\ \"%f\"\\,\ line\ %l\\,%#%m |
| 99 | |
| 100 | exe 'CompilerSet errorformat='..escape(&l:errorformat, ' \|"') |
| 101 | |
| 102 | let &cpo = s:cpo_save |
| 103 | unlet s:cpo_save |