From 8d05a1590aaeab07050e019ac892e1ebacac456d Mon Sep 17 00:00:00 2001 From: cjihrig Date: Mon, 20 Aug 2018 09:10:06 -0400 Subject: [PATCH] test: cover error case in os getCheckedFunction() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getCheckedFunction() is used internally by the os module to handle errors from the binding layer in several methods. This commit adds a test for the case where the binding layer returns an error. PR-URL: https://github.com/nodejs/node/pull/22394 Reviewed-By: Luigi Pinca Reviewed-By: Michaël Zasso Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Tobias Nießen --- test/parallel/test-os-checked-function.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/parallel/test-os-checked-function.js diff --git a/test/parallel/test-os-checked-function.js b/test/parallel/test-os-checked-function.js new file mode 100644 index 00000000000..04c2c3a1f82 --- /dev/null +++ b/test/parallel/test-os-checked-function.js @@ -0,0 +1,15 @@ +'use strict'; +// Monkey patch the os binding before requiring any other modules, including +// common, which requires the os module. +process.binding('os').getHomeDirectory = function(ctx) { + ctx.syscall = 'foo'; + ctx.code = 'bar'; + ctx.message = 'baz'; +}; + +const common = require('../common'); +const os = require('os'); + +common.expectsError(os.homedir, { + message: /^A system error occurred: foo returned bar \(baz\)$/ +});