Skip to content

Commit 0677e83

Browse files
authored
Merge pull request #445 from peterbraden/code-coverage
Code coverage
2 parents 5aee66e + da7e707 commit 0677e83

File tree

11 files changed

+133
-29
lines changed

11 files changed

+133
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
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/

.travis.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ before_install:
3030
- sudo add-apt-repository -y ppa:kubuntu-ppa/backports
3131
- sudo apt-get update
3232
- sudo apt-get install --force-yes --yes libcv-dev libcvaux-dev libhighgui-dev libopencv-dev
33+
# for code coverage
34+
- sudo apt-get install lcov
3335
# get commit message
3436
- COMMIT_MESSAGE=$(git show -s --format=%B $TRAVIS_COMMIT | tr -d '\n')
3537
# put local node-pre-gyp on PATH
@@ -49,11 +51,11 @@ before_install:
4951
- platform=$(uname -s | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/")
5052

5153
install:
52-
# ensure source install works
53-
- npm install --build-from-source
54-
# test our module
55-
- npm test
56-
- node lib/opencv.js
54+
# install dependencies first
55+
- npm install
56+
# build from source, run test and generate code coverage
57+
- make cover
58+
- DEBUG=true node lib/opencv.js
5759
- docker build -t peterbraden/node-opencv-ubuntu-12-04 -f test/Dockerfile-ubuntu-12-04 .
5860
- docker build -t peterbraden/node-opencv-ubuntu-14-04 -f test/Dockerfile-ubuntu-14-04 .
5961

@@ -81,3 +83,5 @@ script:
8183
after_success:
8284
# if success then query and display all published binaries
8385
- node-pre-gyp info
86+
# Upload coverage to codecov
87+
- bash <(curl -s https://codecov.io/bash) -s coverage -f *.info

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
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

Lines changed: 60 additions & 0 deletions
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

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# node-opencv
22

33
[![Build Status](https://secure.travis-ci.org/peterbraden/node-opencv.png)](http://travis-ci.org/peterbraden/node-opencv)
4-
4+
[![Coverage](http://codecov.io/github/peterbraden/node-opencv/coverage.svg?branch=master)](https://codecov.io/gh/peterbraden/node-opencv)
55

66
[OpenCV](http://opencv.org) bindings for Node.js. OpenCV is
77
the defacto computer vision library - by interfacing with it natively in node,
@@ -223,6 +223,20 @@ contours.approxPolyDP(index, epsilon, isClosed);
223223
contours.convexHull(index, clockwise);
224224
```
225225

226+
## Test
227+
228+
Using [tape](https://github.com/substack/tape). Run with command:
229+
230+
`npm test`.
231+
232+
## Code coverage
233+
234+
Using [istanbul](http://gotwarlost.github.io/istanbul/) and [lcov](http://ltp.sourceforge.net/coverage/lcov.php). Run with command:
235+
236+
`make cover`
237+
238+
Build version of `opencv.node` will be generated, and coverage files will be put in `coverage/` directory. These files can be remvoved automatically by running `make clean`.
239+
226240
## MIT License
227241
The library is distributed under the MIT License - if for some reason that
228242
doesn't work for you please get in touch.

binding.gyp

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,41 @@
6060
[ # cflags on OS X are stupid and have to be defined like this
6161
"OS==\"mac\"", {
6262
"xcode_settings": {
63-
"OTHER_CFLAGS": [
64-
"-mmacosx-version-min=10.7",
65-
"-std=c++11",
66-
"-stdlib=libc++",
67-
"<!@(node utils/find-opencv.js --cflags)",
63+
"OTHER_CFLAGS": [
64+
"-mmacosx-version-min=10.7",
65+
"-std=c++11",
66+
"-stdlib=libc++",
67+
"<!@(node utils/find-opencv.js --cflags)",
6868
],
69-
"GCC_ENABLE_CPP_RTTI": "YES",
70-
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
69+
"GCC_ENABLE_CPP_RTTI": "YES",
70+
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
71+
}
7172
}
72-
}]
73-
]
73+
]
74+
],
75+
76+
"configurations": {
77+
# This is used for generating code coverage with the `--debug` argument
78+
"Debug": {
79+
"conditions": [
80+
['OS=="linux"', {
81+
"cflags": ["-coverage"],
82+
"ldflags": ["-coverage"]
83+
}],
84+
['OS=="mac"', {
85+
"xcode_settings": {
86+
"OTHER_CFLAGS": [
87+
"-fprofile-arcs -ftest-coverage",
88+
],
89+
"OTHER_LDFLAGS": [
90+
"--coverage"
91+
]
92+
}
93+
}]
94+
95+
]
96+
},
97+
}
7498
},
7599
{
76100
"target_name": "test_nativemat",
@@ -119,10 +143,10 @@
119143
"xcode_settings": {
120144
"OTHER_CFLAGS": [
121145
"-mmacosx-version-min=10.7",
122-
"-std=c++11",
123-
"-stdlib=libc++",
124-
"<!@(node utils/find-opencv.js --cflags)",
125-
],
146+
"-std=c++11",
147+
"-stdlib=libc++",
148+
"<!@(node utils/find-opencv.js --cflags)",
149+
],
126150
"GCC_ENABLE_CPP_RTTI": "YES",
127151
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
128152
}

examples/test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
var cv = require('../lib/opencv');
22

3-
var mat = new cv.Matrix(1, 2, cv.Constants.CV_8U, [1]);
3+
var mat = new cv.Matrix(1, 2, cv.Constants.CV_8UC3, [1]);
44
var row = mat.pixelRow(0);
55
console.log("mat: " + row[0] + row[1]);
6-

lib/bindings.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"author": "Peter Braden <peterbraden@peterbraden.co.uk>",
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
},

src/Matrix.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ double Matrix::DblGet(cv::Mat mat, int i, int j) {
198198

199199
switch (mat.type()) {
200200
case CV_32FC3:
201-
pix = mat.at<cv::Vec3b>(i, j);
201+
pix = mat.at<cv::Vec3f>(i, j);
202202
pint |= (uchar) pix.val[2];
203203
pint |= ((uchar) pix.val[1]) << 8;
204204
pint |= ((uchar) pix.val[0]) << 16;
@@ -281,9 +281,9 @@ NAN_METHOD(Matrix::Set) {
281281
switch (self->mat.type()) {
282282
case CV_32FC3:
283283
vint = static_cast<unsigned int>(val + 0.5);
284-
self->mat.at<cv::Vec3b>(i, j)[0] = (uchar) (vint >> 16) & 0xff;
285-
self->mat.at<cv::Vec3b>(i, j)[1] = (uchar) (vint >> 8) & 0xff;
286-
self->mat.at<cv::Vec3b>(i, j)[2] = (uchar) (vint) & 0xff;
284+
self->mat.at<cv::Vec3f>(i, j)[0] = (uchar) (vint >> 16) & 0xff;
285+
self->mat.at<cv::Vec3f>(i, j)[1] = (uchar) (vint >> 8) & 0xff;
286+
self->mat.at<cv::Vec3f>(i, j)[2] = (uchar) (vint) & 0xff;
287287
// printf("!!!i %x, %x, %x", (vint >> 16) & 0xff, (vint >> 8) & 0xff, (vint) & 0xff);
288288
break;
289289
default:

test/unit.js

Lines changed: 3 additions & 3 deletions
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)