Skip to content

Instantly share code, notes, and snippets.

@SpComb
Last active December 22, 2017 14:16
Show Gist options
  • Save SpComb/96f770d67922f384a9146c5520378e2c to your computer and use it in GitHub Desktop.
Save SpComb/96f770d67922f384a9146c5520378e2c to your computer and use it in GitHub Desktop.
tty-screen + kommando stty errors

kontena/kontena#3058

Usage

$ git clone https://gist.github.com/96f770d67922f384a9146c5520378e2c.git tty-screen-stty && cd tty-screen-stty 
$ docker build -t test/tty-screen-stty . && docker run --rm test/tty-screen-stty

Test

Without fix

$ docker build --build-arg FROM_GIT=false -t test/tty-screen-stty . && docker run --rm --privileged test/tty-screen-stty
Sending build context to Docker daemon  174.1kB
Step 1/9 : FROM alpine:3.5
 ---> f658b09cdc6c
Step 2/9 : RUN apk update && apk --update add     ruby ruby-irb ruby-io-console ruby-dev     build-base strace     git
 ---> Using cache
 ---> 368b48baf8db
Step 3/9 : RUN gem install --no-ri --no-rdoc     bundler
 ---> Using cache
 ---> e21c1d36151b
Step 4/9 : ARG FROM_GIT=
 ---> Using cache
 ---> 4d859c167140
Step 5/9 : ENV FROM_GIT ${FROM_GIT}
 ---> Using cache
 ---> 106c425a103d
Step 6/9 : ADD Gemfile ./
 ---> Using cache
 ---> b52750545ed0
Step 7/9 : RUN bundle install
 ---> Using cache
 ---> 9e1fe6ea3807
Step 8/9 : ADD *.rb ./
 ---> Using cache
 ---> 4ea1c8949fbe
Step 9/9 : CMD bundle exec rspec --format=doc ./tty_screen_spec.rb
 ---> Using cache
 ---> ff2c469babe3
Successfully built ff2c469babe3
Successfully tagged test/tty-screen-stty:latest

kommando + ruby tty-screen
  does not output errors (FAILED - 1)

Failures:

  1) kommando + ruby tty-screen does not output errors
     Failure/Error: expect(k.out).to_not match /stty: standard input/

       expected "stty: standard input\r\n27,80\r\n" not to match /stty: standard input/
       Diff:
       @@ -1,2 +1,3 @@
       -/stty: standard input/
       +stty: standard input
       +27,80
     # /tty_screen_spec.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.21117 seconds (files took 0.12465 seconds to load)
1 example, 1 failure

Failed examples:

rspec /tty_screen_spec.rb:4 # kommando + ruby tty-screen does not output errors

With fix

$ docker build --build-arg FROM_GIT=true -t test/tty-screen-stty . && docker run --rm --privileged test/tty-screen-stty
Sending build context to Docker daemon  174.1kB
Step 1/9 : FROM alpine:3.5
 ---> f658b09cdc6c
Step 2/9 : RUN apk update && apk --update add     ruby ruby-irb ruby-io-console ruby-dev     build-base strace     git
 ---> Using cache
 ---> 368b48baf8db
Step 3/9 : RUN gem install --no-ri --no-rdoc     bundler
 ---> Using cache
 ---> e21c1d36151b
Step 4/9 : ARG FROM_GIT=
 ---> Using cache
 ---> 4d859c167140
Step 5/9 : ENV FROM_GIT ${FROM_GIT}
 ---> Using cache
 ---> 797a0596eeed
Step 6/9 : ADD Gemfile ./
 ---> Using cache
 ---> caf11d112b73
Step 7/9 : RUN bundle install
 ---> Using cache
 ---> a1c881b91aa4
Step 8/9 : ADD *.rb ./
 ---> Using cache
 ---> e5751a81450d
Step 9/9 : CMD bundle exec rspec --format=doc ./tty_screen_spec.rb
 ---> Using cache
 ---> 3fc1420212bc
Successfully built 3fc1420212bc
Successfully tagged test/tty-screen-stty:latest

kommando + ruby tty-screen
  does not output errors

Finished in 0.20655 seconds (files took 0.11936 seconds to load)
1 example, 0 failures
FROM alpine:3.5
RUN apk update && apk --update add \
ruby ruby-irb ruby-io-console ruby-dev \
build-base strace \
git
RUN gem install --no-ri --no-rdoc \
bundler
ARG FROM_GIT=
ENV FROM_GIT=${FROM_GIT}
ADD Gemfile ./
RUN bundle install
ADD *.rb ./
CMD ["bundle", "exec", "rspec", "--format=doc", "./tty_screen_spec.rb"]
source 'https://rubygems.org'
gem 'rspec'
gem 'kommando'
if ENV['FROM_GIT'] == 'true'
gem 'tty-screen',
git: 'https://github.com/SpComb/tty-screen.git',
branch: 'fix/run-command-stderr',
ref: 'b5476241fd6f3303eb0cb63a12e5641438f23a0e'
else
gem 'tty-screen'
end
require 'tty-screen'
puts TTY::Screen.size.join ','
require 'kommando'
require 'tty-screen'
def uncolorize(input)
input.gsub(/\e\[.+?m/, '')
end
describe 'kommando + stty' do
it 'outputs size when run with kommando' do
k = Kommando.run 'stty size'
expect(k.out).to match /\d+ \d+/
end
it 'does not output stty errors' do
k = Kommando.run 'strace stty size'
expect(k.code).to be_zero, k.out
expect(k.out).to_not match /stty: standard input/
end
it 'does not print to stderr when run directly' do
expect(TTY::Screen.size).to match [Integer, Integer]
end
it 'runs with a pty' do
k = Kommando.run('ls -l /proc/self/fd/0')
expect(uncolorize k.out).to include '0 -> /dev/pts/'
end
end
require 'kommando'
describe 'kommando + ruby tty-screen' do
it 'does not output errors' do
k = Kommando.run 'ruby ./test.rb'
expect(k.out).to match /\d+,\d+/
expect(k.out).to_not match /stty: standard input/
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment