Skip to content
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: actually test tty getColorDepth() #18800

Merged

Conversation

Fishrock123
Copy link
Contributor

@Fishrock123 Fishrock123 commented Feb 15, 2018

TTY tests should almost never be placed in /parallel/. Skipping TTY
tests there due to missing tty fds just means they will never be run,
ever, on any system.

This moves the tty-get-color-depth test to /pseudo-tty/ where the test
runner will actually make a pty fd.

Also moves getTTYfd() into common/index.js.


Edit: this was noticed by looking at the tty coverage.

cc @BridgeAR

CI: https://ci.nodejs.org/job/node-test-pull-request/13183/

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test, tty

@Fishrock123 Fishrock123 added test Issues and PRs related to the tests. tty Issues and PRs related to the tty subsystem. labels Feb 15, 2018
@nodejs-github-bot nodejs-github-bot added test Issues and PRs related to the tests. tty Issues and PRs related to the tty subsystem. labels Feb 15, 2018
Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with two suggestions. Thanks for fixing this.

'use strict';

const common = require('../common');
const assert = require('assert');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like that we keep using strict mode. It is something that I would like to switch over on the long term.

Copy link
Contributor Author

@Fishrock123 Fishrock123 Feb 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BridgeAR That lint rule does not seem to be correctly applied to /pseudo-tty/, so the linter complains.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will have to deactivate that rule. The rule should actually be updated. I will open an issue so it can be grabbed by someone.

return -1;
}
}
return ttyFd;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something similar wa sin here at some point and is used in another test file. It would be good to consolidate in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is, I'm not sure where it is at. If there are tests somewhere that I missed that use something like this, they probably don't actually work...? I couldn't find any in a quick look.

There are some tests that don't even bother to go for something like this and just go for fd 0 instead. (Which could probably be added to the lookup list here? I'll do that.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one in sequential/test-async-wrap-getasyncid.js. And zero was removed because it can cause issues on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part of that test definitely never ever runs. 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move that out next and base it off of this then, I suppose.

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 15, 2018
@@ -24,6 +24,8 @@
const process = global.process; // Some tests tamper with the process global.
const path = require('path');
const fs = require('fs');
/* eslint-disable no-restricted-properties */
const { openSync } = require('fs');
Copy link
Member

@Trott Trott Feb 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're already importing all of fs on the immediately prior line, is this really necessary? Can we just use fs.openSync in the one place it gets used later on (line 814)?

@@ -24,6 +24,8 @@
const process = global.process; // Some tests tamper with the process global.
const path = require('path');
const fs = require('fs');
/* eslint-disable no-restricted-properties */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This eslint-disable comment is unnecessary. Please remove it.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skipping TTY
tests there due to missing tty fds just means they will never be run,
ever, on any system.

/dev/tty should in practice be a pretty reliable way to get a TTY, at least for developer machines.

exports.getTTYfd = function getTTYfd() {
const tty = require('tty');
// Do our best to grab a tty fd.
const ttyFd = [1, 2, 4, 5].find(tty.isatty);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is also a very good candidate for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was removed recently: ef28619

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I'll have to leave a note about this.

@Fishrock123
Copy link
Contributor Author

/dev/tty should in practice be a pretty reliable way to get a TTY, at least for developer machines.

That's only true if a terminal is directly attached to the process.

If I comment out these lines on master, the test runner fails:

if (fd === -1)
common.skip();

@Fishrock123 Fishrock123 force-pushed the actually-test-tty-get-color-depth branch 2 times, most recently from 667ced5 to f4b997d Compare February 16, 2018 17:12
@Fishrock123
Copy link
Contributor Author

Fishrock123 commented Feb 16, 2018

@Fishrock123 Fishrock123 force-pushed the actually-test-tty-get-color-depth branch from f4b997d to e745f29 Compare February 16, 2018 17:17
Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM

@BridgeAR
Copy link
Member

@Fishrock123 this needs a rebase

@BridgeAR BridgeAR removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 18, 2018
@Fishrock123 Fishrock123 force-pushed the actually-test-tty-get-color-depth branch from e745f29 to c8bdcf8 Compare February 20, 2018 17:26
This utility is fairly generic and likely useful for more than one test.

PR-URL: nodejs#18800
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
TTY tests should almost never be placed in `/parallel/`. Skipping TTY
tests there due to missing tty fds just means they will never be run,
ever, on any system.

This moves the tty-get-color-depth test to `/pseudo-tty/` where the test
runner will actually make a pty fd.

Refs: nodejs#17615
PR-URL: nodejs#18800
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@Fishrock123 Fishrock123 force-pushed the actually-test-tty-get-color-depth branch from c8bdcf8 to 7514eb3 Compare February 20, 2018 17:32
@Fishrock123 Fishrock123 merged commit 7514eb3 into nodejs:master Feb 20, 2018
@Fishrock123 Fishrock123 deleted the actually-test-tty-get-color-depth branch February 20, 2018 17:34
@MylesBorins
Copy link
Contributor

Should this be backported to v9.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

Fishrock123 added a commit to Fishrock123/node that referenced this pull request Feb 22, 2018
Follow-up from nodejs#18800

Code that tries to exercise tty fds must be placed in `/pseudo-tty/`.

PR-URL: nodejs#18886
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Fishrock123 added a commit that referenced this pull request Feb 22, 2018
Follow-up from #18800

Code that tries to exercise tty fds must be placed in `/pseudo-tty/`.

PR-URL: #18886
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request May 1, 2018
This utility is fairly generic and likely useful for more than one test.

PR-URL: nodejs#18800
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request May 1, 2018
TTY tests should almost never be placed in `/parallel/`. Skipping TTY
tests there due to missing tty fds just means they will never be run,
ever, on any system.

This moves the tty-get-color-depth test to `/pseudo-tty/` where the test
runner will actually make a pty fd.

Refs: nodejs#17615
PR-URL: nodejs#18800
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request May 1, 2018
Follow-up from nodejs#18800

Code that tries to exercise tty fds must be placed in `/pseudo-tty/`.

PR-URL: nodejs#18886
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
This utility is fairly generic and likely useful for more than one test.

PR-URL: nodejs#18800
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
TTY tests should almost never be placed in `/parallel/`. Skipping TTY
tests there due to missing tty fds just means they will never be run,
ever, on any system.

This moves the tty-get-color-depth test to `/pseudo-tty/` where the test
runner will actually make a pty fd.

Refs: nodejs#17615
PR-URL: nodejs#18800
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
Follow-up from nodejs#18800

Code that tries to exercise tty fds must be placed in `/pseudo-tty/`.

PR-URL: nodejs#18886
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins
Copy link
Contributor

should these tty updates be backported to v8.x?

@jasnell
Copy link
Member

jasnell commented Aug 17, 2018

does not land cleanly in 8.x. Would need a backport PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Issues and PRs related to the tests. tty Issues and PRs related to the tty subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants