-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: make common.mustNotCall show file:linenumber #17257
Conversation
with a message test? |
@targos do you mean by testing the message against an expected value? The only way I can think of achieving that without resulting in a call to |
I mean adding a test in test/message that results in the output you want to check. |
test/common/index.js
Outdated
err.stack; | ||
Error.prepareStackTrace = originalStackFormatter; | ||
err.stack; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how this works. There is no return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stupid mistake. Fixed and test added.
@targos test added - it actually wasn't very complicated. |
Lance... CI was generally good but I bumped the freebsd run to later in the queue to get another one of the code-and-learn PRs finished up first https://ci.nodejs.org/job/node-test-commit-freebsd/13516/ |
test/common/index.js
Outdated
@@ -568,9 +568,24 @@ exports.canCreateSymLink = function() { | |||
return true; | |||
}; | |||
|
|||
function getCallSite(level = 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Could you export this, it might be useful in other places.
- AFAIK the second argument to
Error.captureStackTrace
is a function pointer so this should be:
function getCallSite(level) {
...
Error.prepareStackTrace = (err, stack) =>
`${stack[0].getFileName()}:${stack[0].getLineNumber()}`;
...
Error.captureStackTrace(err, level);
...
const callSite = getCallSite(exports.mustNotCall);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I'm not sure why I put level
as the second arg. I will take 'hours before Thanksgiving holiday' as my excuse this time. In any case, it seems that Error.captureStackTrace
just quietly ignores that parameter it if it's not a function pointer, so things still worked.
I agree though that using the function pointer is probably a more reliable, and easier to grok way of indexing into the stack than by using an index number. Change coming soon.
You cracked half of #13115. 🤸♀️ |
@refack changes addressed. However, by exporting |
test/common/index.js
Outdated
const err = new Error(); | ||
Error.captureStackTrace(err, top); | ||
// the way V8 Error API works, the stack is not | ||
// formatted until it is accessed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fits into one line.
Another CI: https://ci.nodejs.org/job/node-test-pull-request/11688/ The first one indicated some inconsistent failures on Windows. E.g.
And... just as I pasted this, I realized the problem... |
Another CI after changes to accommodate Windows paths. |
CI looks good, with the exception of the following unrelated errors. centos6-64/usr/bin/python tools/test.py -j 2 -p tap --logfile test.tap \ --mode=release --flaky-tests=dontcare \ async-hooks default addons addons-napi \ doctool known_issues Traceback (most recent call last): File "tools/test.py", line 1759, in sys.exit(Main()) File "tools/test.py", line 1662, in Main 'type': get_env_type(vm, options.type), File "tools/test.py", line 1569, in get_env_type if "fips" in subprocess.check_output([vm, "-p", AttributeError: 'module' object has no attribute 'check_output' Makefile:408: recipe for target 'test-ci' failed make[1]: *** [test-ci] Error 1 Makefile:608: recipe for target 'run-ci' failed make: *** [run-ci] Error 2 Build step 'Execute shell' marked build as failure ubuntu1604_sharedlibs_openssl110_x6412:36:00 gyp info ok 12:36:00 touch test/addons-napi/.buildstamp 12:36:00 make[1]: write error: stdout 12:36:00 Makefile:608: recipe for target 'run-ci' failed |
@refack if this looks good to you now, I can land it. |
test/common/README.md
Outdated
@@ -136,6 +136,12 @@ Path to the 'fixtures' directory. | |||
|
|||
Returns an instance of all possible `ArrayBufferView`s of the provided Buffer. | |||
|
|||
### getCallSite(func) | |||
* `func` [<Function] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there be a >
after Function
?
@@ -568,9 +568,23 @@ exports.canCreateSymLink = function() { | |||
return true; | |||
}; | |||
|
|||
exports.getCallSite = function getCallSite(top) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better if we validated that if top
is actually a function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't really matter, in my opinion. The only place it is used is in Error.captureStackTrace()
which does that checking for us. I.e. if it's not a function, the parameter is ignored and the top frame in the stack will be where Error.captureStackTrace()
was called.
> const common = require('./test/common');
undefined
> let x = common.getCallSite()
undefined
> x
'/Users/lanceball/src/node/test/common/index.js:576'
> x = common.getCallSite('abc');
'/Users/lanceball/src/node/test/common/index.js:576'
> x = common.getCallSite(123)
'/Users/lanceball/src/node/test/common/index.js:576'
>
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.
Instead of indexing into the call stack to find the right level to store, just use the `Error.captureStackTrace()` function's second parameter - a function pointer.
Because of the way this test splits up the message string on ':' we need to ensure that the initial drive letter does not affect the string manipulation. Shortening it by 2 characters solves this.
Landed in: a322b8e |
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: #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>
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: #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>
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: #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>
Should this be backported to |
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: #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>
@gibfahn apologies for the delay on this. I am only now coming up from a lot of internal work that has prevented me from contributing to node as much as I would have liked. In any case, I'm a little more open now and will look into a backport to 6.x for this. |
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. Backport-PR-URL: #19355 PR-URL: #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>
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. Backport-PR-URL: #19355 PR-URL: #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>
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. Backport-PR-URL: #19355 PR-URL: #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>
When a test fails via
common.mustNotCall
it is sometimes hard todetermine 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 eventof failure, this information is printed.
I tried to write a test for this, butI did simulate acommon.mustNotCall()
ultimatelycalls
assert.fail()
which made it difficult to do.failure, and this is what the output looked like:
@nodejs/collaborators if you have a recommendation for testing this, I'm all ears.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test