-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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: add a common.debuglog function #22206
Conversation
@gibfahn: the test passes when invoked with How do I fix this? |
@SirR4T Please see #21914 (comment). I'd suggest that rather than hijack stderr the test should instead spawn another process (with |
thanks @richardlau ! fixed the test cases now. |
test/common/README.md
Outdated
* `msg` [<string>] The string to be printed to stderr | ||
* `msgs` [<string>] Additional arguments to the function | ||
|
||
Prints messages (optionally, formatted using `fmt`) to `process.stderr`, using `util.debuglog('test')`. |
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.
Not sure why linter does not warn about this (maybe we do not lint docs outside api
?) but it seems this line needs to be wrapped at 80 characters or less)
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.
@vsemozhetbyt test
is omitted from the markdown linting. I have a PR in the works to add it. Will have it ready to be opened today, I think.
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.
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.
Left some inline comments.
With regards to the test, it would be good to add the case where NODE_DEBUG
is not set (no output expected) and/or possiblty also if NODE_DEBUG
is set to something other than test
.
const common = require('../common'); | ||
|
||
// argv[0] is the execPath, argv[1] is the test script filename | ||
common.debuglog.apply(null, process.argv.slice(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.
This should either be inlined into the new test/parallel/test-common-debuglog.js
(see test/parallel/test-child-process-spawnsync-env.js
for how tests that spawn other processes are typically written) or this file should be moved to test/fixtures
.
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.
will move it to test/fixtures
, since the same file will need to be invoked with on different child processes... Inlining it might make it needlessly complex, to test for different values of NODE_DEBUG
@@ -0,0 +1,18 @@ | |||
'use strict'; | |||
|
|||
const common = require('../common'); // eslint-disable-line no-unused-vars |
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.
Just write
require('../common');
instead of disabling the lint rule.
b1b2463
to
cee02c7
Compare
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.
LGTM! 🎉
You might want to wrap that long line at 80 chars, though.
cee02c7
to
8363dcf
Compare
@sagirk sorry, missed that! pushed now, thanks! |
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.
Left a couple of suggestions, otherwise LGTM.
{ | ||
process.env.NODE_DEBUG = 'test'; | ||
const { stderr } = spawnSync(process.execPath, [ | ||
path.resolve(__dirname, '../fixtures/common-debuglog.js'), |
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.
Use fixtures.path
from https://github.com/nodejs/node/blob/master/test/common/README.md#fixtures-module.
test/common/README.md
Outdated
* `msgs` [<string>] Additional arguments to the function | ||
|
||
Prints messages (optionally, formatted using `fmt`) to `process.stderr`, | ||
using `util.debuglog('test')`. |
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.
Perhaps the wording should clarify that the messages are conditionally printed to stderr based on the value of NODE_DEBUG
?
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.
Or maybe omit the stderr part, e.g.
* `msg` [<string>] The string to be printed
and
Prints messages (optionally, formatted using `fmt`) using `util.debuglog('test')`.
test/fixtures/common-debuglog.js
Outdated
const common = require('../common'); | ||
|
||
// argv[0] is the execPath, argv[1] is the test script filename | ||
common.debuglog.apply(null, process.argv.slice(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 this be simplified to
common.debuglog(process.argv.slice(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.
that ends up printing TEST 2461: [ 'message' ]
instead of TEST 2461: message
, since slice returns an array. So resorted to common.debuglog(...process.argv.slice(2))
instead.
37ca6e2
to
80295d8
Compare
Could stand to get one more approval. @nodejs/testing |
(Not approving myself because I generally don't 👍 adding stuff to |
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 am -0 on this. I agree with @Trott that we have a lot in common already and adding more is not ideal. Besides the fact that we could just all agree on always using test
in which case it would be possible to just directly use util.debuglog()
.
80295d8
to
8942222
Compare
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.
Doing design review
Hello @SirR4T and thank you very much for this contribution.
|
Given that the PR does not touch test.py and does not change test.py, how are these questions relevant to this PR? |
I definitely believe so in that it makes the intent of the statements far more explicit and gives clear separation between output that is purely intended as debug output vs. output that is part of exercising the test. |
When running tests through
If we move tracing output to use |
Hi @refack !
|
8942222
to
68a4476
Compare
Hi @refack ! how do we proceed on this? |
68a4476
to
93aa055
Compare
Hi @refack ! Ping! how do we move forward here? |
@nodejs/tsc please weight in. |
I'm against this change, since |
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.
Seems like a convenient and readable thing to have in the tests. LGTM.
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.
LGTM
cc @Trott there are a lot of console.log()
statements in test/parallel
, it might be good for code&learn exercises.
@@ -804,3 +804,6 @@ exports.runWithInvalidFD = function(func) { | |||
|
|||
exports.printSkipMessage('Could not generate an invalid fd'); | |||
}; | |||
|
|||
const utilDebugLog = util.debuglog('test'); |
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.
If the intention is to get all the tests to slowly refactor to use common.debuglog
, then I am -1 to this since I think something like out/Release/node test/paralell/test-*.js
should still give useful output without any tweak to the environment.
In that sense at least this PR needs to also modify test.py to add NODE_DEBUG=test
to
Line 197 in f4e4ef5
print "Command: %s" % EscapeCommand(failed.command) |
or even a hint in CONTRIBUTING.md (even though I believe many people don't read it through before contributing) if that's where it's going, otherwise when the test fail, the hint won't be too useful to a new contributor.
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.
If the intention is to get all the tests to slowly refactor to use
common.debuglog
, then I am -1 to this since I think something likeout/Release/node test/paralell/test-*.js
should still give useful output without any tweak to the environment.
@joyeecheung do you mean that it should still give output for tests that fail, or that it should always give output for all tests?
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.
@gibfahn I am not sure if it's reasonable to only give output for tests that fail unless we implement this in the test runner - we test our process.exit()
hooks in JS, among many things. If the hooks are broken, common.debuglog()
can be broken as well - unless we setup some signal handlers in the native layer to do this, but I am not sure if that is a good idea.
Seems like this has stalled and has some mild opposition. I'm going to close it, but if it's still being worked on, feel free to re-open or comment asking for someone else to re-open. Thanks for the pull request and I hope you continue to contribute! |
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesFixes #9314