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

irb command doesn't work in test mode #115

Closed
st0012 opened this issue Jun 24, 2021 · 10 comments
Closed

irb command doesn't work in test mode #115

st0012 opened this issue Jun 24, 2021 · 10 comments

Comments

@st0012
Copy link
Member

st0012 commented Jun 24, 2021

The irb command would hang without any output in the test mode:

❯ ruby test/debug/irb_test.rb
Loaded suite test/debug/irb_test
Started
[1, 2] in /var/folders/yg/hnbymwxd5pn7v94_clc59y6r0000gn/T/debugger20210624-80600-aod65v.rb
=>    1| a = 1
      2| b = 2
=>#0    <main> at /var/folders/yg/hnbymwxd5pn7v94_clc59y6r0000gn/T/debugger20210624-80600-aod65v.rb:1
INTERNAL_INFO: {"location":"/var/folders/yg/hnbymwxd5pn7v94_clc59y6r0000gn/T/debugger20210624-80600-aod65v.rb:1","line":1}
irb

(rdbg) irb
# then timeout

I suspect it's because the test framework doesn't support such cases yet.

Example test:

require_relative '../support/test_case'

module DEBUGGER__
  class IRBCommandTest < TestCase
    def program
      <<~RUBY
      a = 1
      b = 2
      RUBY
    end

    def test_irb_starts_an_irb_session
      debug_code(program) do
        type 'irb'
        assert_line_text(/irb\(main\)/)
        type 'exit'
        assert_line_text(/rdbg/)
        type 'q!'
      end
    end
  end
end
@st0012
Copy link
Member Author

st0012 commented Jun 24, 2021

@ono-max can you give this a look? thx

@st0012 st0012 mentioned this issue Jun 24, 2021
13 tasks
@ono-max
Copy link
Collaborator

ono-max commented Jun 25, 2021

Thanks. I took a look at the issue. There seems to be garbled characters when irb is typed. I think we need to fix it first.

Example test

I used the test that @st0012 presented to me.

Piece of code in utils.rb

 when /INTERNAL_INFO:\s(.*)/
                @internal_info = JSON.parse(Regexp.last_match(1))
                cmd = @queue.pop
                if cmd.is_a?(Proc)
                  cmd.call
                  cmd = @queue.pop
                end
                if ask_cmd.include?(cmd)
                  write.puts(cmd)
                  cmd = @queue.pop
                end
                write.puts(cmd)
                @last_backlog.clear
                next # INTERNAL_INFO shouldn't be pushed into @backlog and @last_backlog
  # I added lines below for debug.
              when /\(rdbg\) irb/
                while output = read.getc
                  print output
                end

Output

$ ruby test/debug/hoge_test.rb
Loaded suite test/debug/hoge_test
Started
[1, 2] in /var/folders/kv/w1k6nh1x5fl7vx47b2pd005w0000gn/T/debugger20210625-33210-j22slv.rb
=>    1| a = 1
      2| b = 2
=>#0	<main> at /var/folders/kv/w1k6nh1x5fl7vx47b2pd005w0000gn/T/debugger20210625-33210-j22slv.rb:1
INTERNAL_INFO: {"location":"/var/folders/kv/w1k6nh1x5fl7vx47b2pd005w0000gn/T/debugger20210625-33210-j22slv.rb:1","line":1}
irb

(rdbg) irb
# this is the content of `output` variable.
▽^[[63;2R

@ono-max
Copy link
Collaborator

ono-max commented Jun 25, 2021

@st0012
BTW do you think we can test irb?
I'm not sure about it.

@st0012
Copy link
Member Author

st0012 commented Jun 25, 2021

thanks for investigating. do you know why we can't see irb's prompt properly? I thought since it's not colorized or contain any special character, we should be able to read it like any debugger output?

BTW do you think we can test irb?

I'm not trying to test irb. I just want to verify that the debugger can enter and exit the irb session correctly.

@ono-max
Copy link
Collaborator

ono-max commented Jun 25, 2021

do you know why we can't see irb's prompt properly?

No, that's why I asked you if we can test irb 😵 I've never seen anything like this before.

@st0012
Copy link
Member Author

st0012 commented Jul 6, 2021

I’ll give this another try. @ko1 do you have any guess on the cause?

@ko1
Copy link
Collaborator

ko1 commented Jul 7, 2021

It seems recent irb can not control on PTY.

@ko1
Copy link
Collaborator

ko1 commented Jul 7, 2021

tried on this script and I can't quit it (and old irb bundled with ruby 2.6 can work).
maybe it needs other techs.

require 'pty'

PTY.spawn('irb '){|r, w, pid|
  puts r.readpartial(1024)
  w.print "quit\r\n"
  w.flush
  while true
    puts r.readpartial(1024)
  end
}

@ko1
Copy link
Collaborator

ko1 commented Jul 7, 2021

it seems hard so let's skip the test.
(or remove irb command)

@st0012
Copy link
Member Author

st0012 commented Jul 7, 2021

ok let's skip the irb test for now. the command is still needed imo.

@st0012 st0012 closed this as completed Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants