Skip to content

Commit

Permalink
Add test for ExtendCommandBundle.def_extend_command
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Feb 17, 2024
1 parent 9d33fe1 commit 68002e7
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/irb/test_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,56 @@ def test_irb_info_lang
end
end

class ExtendCommandBundleCompatibilityTest < CommandTestCase
class FooBarCommand < IRB::Command::Base
category 'FooBarCategory'
description 'foobar_description'
def execute(_arg)
puts "FooBar executed"
end
end

def setup
super
execute_lines("show_cmds\n") # To ensure command initialization is done
@ivars_backup = IRB::ExtendCommandBundle.instance_variables.to_h do |ivar|
[ivar, IRB::ExtendCommandBundle.instance_variable_get(ivar)]
end
@cvars_backup = IRB::ExtendCommandBundle.class_variables.to_h do |cvar|
[cvar, IRB::ExtendCommandBundle.class_variable_get(cvar)]
end
IRB::Command.const_set :FooBarCommand, FooBarCommand
end

def teardown
super
@ivars_backup.each do |ivar, value|
IRB::ExtendCommandBundle.instance_variable_set(ivar, value)
end
@cvars_backup.each do |cvar, value|
IRB::ExtendCommandBundle.class_variable_set(cvar, value)
end
IRB::Command.send(:remove_const, :FooBarCommand)
end

def test_def_extend_command
command = [:foobar, :FooBarCommand, nil, [:fbalias, IRB::ExtendCommandBundle::OVERRIDE_ALL]]
IRB::ExtendCommandBundle.instance_variable_get(:@EXTEND_COMMANDS).push(command)
IRB::ExtendCommandBundle.def_extend_command(*command)
out, err = execute_lines("foobar\n")
assert_empty err
assert_include(out, "FooBar executed")

out, err = execute_lines("fbalias\n")
assert_empty err
assert_include(out, "FooBar executed")

out, err = execute_lines("show_cmds\n")
assert_include(out, "FooBarCategory")
assert_include(out, "foobar_description")
end
end

class MeasureTest < CommandTestCase
def test_measure
conf = {
Expand Down

0 comments on commit 68002e7

Please sign in to comment.