Skip to content

Commit 64b35c1

Browse files
committed
Add code coverage
1 parent 5aee66e commit 64b35c1

File tree

7 files changed

+92
-13
lines changed

7 files changed

+92
-13
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ out*.png
88
examples/*.avi
99
examples/tmp/*
1010
vagrant/.vagrant
11+
coverage/

CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ Ordered by date of first contribution. [Auto-generated](https://github.com/xingr
6868
- [vyacheslav](https://github.com/vyacheslav-lonschakov)
6969
- vyacheslav
7070
- [Harold Ozouf](https://github.com/jspdown)
71+
- [Dan Schultzer](https://github.com/danschultzer)

Makefile

+60
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,63 @@ travis-build:
3939
docker build -t peterbraden/node-opencv-ubuntu-12-04 -f test/Dockerfile-ubuntu-12-04 .
4040
docker build -t peterbraden/node-opencv-ubuntu-14-04 -f test/Dockerfile-ubuntu-14-04 .
4141
.PHONY: travis-build
42+
43+
44+
# Below build, coverage and clean tasks were partly lifted from https://github.com/geo-data/node-mapserv/blob/e99b23a44d910d444f5a45d144859758f820e1d1/Makefile
45+
# @author danschultzer
46+
47+
# The location of the `istanbul` JS code coverage framework. Try and get a
48+
# globally installed version, falling back to a local install.
49+
ISTANBUL := $(shell which istanbul)
50+
ifeq ($(ISTANBUL),)
51+
ISTANBUL = ./node_modules/.bin/istanbul/lib/cli.js
52+
endif
53+
54+
# The location of the `node-pre-gyp` module builder. Try and get a globally
55+
# installed version, falling back to a local install.
56+
NODE_PRE_GYP = $(shell which node-pre-gyp)
57+
ifeq ($(NODE_GYP),)
58+
NODE_PRE_GYP = ./node_modules/.bin/node-pre-gyp
59+
endif
60+
61+
NODE := $(shell which node)
62+
test_deps = build \
63+
./test/*.js \
64+
./lib/*.js \
65+
$(NODE)
66+
67+
build: build/Debug/opencv.node
68+
build/Debug/opencv.node:
69+
$(NODE_PRE_GYP) --verbose --debug rebuild
70+
71+
# Perform the code coverage
72+
cover: coverage/index.html
73+
coverage/index.html: coverage/node-opencv.info
74+
genhtml --output-directory coverage coverage/node-opencv.info
75+
@echo "\033[0;32mPoint your browser at \`coverage/index.html\`\033[m\017"
76+
coverage/node-opencv.info: coverage/bindings.info
77+
lcov --test-name node-opencv \
78+
--add-tracefile coverage/lcov.info \
79+
--add-tracefile coverage/bindings.info \
80+
--output-file coverage/node-opencv.info
81+
coverage/bindings.info: coverage/addon.info
82+
lcov --extract coverage/addon.info '*opencv/src/*' --output-file coverage/bindings.info
83+
coverage/addon.info: coverage/lcov.info
84+
lcov --capture --base-directory build/ --directory . --output-file coverage/addon.info
85+
# This generates the JS lcov info as well as gcov `*.gcda` files:
86+
coverage/lcov.info: $(test_deps) $(ISTANBUL)
87+
DEBUG=true $(NODE) --nouse_idle_notification --expose-gc \
88+
$(ISTANBUL) cover --report lcovonly -- test/unit.js
89+
90+
$(NODE_PRE_GYP):
91+
npm install node-pre-gyp
92+
93+
$(ISTANBUL): package.json
94+
npm install istanbul
95+
@touch $(ISTANBUL)
96+
97+
# Clean up any generated files
98+
clean: $(NODE_PRE_GYP)
99+
$(NODE_PRE_GYP) clean
100+
rm -rf coverage
101+
rm -rf build

binding.gyp

+25-9
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,31 @@
6262
"xcode_settings": {
6363
"OTHER_CFLAGS": [
6464
"-mmacosx-version-min=10.7",
65-
"-std=c++11",
66-
"-stdlib=libc++",
67-
"<!@(node utils/find-opencv.js --cflags)",
68-
],
65+
" -fprofile-arcs -ftest-coverage ",
66+
"-std=c++11",
67+
"-stdlib=libc++",
68+
"<!@(node utils/find-opencv.js --cflags)",
69+
],
70+
"OTHER_LDFLAGS": [
71+
"--coverage"
72+
],
6973
"GCC_ENABLE_CPP_RTTI": "YES",
7074
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
7175
}
7276
}]
73-
]
77+
],
78+
79+
"configurations": {
80+
# This is used for generating code coverage with the `--debug` argument
81+
"Debug": {
82+
"conditions": [
83+
['OS=="linux"', {
84+
"cflags": ["-coverage"],
85+
"ldflags": ["-coverage"]
86+
}]
87+
]
88+
},
89+
}
7490
},
7591
{
7692
"target_name": "test_nativemat",
@@ -119,10 +135,10 @@
119135
"xcode_settings": {
120136
"OTHER_CFLAGS": [
121137
"-mmacosx-version-min=10.7",
122-
"-std=c++11",
123-
"-stdlib=libc++",
124-
"<!@(node utils/find-opencv.js --cflags)",
125-
],
138+
"-std=c++11",
139+
"-stdlib=libc++",
140+
"<!@(node utils/find-opencv.js --cflags)",
141+
],
126142
"GCC_ENABLE_CPP_RTTI": "YES",
127143
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
128144
}

lib/bindings.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var binary = require('node-pre-gyp');
22
var path = require('path');
3-
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
3+
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')), { debug: !!process.env.DEBUG });
44
var binding = require(binding_path);
55

66
//module.exports = require('../build/Release/opencv.node');

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"author": "Peter Braden <[email protected]>",
66
"dependencies": {
77
"buffers": "^0.1.1",
8+
"istanbul": "0.4.5",
89
"nan": "^2.0.9",
910
"node-pre-gyp": "^0.6.30"
1011
},

test/unit.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ test('Matrix constructor', function(assert){
6161

6262
test('Matrix accessors', function(assert){
6363
var mat = new cv.Matrix(1, 2);
64-
mat.set(0,0,3)
65-
mat.set(0,1,5000)
64+
mat.set(0,0,3);
65+
mat.set(0,1,5000);
6666
assert.deepEqual(mat.row(0), [3,5000]);
6767

6868
mat = new cv.Matrix(1,2);
@@ -335,7 +335,7 @@ test('LDA Wrap', function(assert) {
335335

336336

337337
test('Native Matrix', function(assert) {
338-
var nativemat = require('../build/Release/test_nativemat.node');
338+
var nativemat = require('../build/' + (!!process.env.DEBUG ? 'Debug' : 'Release') + '/test_nativemat.node');
339339
var mat = new cv.Matrix(42, 8);
340340

341341
assert.deepEqual(mat.size(), nativemat.size(mat), 'nativemat');

0 commit comments

Comments
 (0)