2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2011-05-31 23:45:05 -04:00
|
|
|
require "rubygems"
|
2021-06-01 23:32:47 -04:00
|
|
|
require_relative "helper"
|
2011-05-31 23:45:05 -04:00
|
|
|
require "rubygems/commands/help_command"
|
2012-11-29 01:52:18 -05:00
|
|
|
require "rubygems/package"
|
2011-05-31 23:45:05 -04:00
|
|
|
require "rubygems/command_manager"
|
|
|
|
|
|
|
|
class TestGemCommandsHelpCommand < Gem::TestCase
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@cmd = Gem::Commands::HelpCommand.new
|
2013-07-08 18:41:03 -04:00
|
|
|
|
2019-12-13 06:19:08 -05:00
|
|
|
load File.expand_path('../rubygems_plugin.rb', __FILE__) unless Gem::Commands.const_defined? :InterruptCommand
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem_help_bad
|
|
|
|
util_gem 'bad' do |out, err|
|
|
|
|
assert_equal('', out)
|
2013-09-14 04:59:02 -04:00
|
|
|
assert_match "Unknown command bad", err
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
def test_gem_help_gem_dependencies
|
|
|
|
util_gem 'gem_dependencies' do |out, err|
|
|
|
|
assert_match 'gem.deps.rb', out
|
|
|
|
assert_equal '', err
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def test_gem_help_platforms
|
|
|
|
util_gem 'platforms' do |out, err|
|
|
|
|
assert_match(/x86-freebsd/, out)
|
|
|
|
assert_equal '', err
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-28 06:47:49 -04:00
|
|
|
def test_gem_help_build
|
|
|
|
util_gem 'build' do |out, err|
|
|
|
|
assert_match(/-C PATH *Run as if gem build was started in <PATH>/, out)
|
|
|
|
assert_equal '', err
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def test_gem_help_commands
|
|
|
|
mgr = Gem::CommandManager.new
|
|
|
|
|
|
|
|
util_gem 'commands' do |out, err|
|
|
|
|
mgr.command_names.each do |cmd|
|
2020-12-08 02:33:39 -05:00
|
|
|
unless mgr[cmd].deprecated?
|
|
|
|
assert_match(/\s+#{cmd}\s+\S+/, out)
|
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
2013-07-08 18:41:03 -04:00
|
|
|
|
2020-12-08 02:33:39 -05:00
|
|
|
if Gem::HAVE_OPENSSL
|
2013-09-14 04:59:02 -04:00
|
|
|
assert_empty err
|
|
|
|
|
2021-05-11 03:45:31 -04:00
|
|
|
refute_match %r{No command found for }, out
|
2013-09-14 04:59:02 -04:00
|
|
|
end
|
2011-05-31 23:45:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-08 02:33:39 -05:00
|
|
|
def test_gem_help_commands_omits_deprecated_commands
|
|
|
|
mgr = Gem::CommandManager.new
|
|
|
|
|
|
|
|
util_gem 'commands' do |out, err|
|
|
|
|
deprecated_commands = mgr.command_names.select {|cmd| mgr[cmd].deprecated? }
|
|
|
|
deprecated_commands.each do |cmd|
|
|
|
|
refute_match(/\A\s+#{cmd}\s+\S+\z/, out)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def test_gem_no_args_shows_help
|
|
|
|
util_gem do |out, err|
|
|
|
|
assert_match(/Usage:/, out)
|
|
|
|
assert_match(/gem install/, out)
|
|
|
|
assert_equal '', err
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def util_gem(*args)
|
2011-05-31 23:45:05 -04:00
|
|
|
@cmd.options[:args] = args
|
|
|
|
|
|
|
|
use_ui @ui do
|
|
|
|
Dir.chdir @tempdir do
|
|
|
|
@cmd.execute
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
yield @ui.output, @ui.error
|
|
|
|
end
|
|
|
|
end
|