diff --git a/test/node_modules/test_action1/binding.gyp b/test/node_modules/test_action1/binding.gyp new file mode 100644 index 0000000000..e7da730e16 --- /dev/null +++ b/test/node_modules/test_action1/binding.gyp @@ -0,0 +1,28 @@ +{ + "targets": [ + { + "target_name": "hello", + "conditions": [ + [ 'OS!="win"' , { + 'variables': { + "copy_action" : 'cp' + } + }, { + 'variables': { + "copy_action" : 'copy' + } + } ], + ], + "actions" : [ + { + "msvs_quote_cmd": 0, + "action_name" : "action_test_no_encode", + "inputs": ["hello.txt"], + "outputs": ["<(PRODUCT_DIR)/hello.cc.copy"], + "action": ['<(copy_action) "<(RULE_INPUT_PATH)>" "<(PRODUCT_DIR)/hello.txt.copy" & \ + echo <(PRODUCT_DIR)/hello.txt.copy > <(RULE_INPUT_DIRNAME)/loc.txt'] + } + ] + } + ] +} diff --git a/test/node_modules/test_action1/hello.txt b/test/node_modules/test_action1/hello.txt new file mode 100644 index 0000000000..89bfd7ac04 --- /dev/null +++ b/test/node_modules/test_action1/hello.txt @@ -0,0 +1,12 @@ +#include + +void Method(const Nan::FunctionCallbackInfo& info) { + info.GetReturnValue().Set(Nan::New("world").ToLocalChecked()); +} + +void Init(v8::Local exports) { + exports->Set(Nan::New("hello").ToLocalChecked(), + Nan::New(Method)->GetFunction()); +} + +NODE_MODULE(hello, Init) diff --git a/test/node_modules/test_action1/package.json b/test/node_modules/test_action1/package.json new file mode 100644 index 0000000000..b09778c334 --- /dev/null +++ b/test/node_modules/test_action1/package.json @@ -0,0 +1,15 @@ +{ + "name": "hello_world", + "version": "0.0.0", + "description": "Node.js Addons Example #1", + "main": "hello.js", + "private": true, + "dependencies": { + "bindings": "~1.2.1", + "nan": "^2.0.0" + }, + "scripts": { + "test": "node hello.js" + }, + "gypfile": true +} diff --git a/test/node_modules/test_action2/binding.gyp b/test/node_modules/test_action2/binding.gyp new file mode 100644 index 0000000000..c723513901 --- /dev/null +++ b/test/node_modules/test_action2/binding.gyp @@ -0,0 +1,28 @@ +{ + "targets": [ + { + "target_name": "hello", + "conditions": [ + [ 'OS!="win"' , { + 'variables': { + "copy_action" : 'cp' + } + }, { + 'variables': { + "copy_action" : 'copy' + } + } ], + ], + "actions" : [ + { + "msvs_quote_cmd": 1, + "action_name" : "action_test_with_encode", + "inputs": ["hello.txt"], + "outputs": ["<(PRODUCT_DIR)/hello.cc.copy"], + "action": ['<(copy_action) "<(RULE_INPUT_PATH)>" "<(PRODUCT_DIR)/hello.txt.copy" & \ + echo <(PRODUCT_DIR)/hello.txt.copy > <(RULE_INPUT_DIRNAME)/loc.txt'] + } + ] + } + ] +} diff --git a/test/node_modules/test_action2/hello.txt b/test/node_modules/test_action2/hello.txt new file mode 100644 index 0000000000..89bfd7ac04 --- /dev/null +++ b/test/node_modules/test_action2/hello.txt @@ -0,0 +1,12 @@ +#include + +void Method(const Nan::FunctionCallbackInfo& info) { + info.GetReturnValue().Set(Nan::New("world").ToLocalChecked()); +} + +void Init(v8::Local exports) { + exports->Set(Nan::New("hello").ToLocalChecked(), + Nan::New(Method)->GetFunction()); +} + +NODE_MODULE(hello, Init) diff --git a/test/node_modules/test_action2/package.json b/test/node_modules/test_action2/package.json new file mode 100644 index 0000000000..b09778c334 --- /dev/null +++ b/test/node_modules/test_action2/package.json @@ -0,0 +1,15 @@ +{ + "name": "hello_world", + "version": "0.0.0", + "description": "Node.js Addons Example #1", + "main": "hello.js", + "private": true, + "dependencies": { + "bindings": "~1.2.1", + "nan": "^2.0.0" + }, + "scripts": { + "test": "node hello.js" + }, + "gypfile": true +} diff --git a/test/test-gyp-patches.js b/test/test-gyp-patches.js new file mode 100644 index 0000000000..bea07f60e5 --- /dev/null +++ b/test/test-gyp-patches.js @@ -0,0 +1,47 @@ +'use strict' + +var test = require('tape') +var execFile = require('child_process').execFile +var path = require('path') +var fs = require('fs') +var nodeGyp = path.resolve(__dirname, '..', 'bin', 'node-gyp.js') + +test('#1151 build addon with an action', function (t) { + t.plan(3) + + var addonPath = path.resolve(__dirname, 'node_modules', 'test_action1') + // Set the loglevel otherwise the output disappears when run via 'npm test' + var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose'] + var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) { + var logLines = stderr.toString().trim().split(/\r?\n/) + var lastLine = logLines[logLines.length - 1] + t.notOk(err) + t.strictEqual(lastLine, 'gyp info ok', 'should end in ok') + var locPath = path.resolve(addonPath, 'loc.txt') + var loc = fs.readFileSync(locPath, {encoding: 'utf-8'}).trim() + fs.unlinkSync(locPath); + t.ok(fs.existsSync(loc)); + }) + proc.stdout.setEncoding('utf-8') + proc.stderr.setEncoding('utf-8') +}) + +test('#1151 build addon with an action 2', function (t) { + t.plan(3) + + var addonPath = path.resolve(__dirname, 'node_modules', 'test_action2') + // Set the loglevel otherwise the output disappears when run via 'npm test' + var cmd = [nodeGyp, 'rebuild', '-C', addonPath, '--loglevel=verbose'] + var proc = execFile(process.execPath, cmd, function (err, stdout, stderr) { + var logLines = stderr.toString().trim().split(/\r?\n/) + var lastLine = logLines[logLines.length - 1] + t.notOk(err) + t.strictEqual(lastLine, 'gyp info ok', 'should end in ok') + var locPath = path.resolve(addonPath, 'loc.txt') + var loc = fs.readFileSync(locPath, {encoding: 'utf-8'}).trim() + fs.unlinkSync(locPath); + t.ok(fs.existsSync(loc)); + }) + proc.stdout.setEncoding('utf-8') + proc.stderr.setEncoding('utf-8') +})