GithubHelp home page GithubHelp logo

lipp / luacov Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lunarmodules/luacov

0.0 2.0 0.0 309 KB

LuaCov is a simple coverage analyzer for Lua code.

Home Page: http://keplerproject.github.com/luacov/

Shell 7.80% Lua 92.20%

luacov's Introduction

Overview

LuaCov is a simple coverage analyzer for Lua scripts. When a Lua script is run with the luacov module loaded, it generates a stats file with the number of executions of each line of the script and its loaded modules. The luacov 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.

LuaCov is free software and, like Lua, is released under the MIT License.

Download and Installation

LuaCov can be downloaded from its LuaForge page.

It can also be installed using Luarocks:

luarocks install luacov

LuaCov is written in pure Lua and has no external dependencies.

Instructions

Using LuaCov consists of two steps: running your script to collect coverage data, and then running luacov on the collected data to generate a report (see configuration below for other options).

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

lua -lluacov test.lua

Alternatively, you can add require("luacov") to the first line of your script.

Once the script is run, a file called luacov.stats.out is generated. If the file already exists, statistics are added 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.

To generate a report, just run the luacov command-line script. It expects to find a file named luacov.stats.out in the current directory, and outputs a file named luacov.report.out. The script take the following parameters;

luacov [-c=configfile] [filename [ filename[ ...]]]

For the -c option see below at configuration. The filenames (actually patterns) indicate the files to include in the report, specifying them here equals to adding them to the include list in the configuration file.

This is an example output of the report file:

============================================================
../test.lua
============================================================

        -- Which branch will run?
1       if 10 > 100 then
0          print("I don't think this line will execute.")
0       else
1          print("Hello, LuaCov!")
1       end

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

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 luacov.tick module, which periodically saves the stats file. For example, to run (on Unix systems) LuaCov on Xavante, just modify the first line of xavante_start.lua so it reads:

#!/usr/bin/env lua -lluacov.tick

Configuration

LuaCov includes several configuration options, which have their defaults stored in /luacov/defaults.lua. These are the global defaults. To create project specific defaults, copy the file and store it as .luacov in the project directory from where luacov is being run.

Options include changing filenames, automatic report generation upon completion and removal of the stats after generating the report.

Credits

LuaCov was designed and implemented by Hisham Muhammad as a tool for testing Luarocks.

luacov's People

Contributors

akavel avatar geoffleyland avatar hishamhm avatar lipp avatar mascarenhas avatar norman avatar tieske avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.