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 23, 2024
1 parent 124f275 commit b32af7a
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/irb/test_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,52 @@ 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
@EXTEND_COMMANDS_backup = IRB::ExtendCommandBundle.instance_variable_get(:@EXTEND_COMMANDS).dup
@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
IRB::ExtendCommandBundle.instance_variable_set(:@EXTEND_COMMANDS, @EXTEND_COMMANDS_backup)
@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 b32af7a

Please sign in to comment.