Add code coverage

This commit is contained in:
Dan Schultzer 2016-09-22 01:45:58 -07:00
parent 5aee66eb2c
commit 64b35c19b2
7 changed files with 92 additions and 13 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ out*.png
examples/*.avi
examples/tmp/*
vagrant/.vagrant
coverage/

View File

@ -68,3 +68,4 @@ Ordered by date of first contribution. [Auto-generated](https://github.com/xingr
- [vyacheslav](https://github.com/vyacheslav-lonschakov)
- vyacheslav
- [Harold Ozouf](https://github.com/jspdown)
- [Dan Schultzer](https://github.com/danschultzer)

View File

@ -39,3 +39,63 @@ travis-build:
docker build -t peterbraden/node-opencv-ubuntu-12-04 -f test/Dockerfile-ubuntu-12-04 .
docker build -t peterbraden/node-opencv-ubuntu-14-04 -f test/Dockerfile-ubuntu-14-04 .
.PHONY: travis-build
# Below build, coverage and clean tasks were partly lifted from https://github.com/geo-data/node-mapserv/blob/e99b23a44d910d444f5a45d144859758f820e1d1/Makefile
# @author danschultzer
# The location of the `istanbul` JS code coverage framework. Try and get a
# globally installed version, falling back to a local install.
ISTANBUL := $(shell which istanbul)
ifeq ($(ISTANBUL),)
ISTANBUL = ./node_modules/.bin/istanbul/lib/cli.js
endif
# The location of the `node-pre-gyp` module builder. Try and get a globally
# installed version, falling back to a local install.
NODE_PRE_GYP = $(shell which node-pre-gyp)
ifeq ($(NODE_GYP),)
NODE_PRE_GYP = ./node_modules/.bin/node-pre-gyp
endif
NODE := $(shell which node)
test_deps = build \
./test/*.js \
./lib/*.js \
$(NODE)
build: build/Debug/opencv.node
build/Debug/opencv.node:
$(NODE_PRE_GYP) --verbose --debug rebuild
# Perform the code coverage
cover: coverage/index.html
coverage/index.html: coverage/node-opencv.info
genhtml --output-directory coverage coverage/node-opencv.info
@echo "\033[0;32mPoint your browser at \`coverage/index.html\`\033[m\017"
coverage/node-opencv.info: coverage/bindings.info
lcov --test-name node-opencv \
--add-tracefile coverage/lcov.info \
--add-tracefile coverage/bindings.info \
--output-file coverage/node-opencv.info
coverage/bindings.info: coverage/addon.info
lcov --extract coverage/addon.info '*opencv/src/*' --output-file coverage/bindings.info
coverage/addon.info: coverage/lcov.info
lcov --capture --base-directory build/ --directory . --output-file coverage/addon.info
# This generates the JS lcov info as well as gcov `*.gcda` files:
coverage/lcov.info: $(test_deps) $(ISTANBUL)
DEBUG=true $(NODE) --nouse_idle_notification --expose-gc \
$(ISTANBUL) cover --report lcovonly -- test/unit.js
$(NODE_PRE_GYP):
npm install node-pre-gyp
$(ISTANBUL): package.json
npm install istanbul
@touch $(ISTANBUL)
# Clean up any generated files
clean: $(NODE_PRE_GYP)
$(NODE_PRE_GYP) clean
rm -rf coverage
rm -rf build

View File

@ -62,15 +62,31 @@
"xcode_settings": {
"OTHER_CFLAGS": [
"-mmacosx-version-min=10.7",
"-std=c++11",
"-stdlib=libc++",
"<!@(node utils/find-opencv.js --cflags)",
],
" -fprofile-arcs -ftest-coverage ",
"-std=c++11",
"-stdlib=libc++",
"<!@(node utils/find-opencv.js --cflags)",
],
"OTHER_LDFLAGS": [
"--coverage"
],
"GCC_ENABLE_CPP_RTTI": "YES",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
}
}]
]
],
"configurations": {
# This is used for generating code coverage with the `--debug` argument
"Debug": {
"conditions": [
['OS=="linux"', {
"cflags": ["-coverage"],
"ldflags": ["-coverage"]
}]
]
},
}
},
{
"target_name": "test_nativemat",
@ -119,10 +135,10 @@
"xcode_settings": {
"OTHER_CFLAGS": [
"-mmacosx-version-min=10.7",
"-std=c++11",
"-stdlib=libc++",
"<!@(node utils/find-opencv.js --cflags)",
],
"-std=c++11",
"-stdlib=libc++",
"<!@(node utils/find-opencv.js --cflags)",
],
"GCC_ENABLE_CPP_RTTI": "YES",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
}

View File

@ -1,6 +1,6 @@
var binary = require('node-pre-gyp');
var path = require('path');
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')), { debug: !!process.env.DEBUG });
var binding = require(binding_path);
//module.exports = require('../build/Release/opencv.node');

View File

@ -5,6 +5,7 @@
"author": "Peter Braden <peterbraden@peterbraden.co.uk>",
"dependencies": {
"buffers": "^0.1.1",
"istanbul": "0.4.5",
"nan": "^2.0.9",
"node-pre-gyp": "^0.6.30"
},

View File

@ -61,8 +61,8 @@ test('Matrix constructor', function(assert){
test('Matrix accessors', function(assert){
var mat = new cv.Matrix(1, 2);
mat.set(0,0,3)
mat.set(0,1,5000)
mat.set(0,0,3);
mat.set(0,1,5000);
assert.deepEqual(mat.row(0), [3,5000]);
mat = new cv.Matrix(1,2);
@ -335,7 +335,7 @@ test('LDA Wrap', function(assert) {
test('Native Matrix', function(assert) {
var nativemat = require('../build/Release/test_nativemat.node');
var nativemat = require('../build/' + (!!process.env.DEBUG ? 'Debug' : 'Release') + '/test_nativemat.node');
var mat = new cv.Matrix(42, 8);
assert.deepEqual(mat.size(), nativemat.size(mat), 'nativemat');