2016-02-01 15:43:26 +03:00
|
|
|
# frozen_string_literal: true
|
2011-06-01 07:45:05 +04:00
|
|
|
require "rubygems"
|
2021-06-02 06:32:47 +03:00
|
|
|
require_relative "helper"
|
2011-06-01 07:45:05 +04:00
|
|
|
require "rubygems/commands/help_command"
|
2012-11-29 10:52:18 +04:00
|
|
|
require "rubygems/package"
|
2011-06-01 07:45:05 +04:00
|
|
|
require "rubygems/command_manager"
|
|
|
|
|
|
|
|
class TestGemCommandsHelpCommand < Gem::TestCase
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
|
|
|
@cmd = Gem::Commands::HelpCommand.new
|
2013-07-09 02:41:03 +04:00
|
|
|
|
2022-04-01 14:36:59 +03:00
|
|
|
load File.expand_path("rubygems_plugin.rb", __dir__) unless Gem::Commands.const_defined? :InterruptCommand
|
2011-06-01 07:45:05 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_gem_help_bad
|
|
|
|
util_gem "bad" do |out, err|
|
|
|
|
assert_equal("", out)
|
2013-09-14 12:59:02 +04:00
|
|
|
assert_match "Unknown command bad", err
|
2011-06-01 07:45:05 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-14 07: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-06-01 07: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 13:47:49 +03: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-06-01 07: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 10:33:39 +03:00
|
|
|
unless mgr[cmd].deprecated?
|
|
|
|
assert_match(/\s+#{cmd}\s+\S+/, out)
|
|
|
|
end
|
2011-06-01 07:45:05 +04:00
|
|
|
end
|
2013-07-09 02:41:03 +04:00
|
|
|
|
2020-12-08 10:33:39 +03:00
|
|
|
if Gem::HAVE_OPENSSL
|
2013-09-14 12:59:02 +04:00
|
|
|
assert_empty err
|
|
|
|
|
2021-05-11 10:45:31 +03:00
|
|
|
refute_match %r{No command found for }, out
|
2013-09-14 12:59:02 +04:00
|
|
|
end
|
2011-06-01 07:45:05 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-08 10:33:39 +03:00
|
|
|
def test_gem_help_commands_omits_deprecated_commands
|
|
|
|
mgr = Gem::CommandManager.new
|
|
|
|
|
2023-03-16 04:46:45 +03:00
|
|
|
util_gem "commands" do |out, _err|
|
2020-12-08 10:33:39 +03:00
|
|
|
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-06-01 07: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 13:20:47 +03:00
|
|
|
def util_gem(*args)
|
2011-06-01 07: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
|