Add cpp test framework

This commit is contained in:
Luis Blanco 2020-03-17 10:50:42 +03:00
parent 5434ac9ee8
commit c6435911f6
8 changed files with 17673 additions and 22 deletions

1
.gitignore vendored
View File

@ -7,4 +7,5 @@
.vscode
.eslintrc
node_modules/
test/build/
*.log

View File

@ -18,3 +18,9 @@ matrix:
install:
- cd test
- npm ci
- cd ..
test:
- cd test
- npm test
- ./build/release/test

View File

@ -104,7 +104,7 @@
#define LET_UINT32_ARG(I, VAR) USE_UINT32_ARG(I, VAR, 0)
#define REQ_UINT_ARG(I, VAR) REQ_UINT_ARG(I, VAR)
#define REQ_UINT_ARG(I, VAR) REQ_UINT32_ARG(I, VAR)
#define USE_UINT_ARG(I, VAR, DEF) USE_UINT32_ARG(I, VAR, DEF)
#define LET_UINT_ARG(I, VAR) LET_UINT32_ARG(I, VAR)
@ -181,7 +181,7 @@
CHECK_LET_ARG(I, IsObject(), "Object"); \
Napi::Object VAR = IS_ARG_EMPTY(I) ? (DEF) : info[I].As<Napi::Object>();
#define LET_OBJ_ARG(I, VAR) USE_OBJ_ARG(I, VAR, info[I].As<Napi::Object>())
#define LET_OBJ_ARG(I, VAR) USE_OBJ_ARG(I, VAR, Napi::Object::New(env))
#define REQ_ARRV_ARG(I, VAR) \
@ -195,12 +195,14 @@
#define REQ_ARRAY_ARG(I, VAR) \
REQ_OBJ_ARG(I, _obj_##VAR); \
if ( ! _obj_##VAR.IsArray() ) { \
JS_THROW("Argument " #I " must be of type `Array`"); \
RET_UNDEFINED; \
} \
Napi::Array VAR = _obj_##VAR.As<Napi::Array>();
CHECK_REQ_ARG(I, IsArray(), "Array"); \
Napi::Array VAR = info[I].As<Napi::Array>();
#define USE_ARRAY_ARG(I, VAR, DEF) \
CHECK_LET_ARG(I, IsArray(), "Array"); \
Napi::Array VAR = IS_ARG_EMPTY(I) ? (DEF) : info[I].As<Napi::Array>();
#define LET_ARRAY_ARG(I, VAR) USE_ARRAY_ARG(I, VAR, Napi::Array::New(env))
#define REQ_TYPED_ARRAY_ARG(I, VAR) \

20
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "addon-tools-raub",
"version": "5.0.0",
"version": "5.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -153,9 +153,9 @@
}
},
"node-addon-api": {
"version": "1.7.1",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-1.7.1.tgz",
"integrity": "sha512-2+DuKodWvwRTrCfKOeR24KIc5unKjOh8mz17NCzVnHWfjAdDqbfbjqh7gUT+BkXBRQM52+xCHciKWonJ3CbJMQ=="
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.0.tgz",
"integrity": "sha512-ASCL5U13as7HhOExbT6OlWJJUV/lLzL2voOSP1UVehpRD8FbSrSDjfScK/KwAvVTI5AS6r4VwbOMlIqtvRidnA=="
},
"once": {
"version": "1.4.0",
@ -176,9 +176,9 @@
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
},
"readable-stream": {
"version": "2.3.6",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
"version": "2.3.7",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz",
"integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==",
"requires": {
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
@ -221,9 +221,9 @@
"integrity": "sha1-cXuPIgzAu3tE5AUUwisui7xw2Lk="
},
"unzipper": {
"version": "0.10.5",
"resolved": "https://registry.npmjs.org/unzipper/-/unzipper-0.10.5.tgz",
"integrity": "sha512-i5ufkXNjWZYxU/0nKKf6LkvW8kn9YzRvfwuPWjXP+JTFce/8bqeR0gEfbiN2IDdJa6ZU6/2IzFRLK0z1v0uptw==",
"version": "0.10.10",
"resolved": "https://registry.npmjs.org/unzipper/-/unzipper-0.10.10.tgz",
"integrity": "sha512-wEgtqtrnJ/9zIBsQb8UIxOhAH1eTHfi7D/xvmrUoMEePeI6u24nq1wigazbIFtHt6ANYXdEVTvc8XYNlTurs7A==",
"requires": {
"big-integer": "^1.6.17",
"binary": "~0.3.0",

View File

@ -1,7 +1,7 @@
{
"author": "Luis Blanco <luisblanco1337@gmail.com>",
"name": "addon-tools-raub",
"version": "5.0.0",
"version": "5.0.1",
"description": "Helpers for Node.js addons and dependency packages",
"license": "MIT",
"main": "index.js",
@ -37,7 +37,7 @@
"url": "https://github.com/node-3d/addon-tools-raub.git"
},
"dependencies": {
"node-addon-api": "1.7.1",
"unzipper": "0.10.5"
"node-addon-api": "2.0.0",
"unzipper": "0.10.10"
}
}

14
test/binding.gyp Normal file
View File

@ -0,0 +1,14 @@
{
'targets': [
{
'target_name': 'test',
'type': 'executable',
'sources': [
'test.cpp',
],
'include_dirs': [
'<!@(node -p "require(\'..\').include")',
],
},
],
}

17615
test/catch.hpp Normal file

File diff suppressed because it is too large Load Diff

13
test/test.cpp Normal file
View File

@ -0,0 +1,13 @@
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include "catch.hpp"
unsigned int Factorial( unsigned int number ) {
return number <= 1 ? number : Factorial(number-1)*number;
}
TEST_CASE( "Factorials are computed", "[factorial]" ) {
REQUIRE( Factorial(1) == 1 );
REQUIRE( Factorial(2) == 2 );
REQUIRE( Factorial(3) == 6 );
REQUIRE( Factorial(10) == 3628800 );
}