|
1 | | -" add vim-go the only plugin inside the runtimepath |
2 | | -" |
3 | 1 | let total_started = reltime() |
4 | 2 |
|
| 3 | +" add vim-go the only plugin inside the runtimepath |
5 | 4 | let git_root_path = system("git rev-parse --show-toplevel | tr -d '\\n'") |
6 | 5 | exe 'set rtp=' . git_root_path |
7 | 6 |
|
8 | | -" source test files |
9 | | -for s:vim_file in globpath(git_root_path . "/autoload/go", "*.vim", 0, 1) |
10 | | - if s:vim_file =~# '^\f\+_test\.vim$' |
11 | | - exec 'source ' . s:vim_file |
12 | | - endif |
13 | | -endfor |
| 7 | +" source the passed test file |
| 8 | +source % |
| 9 | + |
| 10 | +" cd into the folder of the test file |
| 11 | +let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' |
| 12 | +let dir = getcwd() |
| 13 | +execute cd . expand('%:p:h') |
14 | 14 |
|
| 15 | +" initialize variables |
| 16 | +let g:testname = expand('%') |
15 | 17 | let s:fail = 0 |
16 | 18 | let s:done = 0 |
17 | | -let s:errors = [] |
18 | | -let s:messages = [] |
| 19 | +let s:logs = [] |
19 | 20 |
|
20 | | -" get a list of all Test_ functions (sourced above) |
| 21 | +" get a list of all Test_ functions for the given file |
21 | 22 | set nomore |
22 | 23 | redir @q |
23 | 24 | silent function /^Test_ |
24 | 25 | redir END |
25 | 26 | let s:tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g')) |
26 | 27 |
|
27 | | - |
28 | | -" cd into autoload/go directory for tests |
29 | | -let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' |
30 | | -let dir = getcwd() |
31 | | -execute cd . fnameescape(git_root_path."/autoload/go") |
32 | | - |
33 | 28 | " Iterate over all tests and execute them |
34 | 29 | for s:test in sort(s:tests) |
35 | 30 | let started = reltime() |
36 | 31 |
|
| 32 | + call add(s:logs, printf("=== RUN %s", s:test[:-3])) |
37 | 33 | exe 'call ' . s:test |
38 | 34 |
|
39 | 35 | let elapsed_time = reltimestr(reltime(started)) |
40 | 36 | let elapsed_time = substitute(elapsed_time, '^\s*\(.\{-}\)\s*$', '\1', '') |
41 | 37 |
|
42 | | - call add(s:messages, printf("=== %s (%ss)", s:test, elapsed_time)) |
43 | | - |
44 | 38 | let s:done += 1 |
45 | 39 |
|
46 | 40 | if len(v:errors) > 0 |
47 | 41 | let s:fail += 1 |
48 | | - call add(s:errors, 'Found errors in ' . s:test . ':') |
49 | | - call extend(s:errors, v:errors) |
| 42 | + call add(s:logs, printf("--- FAIL: %s (%ss)", s:test[:-3], elapsed_time)) |
| 43 | + call extend(s:logs, map(v:errors, '" ". v:val')) |
| 44 | + |
| 45 | + " reset so we can capture failures of next test |
50 | 46 | let v:errors = [] |
| 47 | + else |
| 48 | + call add(s:logs, printf("--- PASS: %s (%ss)", s:test[:-3], elapsed_time)) |
51 | 49 | endif |
52 | 50 | endfor |
53 | 51 |
|
| 52 | +" pop out into the scripts folder |
54 | 53 | execute cd . fnameescape(dir) |
55 | 54 |
|
56 | | -if len(s:errors) > 0 || s:done == 0 |
57 | | - " Append errors to test.log |
58 | | - split test.log |
59 | | - call append(line('$'), '') |
60 | | - call append(line('$'), s:errors) |
| 55 | +" create an empty fail to indicate that the test failed |
| 56 | +if s:fail > 0 |
| 57 | + split FAILED |
61 | 58 | write |
62 | 59 | endif |
63 | 60 |
|
64 | 61 | let total_elapsed_time = reltimestr(reltime(total_started)) |
65 | 62 | let total_elapsed_time = substitute(total_elapsed_time, '^\s*\(.\{-}\)\s*$', '\1', '') |
66 | 63 |
|
67 | 64 | let message = 'Executed ' . s:done . (s:done > 1 ? ' tests' : ' test') . '. Total test time: '. total_elapsed_time .'s' |
68 | | -call add(s:messages, "") |
69 | | -call add(s:messages, message) |
| 65 | +call add(s:logs, "") |
| 66 | +call add(s:logs, message) |
70 | 67 |
|
| 68 | +" store all error messages from within vim into test.log |
| 69 | +redir > test.log |
| 70 | +silent messages |
| 71 | +redir END |
71 | 72 |
|
72 | | -split messages.log |
| 73 | +" also store all internal messages from s:logs: as well |
| 74 | +split test.log |
73 | 75 | call append(line('$'), '') |
74 | | -call append(line('$'), s:messages) |
| 76 | +call append(line('$'), 'From ' . g:testname . ':') |
| 77 | +call append(line('$'), s:logs) |
75 | 78 | write |
76 | 79 |
|
77 | 80 | " bye, bye! |
|
0 commit comments