3 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
5 # See LICENSE.txt for permissions.
10 require 'test/insure_session'
11 require 'rubygems/format'
12 require 'rubygems/command_manager'
14 class FunctionalTest < Test::Unit::TestCase
16 @gem_path = File.expand_path("bin/gem")
17 lib_path = File.expand_path("lib")
18 @ruby_options = "-I#{lib_path} -I."
22 def test_gem_help_options
23 gem_nossl 'help options'
24 assert_match(/Usage:/, @out, @err)
28 def test_gem_help_commands
29 gem_nossl 'help commands'
30 assert_match(/gem install/, @out)
34 def test_gem_no_args_shows_help
36 assert_match(/Usage:/, @out)
40 # This test is disabled because of the insanely long time it takes
42 def xtest_bogus_source_hoses_up_remote_install_but_gem_command_gives_decent_error_message
43 @ruby_options << " -rtest/bogussources"
44 gem_nossl "install asdf --remote"
45 assert_match(/error/im, @err)
49 def test_all_command_helps
50 mgr = Gem::CommandManager.new
51 mgr.command_names.each do |cmdname|
52 gem_nossl "help #{cmdname}"
53 assert_match(/Usage: gem #{cmdname}/, @out,
54 "should see help for #{cmdname}")
58 # :section: Help Methods
60 # Run a gem command without the SSL library.
61 def gem_nossl(options="")
62 old_options = @ruby_options.dup
63 @ruby_options << " -Itest/fake_certlib"
66 @ruby_options = old_options
69 # Run a gem command with the SSL library.
70 def gem_withssl(options="")
74 # Run a gem command for the functional test.
76 shell = Session::Shell.new
77 options = options + " --config-file missing_file" if options !~ /--config-file/
78 command = "#{Gem.ruby} #{@ruby_options} #{@gem_path} #{options}"
79 puts "\n\nCOMMAND: [#{command}]" if @verbose
80 @out, @err = shell.execute command
81 @status = shell.exit_status
82 puts "STATUS: [#{@status}]" if @verbose
83 puts "OUTPUT: [#{@out}]" if @verbose
84 puts "ERROR: [#{@err}]" if @verbose
85 puts "PWD: [#{Dir.pwd}]" if @verbose
91 def assert_status(expected_status=0)
92 assert_equal expected_status, @status