summaryrefslogtreecommitdiff
path: root/doc/index.html
blob: a9a4d5cedec8bd1f5faf7cce85828c8b5b47c470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>LuaCov - Coverage analysis for Lua scripts</title>
    <link rel="stylesheet" href="doc.css" type="text/css" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
pre {
   font-family: "Andale Mono", monospace;
}
div.Example {
   font-family: "Andale Mono", monospace;
   background-color: #f0f0f0;
   margin-left: 1em;
   margin-right: 1em;
   margin-top: 0.5em;
   margin-bottom 0.5em;
   padding: 0.5em;
}
</style>
</head>

<body>

<div id="container">
    
<div id="product">
    <div id="product_logo"><a href="http://keplerproject.github.com/luacov">
        <img alt="LuaCov logo" src="luacov.png" />
    </a></div>
    <div id="product_name"><big><strong>LuaCov</strong></big></div>
    <div id="product_description">Coverage analysis for Lua scripts</div>
</div> <!-- id="product" -->

<div id="main">

<div id="navigation">

<h1>LuaCov</h1>

<ul>
    <li><strong>Home</strong>
        <ul>
            <li> <a href="index.html#over">Overview</a></li>
            <li> <a href="index.html#download">Download</a></li>
            <li> <a href="index.html#instructions">Instructions</a></li>
            <li> <a href="index.html#history">History</a></li>
            <li> <a href="index.html#credits">Credits</a></li>
        </ul>
    </li>
    <li><a href="doc/index.html">Reference</a></li>
    <li><a href="http://github.com/keplerproject/luacov">Project</a>
        <ul>
            <li><a href="http://github.com/keplerproject/luacov">Git</a></li>
        </ul>
    </li>
    <li><a href="license.html">License</a></li>
</ul>

</div> <!-- id="navigation" -->

<div id="content">

<h2><a name="over"></a>Overview</h2>

<p>
LuaCov is a simple coverage analyzer for <a href="http://www.lua.org">Lua</a>
scripts. When a Lua script is run with the <tt>luacov</tt> module loaded, it
generates a stats file with the number of executions of each line of the
script and its loaded modules. The <tt>luacov</tt> command-line script then
processes this file generating a report file which allows one to visualize
which code paths were not traversed, which is useful for verifying the
effectiveness of a test suite.
</p>

<p>
LuaCov is free software and uses the same <a href="license.html">license</a> as Lua.
</p>

<h2><a name="download"></a>Download</h2>

<p>
LuaCov can be downloaded via LuaRocks:
</p>

<div class="Example">
luarocks install luacov
</div>

<p>
There are some C extensions LuaCov can use (if they are available) to improve performance
and analysis accuracy. To install LuaCov with these extensions install
<a href="https://github.com/mpeterv/cluacov">CLuaCov</a> package instead:
</p>

<div class="Example">
luarocks install cluacov
</div>

<p>
LuaCov itself is written in pure Lua and has no external dependencies.
</p>

<p>
You can also get the code directly from <a href="http://github.com/keplerproject/luacov">the git repo</a>.
</p>

<h2><a name="instructions"></a>Instructions</h2>

<p>
Using LuaCov consists of two steps: running your script to collect
coverage data, and then running <tt>luacov</tt> on the collected data to
generate a report.
</p>

<p>
To collect coverage data, your script needs to load the <tt>luacov</tt>
Lua module. This can be done from the command-line, without modifying
your script, like this:
</p>

<div class="Example">
lua -lluacov test.lua
</div>

<p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or
</p>

<div class="Example">
lua -erequire('luacov.runner')('myconfigfilename') test.lua
</div>

<p>
(Alternatively, you can add <tt>require("luacov")</tt> to the first line
of your script.)
</p>

<p>
Once the script is run, a file called <tt>luacov.stats.out</tt> is generated.
If the file already exists, statistics are <i>added</i> to it. This is useful,
for example, for making a series of runs with different input parameters in
a test suite. To start the accounting from scratch, just delete the stats file.
</p>

<p>
To generate a report, just run the <tt>luacov</tt> command-line script.
It expects to find a file named <tt>luacov.stats.out</tt> in the current
directory, and outputs a file named <tt>luacov.report.out</tt>.
</p>

<p>This is an example output of the report file:</p>

<div class="Example"><pre>
==============================================================================
test.lua
==============================================================================
 1 if 10 > 100 then
*0    print("I don't think this line will execute.")
   else
 1    print("Hello, LuaCov!")
   end
</pre></div>

<p>
Note that to generate this report, <tt>luacov</tt> reads the source files.
Therefore, it expects to find them in the same location they were when
the <tt>luacov</tt> module ran (the stats file stores the filenames, but
not the sources themselves).
</p>

<p>
LuaCov saves its stats upon normal program termination. If your program
is a daemon -- in other words, if it does not terminate normally -- you
can use the <tt>luacov.tick</tt> module or the <tt>tick</tt> configuration option,
which periodically saves the stats file. For example, to run (on Unix systems)
LuaCov on <a href="http://keplerproject.github.io/xavante/">Xavante</a>,
just modify the first line of <tt>xavante_start.lua</tt> so it reads:
</p>

<div class="Example">
#!/usr/bin/env lua -lluacov.tick
</div>

or add this to <tt>.luacov</tt> config file:

<div class="Example">
tick = true
</div>

LuaCov includes several configuration options, which have their defaults
stored in <a href="doc/modules/luacov.defaults.html">luacov.defaults module</a>.
These are the global defaults. To use project specific configuration, create a Lua script
setting options as globals or returning a table with some options and store it as
<tt>.luacov</tt> in the project directory from where <tt>luacov</tt> is being run.
For example, this config informs LuaCov that only <tt>foo</tt> module and its submodules
should be covered and that they are located inside <tt>src</tt> directory:

<div class="Example"><pre>
modules = {
   ["foo"] = "src/foo/init.lua",
   ["foo.*"] = "src"
}
</pre></div>

<h2><a name="history"></a>History</h2>

<dl>
    <dt><strong>0.12.0</strong> [June 29, 2016]</dt>
    <dd>
        <ul>
            <li>Added support for experimental C extensions (<a href="https://github.com/mpeterv/cluacov">CLuaCov</a>).</li>
            <li>Changed config format: options are now set by assigning to globals, old format (returning a table) is still supported.</li>
            <li>Added <tt>tick</tt>config option, equivalent to using <tt>luacov.tick</tt> module.</li>
            <li>Fixed coverage data being saved to wrong file when using relative <tt>statsfile</tt> path and the program running LuaCov changes directories.</li>
            <li>Improved config loading error handling.</li>
            <li>Added <tt>:on_file_error()</tt> stub method to base reporter class, used for reporting problems when analyzing coverage data related to a file.</li>
        </ul>
    </dd>
    <dt><strong>0.11.0</strong> [April 18, 2016]</dt>
    <dd>
        <ul>
            <li>Fixed several cases of lines falsely reported as missed.</li>
            <li>Fixed <tt>luacov.tick</tt> module not working.</li>
            <li>Improved default reporter output format.</li>
            <li>Reduced coverage collection overhead.</li>
            <li>Changed how coverage is saved, it's now possible to start a child Lua process with LuaCov enabled without wrapping the launch in <tt>luacov.pause</tt> and <tt>luacov.resume</tt> in the parent.
            <li>Several minor fixes and improvements.</li>
        </ul>
    </dd>
    <dt><strong>0.10.0</strong> [February 9, 2016]</dt>
    <dd>
        <ul>
            <li>Added debug_hook() function for use in custom debug hooks.</li>
            <li>Fixed patterns passed as command-line arguments matching too much.</li>
            <li>Fixed order in which module name translations are applied</li>
        </ul>
    </dd>
    <dt><strong>0.9.1</strong> [December 7, 2015]</dt>
    <dd>
        <ul>
            <li>Fixed error when running LuaCov using Lua 5.1.</li>
        </ul>
    </dd>
    <dt><strong>0.9</strong> [December 6, 2015]</dt>
    <dd>
        <ul>
            <li>with_luacov() function for covering coroutines created via the C API.</li>
            <li>fix priorities in modules list</li>
            <li>improve coverage analysis/exclusions list</li>
            <li>improve handling of multiline function declarations</li>
            <li>LDoc documentation</li>
        </ul>
    </dd>
    <dt><strong>0.8</strong> [September 30, 2015]</dt>
    <dd>
        <ul>
            <li>Improved lexer which reduces false positives</li>
            <li>luacov.pause() and luacov.resume() functions</li>
            <li>"modules" option for configuration</li>
            <li>Plus several fixes and code cleanups.</li>
        </ul>
    </dd>
    <dt><strong>0.7</strong> [January 12, 2015]</dt>
    <dd>
        <ul>
            <li>Improvement in detection of long strings.</li>
            <li>Added "savestepsize" option.</li>
            <li>Fix handling "codefromstring" option.</li>
        </ul>
    </dd>
    <dt><strong>0.6</strong> [September 10, 2014]</dt>
    <dd>
        <ul>
            <li>Support for custom reporter objects</li>
            <li>Configuration option for processing/skipping strings</li>
            <li>Several fixes: behavior of on_exit, inclusion/exclusions lists, etc.</li>
        </ul>
    </dd>
    <dt><strong>0.5</strong> [February 8, 2014]</dt>
    <dd>
        <ul>
            <li>Improved performance in reporter module</li>
            <li>More improvements in exclusions list</li>
        </ul>
    </dd>
    <dt><strong>0.4</strong> [December 3, 2013]</dt>
    <dd>
        <ul>
            <li>Lua 5.2 compatibility fixes</li>
            <li>Several improvements in exclusions list</li>
        </ul>
    </dd>
    <dt><strong>0.3</strong> [October 10, 2012]</dt>
    <dd>
        <ul>
            <li>Added configuration options and files</li>
            <li>Summary in report</li>
            <li>Improved handling of long strings and comments</li>
            <li>Support for coroutines and os.exit()</li>
        </ul>
    </dd>
    <dt><strong>0.2</strong> [April 30, 2009]</dt>
    <dd>
        <ul>
            <li>Ignore code loaded from strings.</li>
        </ul>
    </dd>
    <dt><strong>0.1</strong> [July 16, 2007]</dt>
    <dd>
        <ul>
            <li>Initial release.</li>
        </ul>
    </dd>
</dl>

<h2><a name="credits"></a>Credits</h2>

<p>
LuaCov was originally designed and implemented by Hisham Muhammad as
a tool for testing <a href="http://luarocks.org">LuaRocks</a>. A number
of people have improved it since: see the Git logs for the full list of
contributors!
</p>

</div> <!-- id="content" -->

</div> <!-- id="main" -->

<div id="about">
    <p><a href="http://validator.w3.org/check?uri=referer">
    <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
</div> <!-- id="about" -->

</div> <!-- id="container" -->

</body>
</html>