From 95c8df18f139ae3c2eb930018556683bc4c0807d Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Fri, 30 Jun 2017 09:25:00 +0200 Subject: [PATCH] test: add test to verify ErrnoException path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a test to verify that the path argument to ErrnoException can contain UTF-8 characters. PR-URL: https://github.com/nodejs/node/pull/13958 Reviewed-By: Anna Henningsen Reviewed-By: Tobias Nießen Reviewed-By: Gibson Fahnestock --- test/addons/errno-exception/binding.cc | 18 ++++++++++++++++++ test/addons/errno-exception/binding.gyp | 9 +++++++++ test/addons/errno-exception/test.js | 15 +++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 test/addons/errno-exception/binding.cc create mode 100644 test/addons/errno-exception/binding.gyp create mode 100644 test/addons/errno-exception/test.js diff --git a/test/addons/errno-exception/binding.cc b/test/addons/errno-exception/binding.cc new file mode 100644 index 00000000000000..1c3147ff7a2172 --- /dev/null +++ b/test/addons/errno-exception/binding.cc @@ -0,0 +1,18 @@ +#include +#include + +void Method(const v8::FunctionCallbackInfo& args) { + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope scope(isolate); + args.GetReturnValue().Set(node::ErrnoException(isolate, + 10, + "syscall", + "some error msg", + "päth")); +} + +void init(v8::Local exports) { + NODE_SET_METHOD(exports, "errno", Method); +} + +NODE_MODULE(binding, init) diff --git a/test/addons/errno-exception/binding.gyp b/test/addons/errno-exception/binding.gyp new file mode 100644 index 00000000000000..7ede63d94a0d77 --- /dev/null +++ b/test/addons/errno-exception/binding.gyp @@ -0,0 +1,9 @@ +{ + 'targets': [ + { + 'target_name': 'binding', + 'defines': [ 'V8_DEPRECATION_WARNINGS=1' ], + 'sources': [ 'binding.cc' ] + } + ] +} diff --git a/test/addons/errno-exception/test.js b/test/addons/errno-exception/test.js new file mode 100644 index 00000000000000..ddc13b7ce57ae2 --- /dev/null +++ b/test/addons/errno-exception/test.js @@ -0,0 +1,15 @@ +'use strict'; + +const common = require('../../common'); + +// Verify that the path argument to node::ErrnoException() can contain UTF-8 +// characters. + +const assert = require('assert'); +const binding = require(`./build/${common.buildType}/binding`); +const err = binding.errno(); + +assert.strictEqual(err.syscall, 'syscall'); +assert.strictEqual(err.errno, 10); +assert.strictEqual(err.path, 'päth'); +assert.ok(/^Error:\s\w+, some error msg 'päth'$/.test(err.toString()));