Skip to content
This repository was archived by the owner on Mar 12, 2023. It is now read-only.

Commit 5c780f8

Browse files
committed
Tests for Readline compatibility
1 parent a03870a commit 5c780f8

8 files changed

+256
-10
lines changed

Gemfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
source 'http://rubygems.org'
3+
source 'https://rubygems.org'
44

55
gemspec
66

@@ -23,4 +23,5 @@ group :test do
2323
gem 'rspec-retry'
2424
gem 'simplecov', require: false
2525
gem 'sqlite3'
26+
gem 'reline'
2627
end

lib/ruby_jard/pry_proxy.rb

+5-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ def read_line(current_prompt)
1414

1515
# Proxy for Pry instance. Safely overidding some attributes
1616
class PryProxy < ::Pry
17-
# Some gems want to replace original Readline
18-
OriginalReadline = ::Readline
1917
# Some commands overlaps with Jard, Ruby, and even cause confusion for
2018
# users. It's better ignore or re-implement those commands.
2119
PRY_EXCLUDED_COMMANDS = [
@@ -46,7 +44,7 @@ def initialize(options = {})
4644
@original_output = options[:original_output]
4745
@state_hooks = options[:state_hooks] || {}
4846
options = options.merge(
49-
input: OriginalReadline,
47+
input: ::Readline,
5048
output: @redirected_output,
5149
prompt: pry_jard_prompt,
5250
commands: pry_command_set,
@@ -68,12 +66,12 @@ def handle_line(line, *args)
6866
end
6967

7068
def repl(target = nil)
71-
OriginalReadline.input = @redirected_input
72-
OriginalReadline.output = @redirected_output
69+
::Readline.input = @redirected_input
70+
::Readline.output = @redirected_output
7371
PryReplProxy.new(self, target: target).start
7472
ensure
75-
OriginalReadline.input = @original_input
76-
OriginalReadline.output = @original_output
73+
::Readline.input = @original_input
74+
::Readline.output = @original_output
7775
end
7876

7977
def pager

lib/ruby_jard/repl_manager.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def repl(current_binding)
2626

2727
set_console_raw!
2828
unless @interceptor.interceptable?
29-
@console.output.puts '*Warning*: Key bindings are disabled! '\
30-
'There maybe something touching Jard\'s Readline depedency'
29+
@console.output.puts '*Warning*: One of Jard\'s depedencies (PTY or Readline) is not available or '\
30+
'patched by another gem. Key bindings are disabled. There may be other side effects.'
3131
end
3232

3333
pry_proxy.repl(current_binding)

spec/examples/pty_not_found.rb

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
require 'pty'
4+
5+
Object.send(:remove_const, :PTY)
6+
7+
require 'ruby_jard'
8+
9+
class Calculator
10+
def calculate(a, b, c)
11+
jard
12+
d = a + b
13+
jard
14+
e = d + 10
15+
jard
16+
e + c
17+
end
18+
end
19+
20+
Calculator.new.calculate(1, 2, 3)

spec/examples/readline_patched.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require 'reline'
4+
require 'ruby_jard'
5+
6+
Readline = Reline
7+
8+
class Calculator
9+
def calculate(a, b, c)
10+
jard
11+
d = a + b
12+
jard
13+
e = d + 10
14+
jard
15+
e + c
16+
end
17+
end
18+
19+
Calculator.new.calculate(1, 2, 3)

spec/integration/compatibilities/compatibilities_spec.rb

+40
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,44 @@
8080
test.stop
8181
end
8282
end
83+
84+
context 'when PTY not found' do
85+
it 'ignores interceptor and use direct input instead' do
86+
test = JardIntegrationTest.new(
87+
self, work_dir,
88+
'compatibility_pty_not_found.expected',
89+
"bundle exec ruby #{RSPEC_ROOT}/examples/pty_not_found.rb"
90+
)
91+
test.start
92+
test.assert_screen
93+
94+
test.send_keys('continue', :Enter)
95+
test.assert_screen
96+
97+
test.send_keys('continue', :Enter)
98+
test.assert_screen
99+
ensure
100+
test.stop
101+
end
102+
end
103+
104+
context 'when Readline is patched' do
105+
it 'ignores interceptor and use direct input instead' do
106+
test = JardIntegrationTest.new(
107+
self, work_dir,
108+
'compatibility_readline_patched.expected',
109+
"bundle exec ruby #{RSPEC_ROOT}/examples/readline_patched.rb"
110+
)
111+
test.start
112+
test.assert_screen
113+
114+
test.send_keys('continue', :Enter)
115+
test.assert_screen
116+
117+
test.send_keys('continue', :Enter)
118+
test.assert_screen
119+
ensure
120+
test.stop
121+
end
122+
end
83123
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
### START SCREEN ###
2+
┌ Source ../../examples/pty_not_found.rb:12 ──────────────────────────────────┐
3+
│ 4 │
4+
│ 5 Object.send(:remove_const, :PTY) │
5+
│ 6 │
6+
│ 7 require 'ruby_jard' │
7+
│ 8 │
8+
│ 9 class Calculator │
9+
│ 10 def calculate(a, b, c) │
10+
│ 11 jard │
11+
│⮕ 12 d = a + b │
12+
│ 13 jard │
13+
│ 14 e = d + 10 │
14+
│ 15 jard │
15+
│ 16 e + c │
16+
│ 17 end │
17+
│ 18 end │
18+
│ 19 │
19+
│ 20 Calculator.new.calculate(1, 2, 3) │
20+
├──────────────────────────────────────────────────────────────────────────────┤
21+
│Filter (F2): Application Step (F7) Step Out (Shift+F7) Next (F8) Con »│
22+
└──────────────────────────────────────────────────────────────────────────────┘
23+
*Warning*: One of Jard's depedencies (PTY or Readline) is not available or patch
24+
ed by another gem. Key bindings are disabled. There may be other side effects.
25+
jard >>
26+
### END SCREEN ###
27+
### START SEND_KEYS ###
28+
["continue", :Enter]
29+
### END SEND_KEYS ###
30+
### START SCREEN ###
31+
┌ Source ../../examples/pty_not_found.rb:14 ──────────────────────────────────┐
32+
│ 6 │
33+
│ 7 require 'ruby_jard' │
34+
│ 8 │
35+
│ 9 class Calculator │
36+
│ 10 def calculate(a, b, c) │
37+
│ 11 jard │
38+
│ 12 d = a + b │
39+
│ 13 jard │
40+
│⮕ 14 e = d + 10 │
41+
│ 15 jard │
42+
│ 16 e + c │
43+
│ 17 end │
44+
│ 18 end │
45+
│ 19 │
46+
│ 20 Calculator.new.calculate(1, 2, 3) │
47+
│ │
48+
│ │
49+
├──────────────────────────────────────────────────────────────────────────────┤
50+
│Filter (F2): Application Step (F7) Step Out (Shift+F7) Next (F8) Con »│
51+
└──────────────────────────────────────────────────────────────────────────────┘
52+
*Warning*: One of Jard's depedencies (PTY or Readline) is not available or patch
53+
ed by another gem. Key bindings are disabled. There may be other side effects.
54+
jard >>
55+
### END SCREEN ###
56+
### START SEND_KEYS ###
57+
["continue", :Enter]
58+
### END SEND_KEYS ###
59+
### START SCREEN ###
60+
┌ Source ../../examples/pty_not_found.rb:16 ──────────────────────────────────┐
61+
│ 8 │
62+
│ 9 class Calculator │
63+
│ 10 def calculate(a, b, c) │
64+
│ 11 jard │
65+
│ 12 d = a + b │
66+
│ 13 jard │
67+
│ 14 e = d + 10 │
68+
│ 15 jard │
69+
│⮕ 16 e + c │
70+
│ 17 end │
71+
│ 18 end │
72+
│ 19 │
73+
│ 20 Calculator.new.calculate(1, 2, 3) │
74+
│ │
75+
│ │
76+
│ │
77+
│ │
78+
├──────────────────────────────────────────────────────────────────────────────┤
79+
│Filter (F2): Application Step (F7) Step Out (Shift+F7) Next (F8) Con »│
80+
└──────────────────────────────────────────────────────────────────────────────┘
81+
*Warning*: One of Jard's depedencies (PTY or Readline) is not available or patch
82+
ed by another gem. Key bindings are disabled. There may be other side effects.
83+
jard >>
84+
### END SCREEN ###
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
### START SCREEN ###
2+
┌ Source ../../examples/readline_patched.rb:11 ───────────────────────────────┐
3+
│ 3 require 'reline' │
4+
│ 4 require 'ruby_jard' │
5+
│ 5 │
6+
│ 6 Readline = Reline │
7+
│ 7 │
8+
│ 8 class Calculator │
9+
│ 9 def calculate(a, b, c) │
10+
│ 10 jard │
11+
│⮕ 11 d = a + b │
12+
│ 12 jard │
13+
│ 13 e = d + 10 │
14+
│ 14 jard │
15+
│ 15 e + c │
16+
│ 16 end │
17+
│ 17 end │
18+
│ 18 │
19+
│ 19 Calculator.new.calculate(1, 2, 3) │
20+
├──────────────────────────────────────────────────────────────────────────────┤
21+
│Filter (F2): Application Step (F7) Step Out (Shift+F7) Next (F8) Con »│
22+
└──────────────────────────────────────────────────────────────────────────────┘
23+
*Warning*: One of Jard's depedencies (PTY or Readline) is not available or patch
24+
ed by another gem. Key bindings are disabled. There may be other side effects.
25+
jard >>
26+
### END SCREEN ###
27+
### START SEND_KEYS ###
28+
["continue", :Enter]
29+
### END SEND_KEYS ###
30+
### START SCREEN ###
31+
┌ Source ../../examples/readline_patched.rb:13 ───────────────────────────────┐
32+
│ 5 │
33+
│ 6 Readline = Reline │
34+
│ 7 │
35+
│ 8 class Calculator │
36+
│ 9 def calculate(a, b, c) │
37+
│ 10 jard │
38+
│ 11 d = a + b │
39+
│ 12 jard │
40+
│⮕ 13 e = d + 10 │
41+
│ 14 jard │
42+
│ 15 e + c │
43+
│ 16 end │
44+
│ 17 end │
45+
│ 18 │
46+
│ 19 Calculator.new.calculate(1, 2, 3) │
47+
│ │
48+
│ │
49+
├──────────────────────────────────────────────────────────────────────────────┤
50+
│Filter (F2): Application Step (F7) Step Out (Shift+F7) Next (F8) Con »│
51+
└──────────────────────────────────────────────────────────────────────────────┘
52+
*Warning*: One of Jard's depedencies (PTY or Readline) is not available or patch
53+
ed by another gem. Key bindings are disabled. There may be other side effects.
54+
jard >>
55+
### END SCREEN ###
56+
### START SEND_KEYS ###
57+
["continue", :Enter]
58+
### END SEND_KEYS ###
59+
### START SCREEN ###
60+
┌ Source ../../examples/readline_patched.rb:15 ───────────────────────────────┐
61+
│ 7 │
62+
│ 8 class Calculator │
63+
│ 9 def calculate(a, b, c) │
64+
│ 10 jard │
65+
│ 11 d = a + b │
66+
│ 12 jard │
67+
│ 13 e = d + 10 │
68+
│ 14 jard │
69+
│⮕ 15 e + c │
70+
│ 16 end │
71+
│ 17 end │
72+
│ 18 │
73+
│ 19 Calculator.new.calculate(1, 2, 3) │
74+
│ │
75+
│ │
76+
│ │
77+
│ │
78+
├──────────────────────────────────────────────────────────────────────────────┤
79+
│Filter (F2): Application Step (F7) Step Out (Shift+F7) Next (F8) Con »│
80+
└──────────────────────────────────────────────────────────────────────────────┘
81+
*Warning*: One of Jard's depedencies (PTY or Readline) is not available or patch
82+
ed by another gem. Key bindings are disabled. There may be other side effects.
83+
jard >>
84+
### END SCREEN ###

0 commit comments

Comments
 (0)