1919"
2020" If cleanup after each Test_ function is needed, define a TearDown function.
2121" It will be called after each Test_ function.
22+ "
23+ " When debugging a test it can be useful to add messages to v:errors:
24+ " call add(v:errors, "this happened")
25+
2226
2327" Without the +eval feature we can't run these tests, bail out.
2428so small.vim
@@ -65,21 +69,21 @@ endfunc
6569
6670
6771" Source the test script. First grab the file name, in case the script
68- " navigates away.
69- let testname = expand (' %' )
70- let done = 0
71- let fail = 0
72- let errors = []
73- let messages = []
72+ " navigates away. g:testname can be used by the tests.
73+ let g: testname = expand (' %' )
74+ let s: done = 0
75+ let s: fail = 0
76+ let s: errors = []
77+ let s: messages = []
7478if expand (' %' ) = ~ ' test_viml.vim'
75- " this test has intentional errors, don't use try/catch.
79+ " this test has intentional s: errors, don't use try/catch.
7680 source %
7781else
7882 try
7983 source %
8084 catch
81- let fail += 1
82- call add (errors, ' Caught exception: ' . v: exception . ' @ ' . v: throwpoint )
85+ let s: fail += 1
86+ call add (s: errors , ' Caught exception: ' . v: exception . ' @ ' . v: throwpoint )
8387 endtry
8488endif
8589
@@ -88,27 +92,26 @@ set nomore
8892redir @q
8993function /^Test_
9094redir END
91- let tests = split (substitute (@q , ' function \(\k*()\)' , ' \1' , ' g' ))
95+ let s: tests = split (substitute (@q , ' function \(\k*()\)' , ' \1' , ' g' ))
9296
9397" Execute the tests in alphabetical order.
94- for test in sort (tests)
98+ for s: test in sort (s: tests )
9599 if exists (" *SetUp" )
96100 call SetUp ()
97101 endif
98102
99- call add (messages , ' Executing ' . test)
100- let done += 1
103+ call add (s: messages , ' Executing ' . s: test )
104+ let s: done += 1
101105 try
102- exe ' call ' . test
106+ exe ' call ' . s: test
103107 catch
104- let fail += 1
105- call add (v: errors , ' Caught exception in ' . test . ' : ' . v: exception . ' @ ' . v: throwpoint )
108+ call add (v: errors , ' Caught exception in ' . s: test . ' : ' . v: exception . ' @ ' . v: throwpoint )
106109 endtry
107110
108111 if len (v: errors ) > 0
109- let fail += 1
110- call add (errors, ' Found errors in ' . test . ' :' )
111- call extend (errors, v: errors )
112+ let s: fail += 1
113+ call add (s: errors , ' Found errors in ' . s: test . ' :' )
114+ call extend (s: errors , v: errors )
112115 let v: errors = []
113116 endif
114117
@@ -117,35 +120,36 @@ let tests = split(substitute(@q, 'function \(\k*()\)', '\1', 'g'))
117120 endif
118121endfor
119122
120- if fail == 0
123+ if s: fail == 0
121124 " Success, create the .res file so that make knows it's done.
122- exe ' split ' . fnamemodify (testname, ' :r' ) . ' .res'
125+ exe ' split ' . fnamemodify (g: testname , ' :r' ) . ' .res'
123126 write
124127endif
125128
126- if len (errors) > 0
129+ if len (s: errors ) > 0
127130 " Append errors to test.log
128131 split test.log
129132 call append (line (' $' ), ' ' )
130- call append (line (' $' ), ' From ' . testname . ' :' )
131- call append (line (' $' ), errors)
133+ call append (line (' $' ), ' From ' . g: testname . ' :' )
134+ call append (line (' $' ), s: errors )
132135 write
133136endif
134137
135- let message = ' Executed ' . done . (done > 1 ? ' tests' : ' test' )
138+ let message = ' Executed ' . s: done . (s: done > 1 ? ' tests' : ' test' )
136139echo message
137- call add (messages , message)
138- if fail > 0
139- let message = fail . ' FAILED'
140+ call add (s: messages , message)
141+ if s: fail > 0
142+ let message = s: fail . ' FAILED: '
140143 echo message
141- call add (messages , message)
144+ call add (s: messages , message)
145+ call extend (s: messages , s: errors )
142146endif
143147
144148" Append messages to "messages"
145149split messages
146150call append (line (' $' ), ' ' )
147- call append (line (' $' ), ' From ' . testname . ' :' )
148- call append (line (' $' ), messages )
151+ call append (line (' $' ), ' From ' . g: testname . ' :' )
152+ call append (line (' $' ), s: messages )
149153write
150154
151155qall !
0 commit comments