Bram Moolenaar | c771908 | 2020-08-13 19:42:39 +0200 | [diff] [blame] | 1 | set cpo&vim |
Bram Moolenaar | 9c0cec6 | 2019-06-06 13:38:15 +0200 | [diff] [blame] | 2 | if 1 |
Bram Moolenaar | f1e0544 | 2019-08-20 21:25:46 +0200 | [diff] [blame] | 3 | " This is executed only with the eval feature |
| 4 | set nocompatible |
Bram Moolenaar | eb698d0 | 2019-12-30 00:07:57 +0100 | [diff] [blame] | 5 | set viminfo= |
Bram Moolenaar | 9c0cec6 | 2019-06-06 13:38:15 +0200 | [diff] [blame] | 6 | func Count(match, type) |
| 7 | if a:type ==# 'executed' |
| 8 | let g:executed += (a:match+0) |
| 9 | elseif a:type ==# 'failed' |
Bram Moolenaar | 150f055 | 2019-06-07 21:29:50 +0200 | [diff] [blame] | 10 | let g:failed += a:match+0 |
Bram Moolenaar | 9c0cec6 | 2019-06-06 13:38:15 +0200 | [diff] [blame] | 11 | elseif a:type ==# 'skipped' |
| 12 | let g:skipped += 1 |
Bram Moolenaar | a7f6c3c | 2019-09-27 15:34:16 +0200 | [diff] [blame] | 13 | call extend(g:skipped_output, ["\t" .. a:match]) |
Bram Moolenaar | 9c0cec6 | 2019-06-06 13:38:15 +0200 | [diff] [blame] | 14 | endif |
| 15 | endfunc |
| 16 | |
| 17 | let g:executed = 0 |
| 18 | let g:skipped = 0 |
| 19 | let g:failed = 0 |
| 20 | let g:skipped_output = [] |
| 21 | let g:failed_output = [] |
| 22 | let output = [""] |
| 23 | |
Bram Moolenaar | a7f6c3c | 2019-09-27 15:34:16 +0200 | [diff] [blame] | 24 | if $TEST_FILTER != '' |
| 25 | call extend(g:skipped_output, ["\tAll tests not matching $TEST_FILTER: '" .. $TEST_FILTER .. "'"]) |
| 26 | endif |
| 27 | |
Bram Moolenaar | 9c0cec6 | 2019-06-06 13:38:15 +0200 | [diff] [blame] | 28 | try |
| 29 | " This uses the :s command to just fetch and process the output of the |
Bram Moolenaar | 60b1bcf | 2019-08-30 19:05:32 +0200 | [diff] [blame] | 30 | " tests, it doesn't actually replace anything. |
Bram Moolenaar | f1e0544 | 2019-08-20 21:25:46 +0200 | [diff] [blame] | 31 | " And it uses "silent" to avoid reporting the number of matches. |
Bram Moolenaar | 7eaafe6 | 2020-06-22 22:10:06 +0200 | [diff] [blame] | 32 | silent %s/Executed\s\+\zs\d\+\ze\s\+tests\?/\=Count(submatch(0),'executed')/egn |
Bram Moolenaar | f1e0544 | 2019-08-20 21:25:46 +0200 | [diff] [blame] | 33 | silent %s/^SKIPPED \zs.*/\=Count(submatch(0), 'skipped')/egn |
| 34 | silent %s/^\(\d\+\)\s\+FAILED:/\=Count(submatch(1), 'failed')/egn |
Bram Moolenaar | 9c0cec6 | 2019-06-06 13:38:15 +0200 | [diff] [blame] | 35 | |
Bram Moolenaar | 94722c5 | 2023-01-28 19:19:03 +0000 | [diff] [blame] | 36 | call extend(output, ["Skipped:"]) |
Bram Moolenaar | 9c0cec6 | 2019-06-06 13:38:15 +0200 | [diff] [blame] | 37 | call extend(output, skipped_output) |
| 38 | |
| 39 | call extend(output, [ |
| 40 | \ "", |
| 41 | \ "-------------------------------", |
| 42 | \ printf("Executed: %5d Tests", g:executed), |
| 43 | \ printf(" Skipped: %5d Tests", g:skipped), |
| 44 | \ printf(" %s: %5d Tests", g:failed == 0 ? 'Failed' : 'FAILED', g:failed), |
| 45 | \ "", |
Bram Moolenaar | f1e0544 | 2019-08-20 21:25:46 +0200 | [diff] [blame] | 46 | \ ]) |
Bram Moolenaar | 9c0cec6 | 2019-06-06 13:38:15 +0200 | [diff] [blame] | 47 | if filereadable('test.log') |
| 48 | " outputs and indents the failed test result |
| 49 | call extend(output, ["", "Failures: "]) |
| 50 | let failed_output = filter(readfile('test.log'), { v,k -> !empty(k)}) |
| 51 | call extend(output, map(failed_output, { v,k -> "\t".k})) |
| 52 | " Add a final newline |
| 53 | call extend(output, [""]) |
| 54 | endif |
| 55 | |
| 56 | catch " Catch-all |
| 57 | finally |
| 58 | call writefile(output, 'test_result.log') " overwrites an existing file |
Bram Moolenaar | 9c0cec6 | 2019-06-06 13:38:15 +0200 | [diff] [blame] | 59 | endtry |
| 60 | endif |
| 61 | |
Bram Moolenaar | 9c0cec6 | 2019-06-06 13:38:15 +0200 | [diff] [blame] | 62 | q! |