aboutsummaryrefslogtreecommitdiff
path: root/test/common
diff options
context:
space:
mode:
authorLance Ball <lball@redhat.com>2017-11-22 13:49:50 -0500
committerLance Ball <lball@redhat.com>2017-12-04 11:43:43 -0500
commita322b8e31671a1e6b1a4581e76dd696e00a393e6 (patch)
tree1afc3e0393e25ae86df89fd11aa72dd37dee050f /test/common
parentcf4448cbd48e2da0f9461709f27b6cb41ddd2c87 (diff)
downloadandroid-node-v8-a322b8e31671a1e6b1a4581e76dd696e00a393e6.tar.gz
android-node-v8-a322b8e31671a1e6b1a4581e76dd696e00a393e6.tar.bz2
android-node-v8-a322b8e31671a1e6b1a4581e76dd696e00a393e6.zip
test: make common.mustNotCall show file:linenumber
When a test fails via `common.mustNotCall` it is sometimes hard to determine exactly what was called. This modification stores the caller's file and line number by using the V8 Error API to capture a stack at the time `common.mustNotCall()` is called. In the event of failure, this information is printed. This change also exposes a new function in test/common, `getCallSite()` which accepts a `function` and returns a `String` with the file name and line number for the function. PR-URL: https://github.com/nodejs/node/pull/17257 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Khaidi Chu <i@2333.moe>
Diffstat (limited to 'test/common')
-rw-r--r--test/common/README.md6
-rw-r--r--test/common/index.js16
2 files changed, 21 insertions, 1 deletions
diff --git a/test/common/README.md b/test/common/README.md
index 7fa47677ca..f48215836e 100644
--- a/test/common/README.md
+++ b/test/common/README.md
@@ -133,6 +133,12 @@ a reason otherwise.
Returns an instance of all possible `ArrayBufferView`s of the provided Buffer.
+### getCallSite(func)
+* `func` [&lt;Function>]
+* return [&lt;String>]
+
+Returns the file name and line number for the provided Function.
+
### globalCheck
* [&lt;Boolean>]
diff --git a/test/common/index.js b/test/common/index.js
index a78f900877..2cf188abe5 100644
--- a/test/common/index.js
+++ b/test/common/index.js
@@ -566,9 +566,23 @@ exports.canCreateSymLink = function() {
return true;
};
+exports.getCallSite = function getCallSite(top) {
+ const originalStackFormatter = Error.prepareStackTrace;
+ Error.prepareStackTrace = (err, stack) =>
+ `${stack[0].getFileName()}:${stack[0].getLineNumber()}`;
+ const err = new Error();
+ Error.captureStackTrace(err, top);
+ // with the V8 Error API, the stack is not formatted until it is accessed
+ err.stack;
+ Error.prepareStackTrace = originalStackFormatter;
+ return err.stack;
+};
+
exports.mustNotCall = function(msg) {
+ const callSite = exports.getCallSite(exports.mustNotCall);
return function mustNotCall() {
- assert.fail(msg || 'function should not have been called');
+ assert.fail(
+ `${msg || 'function should not have been called'} at ${callSite}`);
};
};