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

Use stty when available to set tty width for tests #296

Closed
wants to merge 1 commit into from

Conversation

dobbymoodge
Copy link

@dobbymoodge dobbymoodge commented Nov 25, 2019

Checks for stty in path and uses it, if available, to set terminal
width (stty columns 149). This guarantees that the desired terminal
width is used for tests when the value comes from ioctl, since that
has priority over the COLUMNS env var
.

This addresses an issue where tests for the output of templates that
use the termWidth template function would fail when run in certain
environments - in my case, bash running in rxvt-unicode-256color
in Fedora 30 - when the terminal width doesn't match 149 like the
test expects.

Checks for `stty` in path and uses it, if available, to set terminal
width (`stty columns 149`). This guarantees that the desired terminal
width is used for tests when the value comes from `ioctl`, since [that
has priority over the `COLUMNS` env
var](https://github.com/go-jira/jira/blob/590244947b92c5cfef5dc61b4e1aa931f8da5762/jiracli/templates.go#L101).

This addresses an issue where tests for the output of templates that
use the `termWidth` template function would fail when run in certain
environments - in my case, `bash` running in `rxvt-unicode-256color`
in Fedora 30 - when the terminal width doesn't match `149` like the
test expects.
@@ -1,4 +1,8 @@
export COLUMNS=149
if command -v stty 1>/dev/null 2>/dev/null
then
stty columns 149
Copy link
Contributor

@coryb coryb Dec 2, 2019

Choose a reason for hiding this comment

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

This will change my tty params even after the tests exit. I think we need to preserve/restore the original value to make this sane. Something like:

if command -v stty 1>/dev/null 2>/dev/null
then
    cur=$(stty size  | cut -d " " -f 2)
    stty columns 149
    restoreCols() {
        stty columns $cur
    }
    trap restoreCols INT TERM EXIT
fi

Copy link
Author

Choose a reason for hiding this comment

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

That makes sense, though I can't shake the feeling that there's a "right" way to set up a fake TTY for tests like this. I'll do some research when I get a minute tomorrow.

Copy link
Author

Choose a reason for hiding this comment

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

although it looks like #302 obviates the need for this PR; I'll double-check tomorrow and close if so.

mikepea added a commit that referenced this pull request Dec 3, 2019
add template functions to handle table output, fixes #176, replaces #296
@vanniktech vanniktech removed their request for review May 1, 2021 11:10
@dobbymoodge dobbymoodge closed this Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants