Skip to content

Commit

Permalink
Add assertion for dynamic_prompt's assertion execution (#586)
Browse files Browse the repository at this point in the history
Because the assertions for `dynamic_prompt` lives inside a block given to
`RubyLex`, they could be skipped unnoticed if the setup is not correct.

This commit adds a simple assertion to check if the block was actually
executed.
  • Loading branch information
st0012 authored May 20, 2023
1 parent b5f3efd commit bb68645
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/irb/test_ruby_lex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ def assert_dynamic_prompt(lines, expected_prompt_list)
pend if RUBY_ENGINE == 'truffleruby'
context = build_context
ruby_lex = RubyLex.new(context)
dynamic_prompt_executed = false
io = MockIO_DynamicPrompt.new(lines) do |prompt_list|
error_message = <<~EOM
Expected dynamic prompt:
Expand All @@ -647,12 +648,14 @@ def assert_dynamic_prompt(lines, expected_prompt_list)
Actual dynamic prompt:
#{prompt_list.join("\n")}
EOM
dynamic_prompt_executed = true
assert_equal(expected_prompt_list, prompt_list, error_message)
end
ruby_lex.set_prompt do |ltype, indent, continue, line_no|
'%03d:%01d:%1s:%s ' % [line_no, indent, ltype, continue ? '*' : '>']
end
ruby_lex.configure_io(io)
assert dynamic_prompt_executed, "dynamic_prompt's assertions were not executed."
end

def test_dyanmic_prompt
Expand Down

0 comments on commit bb68645

Please sign in to comment.