Skip to content

Commit

Permalink
test: add ability to control experimental tests
Browse files Browse the repository at this point in the history
Add the ability to specify a NAPI_VERSION which
limits the tests executed to those supported by that
version.

As an example tests can be built/run as:
  npm test --NAPI_VERSION=3

Fixes: nodejs#349
  • Loading branch information
mhdawson committed Sep 19, 2018
1 parent b6e2d92 commit 615d54f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"scripts": {
"pretest": "node-gyp rebuild -C test",
"test": "node test",
"test": "NAPI_VERSION=$NODE_VERSION node test",
"doc": "doxygen doc/Doxyfile"
},
"version": "1.4.0"
Expand Down
5 changes: 5 additions & 0 deletions test/bigint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

using namespace Napi;

// currently experimental guard with version of NAPI_VERSION that it is
// released in once it is no longer experimental
#if (NAPI_VERSION > 2147483646)
namespace {

Value IsLossless(const CallbackInfo& info) {
Expand Down Expand Up @@ -74,3 +77,5 @@ Object InitBigInt(Env env) {

return exports;
}

#endif
4 changes: 4 additions & 0 deletions test/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ Object Init(Env env, Object exports) {
exports.Set("basic_types_boolean", InitBasicTypesBoolean(env));
exports.Set("basic_types_number", InitBasicTypesNumber(env));
exports.Set("basic_types_value", InitBasicTypesValue(env));
// currently experimental guard with version of NAPI_VERSION that it is
// released in once it is no longer experimental
#if (NAPI_VERSION > 2147483646)
exports.Set("bigint", InitBigInt(env));
#endif
exports.Set("buffer", InitBuffer(env));
exports.Set("dataview", InitDataView(env));
exports.Set("dataview_read_write", InitDataView(env));
Expand Down
6 changes: 6 additions & 0 deletions test/binding.gyp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
'variables': {
'NAPI_VERSION%': ""
},
'target_defaults': {
'sources': [
'arraybuffer.cc',
Expand Down Expand Up @@ -29,6 +32,9 @@
'objectreference.cc',
'version_management.cc'
],
'conditions': [
['NAPI_VERSION!=""', { 'defines': ['NAPI_VERSION=<@(NAPI_VERSION)'] } ]
],
'include_dirs': ["<!@(node -p \"require('../').include\")"],
'dependencies': ["<!(node -p \"require('../').gyp\")"],
'cflags': [ '-Werror', '-Wall', '-Wextra', '-Wpedantic', '-Wunused-parameter' ],
Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ let testModules = [
'version_management'
];

if(process.env.NAPI_VERSION < 2147483647 ){
// currently experimental only test if NAPI_VERSION
// is set to experimental
// once bigint is in a release this should be guarged
// on the napi version supported by the current
// node being tested
testModules.splice(testModules.indexOf('bigint'), 1);
}

if (typeof global.gc === 'function') {
console.log('Starting test suite\n');

Expand Down
16 changes: 16 additions & 0 deletions test/typedarray.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Value CreateTypedArray(const CallbackInfo& info) {
NAPI_TYPEDARRAY_NEW(Float64Array, info.Env(), length, napi_float64_array) :
NAPI_TYPEDARRAY_NEW_BUFFER(Float64Array, info.Env(), length, buffer, bufferOffset,
napi_float64_array);
// currently experimental guard with version of NAPI_VERSION that it is
// released in once it is no longer experimental
#if (NAPI_VERSION > 2147483646)
} else if (arrayType == "bigint64") {
return buffer.IsUndefined() ?
NAPI_TYPEDARRAY_NEW(BigInt64Array, info.Env(), length, napi_bigint64_array) :
Expand All @@ -75,6 +78,7 @@ Value CreateTypedArray(const CallbackInfo& info) {
NAPI_TYPEDARRAY_NEW(BigUint64Array, info.Env(), length, napi_biguint64_array) :
NAPI_TYPEDARRAY_NEW_BUFFER(BigUint64Array, info.Env(), length, buffer, bufferOffset,
napi_biguint64_array);
#endif
} else {
Error::New(info.Env(), "Invalid typed-array type.").ThrowAsJavaScriptException();
return Value();
Expand All @@ -97,8 +101,12 @@ Value GetTypedArrayType(const CallbackInfo& info) {
case napi_uint32_array: return String::New(info.Env(), "uint32");
case napi_float32_array: return String::New(info.Env(), "float32");
case napi_float64_array: return String::New(info.Env(), "float64");
// currently experimental guard with version of NAPI_VERSION that it is
// released in once it is no longer experimental
#if (NAPI_VERSION > 2147483646)
case napi_bigint64_array: return String::New(info.Env(), "bigint64");
case napi_biguint64_array: return String::New(info.Env(), "biguint64");
#endif
default: return String::New(info.Env(), "invalid");
}
}
Expand Down Expand Up @@ -135,10 +143,14 @@ Value GetTypedArrayElement(const CallbackInfo& info) {
return Number::New(info.Env(), array.As<Float32Array>()[index]);
case napi_float64_array:
return Number::New(info.Env(), array.As<Float64Array>()[index]);
// currently experimental guard with version of NAPI_VERSION that it is
// released in once it is no longer experimental
#if (NAPI_VERSION > 2147483646)
case napi_bigint64_array:
return BigInt::New(info.Env(), array.As<BigInt64Array>()[index]);
case napi_biguint64_array:
return BigInt::New(info.Env(), array.As<BigUint64Array>()[index]);
#endif
default:
Error::New(info.Env(), "Invalid typed-array type.").ThrowAsJavaScriptException();
return Value();
Expand Down Expand Up @@ -177,6 +189,9 @@ void SetTypedArrayElement(const CallbackInfo& info) {
case napi_float64_array:
array.As<Float64Array>()[index] = value.DoubleValue();
break;
// currently experimental guard with version of NAPI_VERSION that it is
// released in once it is no longer experimental
#if (NAPI_VERSION > 2147483646)
case napi_bigint64_array: {
bool lossless;
array.As<BigInt64Array>()[index] = value.As<BigInt>().Int64Value(&lossless);
Expand All @@ -187,6 +202,7 @@ void SetTypedArrayElement(const CallbackInfo& info) {
array.As<BigUint64Array>()[index] = value.As<BigInt>().Uint64Value(&lossless);
break;
}
#endif
default:
Error::New(info.Env(), "Invalid typed-array type.").ThrowAsJavaScriptException();
}
Expand Down
4 changes: 4 additions & 0 deletions test/typedarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ function test(binding) {
}
});

// currently experimental, guard qurg NAPI_VERSION it
// is related in once no longer experimntal
if(process.env.NAPI_VERSION > 2147483646 ){
[
['bigint64', BigInt64Array],
['biguint64', BigUint64Array],
Expand Down Expand Up @@ -110,6 +113,7 @@ function test(binding) {
throw e;
}
});
}

assert.throws(() => {
binding.typedarray.createInvalidTypedArray();
Expand Down

0 comments on commit 615d54f

Please sign in to comment.