diff options
Diffstat (limited to 'spec/ruby/command_line')
28 files changed, 340 insertions, 74 deletions
diff --git a/spec/ruby/command_line/backtrace_limit_spec.rb b/spec/ruby/command_line/backtrace_limit_spec.rb new file mode 100644 index 0000000000..56afa8efef --- /dev/null +++ b/spec/ruby/command_line/backtrace_limit_spec.rb @@ -0,0 +1,48 @@ +require_relative '../spec_helper' + +ruby_version_is "3.0" do + describe "The --backtrace-limit command line option" do + it "limits top-level backtraces to a given number of entries" do + file = fixture(__FILE__ , "backtrace.rb") + out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1) + out = out.gsub(__dir__, '') + + out.should == <<-MSG +top +/fixtures/backtrace.rb:2:in `a': oops (RuntimeError) +\tfrom /fixtures/backtrace.rb:6:in `b' +\tfrom /fixtures/backtrace.rb:10:in `c' +\t ... 2 levels... + MSG + end + + it "affects Exception#full_message" do + file = fixture(__FILE__ , "backtrace.rb") + out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1") + out = out.gsub(__dir__, '') + + out.should == <<-MSG +full_message +/fixtures/backtrace.rb:2:in `a': oops (RuntimeError) +\tfrom /fixtures/backtrace.rb:6:in `b' +\tfrom /fixtures/backtrace.rb:10:in `c' +\t ... 2 levels... + MSG + end + + it "does not affect Exception#backtrace" do + file = fixture(__FILE__ , "backtrace.rb") + out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1") + out = out.gsub(__dir__, '') + + out.should == <<-MSG +backtrace +/fixtures/backtrace.rb:2:in `a' +/fixtures/backtrace.rb:6:in `b' +/fixtures/backtrace.rb:10:in `c' +/fixtures/backtrace.rb:14:in `d' +/fixtures/backtrace.rb:29:in `<main>' + MSG + end + end +end diff --git a/spec/ruby/command_line/dash_e_spec.rb b/spec/ruby/command_line/dash_e_spec.rb index 70ecdd5dce..24ed34376d 100644 --- a/spec/ruby/command_line/dash_e_spec.rb +++ b/spec/ruby/command_line/dash_e_spec.rb @@ -23,9 +23,9 @@ describe "The -e command line option" do #needs to test return => LocalJumpError - describe "with -n and a Fixnum range" do + describe "with -n and an Integer range" do before :each do - @script = "-W0 -ne 'print if %s' #{fixture(__FILE__, "conditional_range.txt")}" + @script = "-ne 'print if %s' #{fixture(__FILE__, "conditional_range.txt")}" end it "mimics an awk conditional by comparing an inclusive-end range with $." do diff --git a/spec/ruby/command_line/dash_encoding_spec.rb b/spec/ruby/command_line/dash_encoding_spec.rb index 36ce55af5f..5803d328c1 100644 --- a/spec/ruby/command_line/dash_encoding_spec.rb +++ b/spec/ruby/command_line/dash_encoding_spec.rb @@ -25,6 +25,12 @@ describe "The --encoding command line option" do end it "does not accept a third encoding" do - ruby_exe(@test_string, options: "--disable-gems --encoding big5:#{@enc2}:utf-32le", args: "2>&1").should =~ /extra argument for --encoding: utf-32le/ + options = { + options: "--disable-gems --encoding big5:#{@enc2}:utf-32le", + args: "2>&1", + exit_status: 1 + } + + ruby_exe(@test_string, options).should =~ /extra argument for --encoding: utf-32le/ end end diff --git a/spec/ruby/command_line/dash_l_spec.rb b/spec/ruby/command_line/dash_l_spec.rb new file mode 100644 index 0000000000..5c1d3cf4cd --- /dev/null +++ b/spec/ruby/command_line/dash_l_spec.rb @@ -0,0 +1,31 @@ +require_relative '../spec_helper' + +describe "The -l command line option" do + before :each do + @names = fixture __FILE__, "full_names.txt" + end + + it "chomps lines with default separator" do + ruby_exe('puts $_.end_with?("\n")', options: "-n -l", escape: true, + args: " < #{@names}").should == + "false\nfalse\nfalse\n" + end + + it "chomps last line based on $/" do + ruby_exe('BEGIN { $/ = "ones\n" }; puts $_', options: "-W0 -n -l", escape: true, + args: " < #{@names}").should == + "alice j\nbob field\njames grey\n" + end + + it "sets $\\ to the value of $/" do + ruby_exe("puts $\\ == $/", options: "-W0 -n -l", escape: true, + args: " < #{@names}").should == + "true\ntrue\ntrue\n" + end + + it "sets $-l" do + ruby_exe("puts $-l", options: "-n -l", escape: true, + args: " < #{@names}").should == + "true\ntrue\ntrue\n" + end +end diff --git a/spec/ruby/command_line/dash_r_spec.rb b/spec/ruby/command_line/dash_r_spec.rb index b29895bd26..ea5bde5adf 100644 --- a/spec/ruby/command_line/dash_r_spec.rb +++ b/spec/ruby/command_line/dash_r_spec.rb @@ -7,7 +7,22 @@ describe "The -r command line option" do end it "requires the specified file" do - result = ruby_exe(@script, options: "-r #{@test_file}") - result.should include(@test_file + ".rb") + out = ruby_exe(@script, options: "-r #{@test_file}") + out.should include("REQUIRED") + out.should include(@test_file + ".rb") + end + + it "requires the file before parsing the main script" do + out = ruby_exe(fixture(__FILE__, "bad_syntax.rb"), options: "-r #{@test_file}", args: "2>&1", exit_status: 1) + $?.should_not.success? + out.should include("REQUIRED") + out.should include("syntax error") + end + + it "does not require the file if the main script file does not exist" do + out = `#{ruby_exe.to_a.join(' ')} -r #{@test_file} #{fixture(__FILE__, "does_not_exist.rb")} 2>&1` + $?.should_not.success? + out.should_not.include?("REQUIRED") + out.should.include?("No such file or directory") end end diff --git a/spec/ruby/command_line/dash_upper_c_spec.rb b/spec/ruby/command_line/dash_upper_c_spec.rb index 761beaadab..ece1b32105 100644 --- a/spec/ruby/command_line/dash_upper_c_spec.rb +++ b/spec/ruby/command_line/dash_upper_c_spec.rb @@ -1,23 +1,6 @@ require_relative '../spec_helper' +require_relative 'shared/change_directory' -describe 'The -C command line option' do - before :all do - @script = fixture(__FILE__, 'dash_upper_c_script.rb') - @tempdir = File.dirname(@script) - end - - it 'changes the PWD when using a file' do - output = ruby_exe(@script, options: "-C #{@tempdir}") - output.should == @tempdir - end - - it 'does not need a space after -C for the argument' do - output = ruby_exe(@script, options: "-C#{@tempdir}") - output.should == @tempdir - end - - it 'changes the PWD when using -e' do - output = ruby_exe(nil, options: "-C #{@tempdir} -e 'print Dir.pwd'") - output.should == @tempdir - end +describe "The -C command line option" do + it_behaves_like :command_line_change_directory, "-C" end diff --git a/spec/ruby/command_line/dash_upper_e_spec.rb b/spec/ruby/command_line/dash_upper_e_spec.rb index b3c6ce262b..5a83962583 100644 --- a/spec/ruby/command_line/dash_upper_e_spec.rb +++ b/spec/ruby/command_line/dash_upper_e_spec.rb @@ -31,6 +31,7 @@ describe "ruby -E" do it "raises a RuntimeError if used with -U" do ruby_exe("p 1", options: '-Eascii:ascii -U', - args: '2>&1').should =~ /RuntimeError/ + args: '2>&1', + exit_status: 1).should =~ /RuntimeError/ end end diff --git a/spec/ruby/command_line/dash_upper_k_spec.rb b/spec/ruby/command_line/dash_upper_k_spec.rb index ef1248b19c..7e71532295 100644 --- a/spec/ruby/command_line/dash_upper_k_spec.rb +++ b/spec/ruby/command_line/dash_upper_k_spec.rb @@ -6,24 +6,24 @@ describe 'The -K command line option' do end describe 'sets __ENCODING__ and Encoding.default_external' do - it "to Encoding::ASCII_8BIT with -Ka" do + it "to Encoding::BINARY with -Ka" do ruby_exe(@test_string, options: '-Ka').should == - [Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect + [Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect end - it "to Encoding::ASCII_8BIT with -KA" do + it "to Encoding::BINARY with -KA" do ruby_exe(@test_string, options: '-KA').should == - [Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect + [Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect end - it "to Encoding::ASCII_8BIT with -Kn" do + it "to Encoding::BINARY with -Kn" do ruby_exe(@test_string, options: '-Kn').should == - [Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect + [Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect end - it "to Encoding::ASCII_8BIT with -KN" do + it "to Encoding::BINARY with -KN" do ruby_exe(@test_string, options: '-KN').should == - [Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect + [Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect end it "to Encoding::EUC_JP with -Ke" do @@ -58,8 +58,8 @@ describe 'The -K command line option' do end it "ignores unknown codes" do - locale = Encoding.find('locale') + external = Encoding.find('external') ruby_exe(@test_string, options: '-KZ').should == - [Encoding::UTF_8.name, locale.name, nil].inspect + [Encoding::UTF_8.name, external.name, nil].inspect end end diff --git a/spec/ruby/command_line/dash_upper_s_spec.rb b/spec/ruby/command_line/dash_upper_s_spec.rb index 3a28fa2ad2..17991503f1 100644 --- a/spec/ruby/command_line/dash_upper_s_spec.rb +++ b/spec/ruby/command_line/dash_upper_s_spec.rb @@ -21,7 +21,7 @@ describe 'The -S command line option' do end it "runs launcher found in PATH and sets the exit status to 1 if it fails" do - result = ruby_exe(nil, options: '-S dash_s_fail', env: { 'PATH' => @path }, args: '2>&1') + result = ruby_exe(nil, options: '-S dash_s_fail', env: { 'PATH' => @path }, args: '2>&1', exit_status: 1) result.should =~ /\bdie\b/ $?.exitstatus.should == 1 end diff --git a/spec/ruby/command_line/dash_upper_u_spec.rb b/spec/ruby/command_line/dash_upper_u_spec.rb index 2546b5b9f4..d62718b095 100644 --- a/spec/ruby/command_line/dash_upper_u_spec.rb +++ b/spec/ruby/command_line/dash_upper_u_spec.rb @@ -32,12 +32,14 @@ describe "ruby -U" do it "raises a RuntimeError if used with -Eext:int" do ruby_exe("p 1", options: '-U -Eascii:ascii', - args: '2>&1').should =~ /RuntimeError/ + args: '2>&1', + exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError if used with -E:int" do ruby_exe("p 1", options: '-U -E:ascii', - args: '2>&1').should =~ /RuntimeError/ + args: '2>&1', + exit_status: 1).should =~ /RuntimeError/ end end diff --git a/spec/ruby/command_line/dash_upper_w_spec.rb b/spec/ruby/command_line/dash_upper_w_spec.rb index 31bb976ad2..4019510d42 100644 --- a/spec/ruby/command_line/dash_upper_w_spec.rb +++ b/spec/ruby/command_line/dash_upper_w_spec.rb @@ -18,3 +18,27 @@ end describe "The -W command line option with 2" do it_behaves_like :command_line_verbose, "-W2" end + +describe "The -W command line option with :deprecated" do + it "enables deprecation warnings" do + ruby_exe('p Warning[:deprecated]', options: '-W:deprecated').should == "true\n" + end +end + +describe "The -W command line option with :no-deprecated" do + it "suppresses deprecation warnings" do + ruby_exe('p Warning[:deprecated]', options: '-w -W:no-deprecated').should == "false\n" + end +end + +describe "The -W command line option with :experimental" do + it "enables experimental warnings" do + ruby_exe('p Warning[:experimental]', options: '-W:experimental').should == "true\n" + end +end + +describe "The -W command line option with :no-experimental" do + it "suppresses experimental warnings" do + ruby_exe('p Warning[:experimental]', options: '-w -W:no-experimental').should == "false\n" + end +end diff --git a/spec/ruby/command_line/dash_upper_x_spec.rb b/spec/ruby/command_line/dash_upper_x_spec.rb new file mode 100644 index 0000000000..8ef9aae4b1 --- /dev/null +++ b/spec/ruby/command_line/dash_upper_x_spec.rb @@ -0,0 +1,6 @@ +require_relative '../spec_helper' +require_relative 'shared/change_directory' + +describe "The -X command line option" do + it_behaves_like :command_line_change_directory, "-X" +end diff --git a/spec/ruby/command_line/dash_v_spec.rb b/spec/ruby/command_line/dash_v_spec.rb index 04d684fdad..a4f4dcd051 100644 --- a/spec/ruby/command_line/dash_v_spec.rb +++ b/spec/ruby/command_line/dash_v_spec.rb @@ -7,6 +7,7 @@ describe "The -v command line option" do describe "when used alone" do it "prints version and ends" do ruby_exe(nil, args: '-v').should include(RUBY_DESCRIPTION) - end + end unless (defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?) || + (defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?) end end diff --git a/spec/ruby/command_line/dash_w_spec.rb b/spec/ruby/command_line/dash_w_spec.rb index 1d93e0347b..f310dca3ed 100644 --- a/spec/ruby/command_line/dash_w_spec.rb +++ b/spec/ruby/command_line/dash_w_spec.rb @@ -3,4 +3,8 @@ require_relative 'shared/verbose' describe "The -w command line option" do it_behaves_like :command_line_verbose, "-w" + + it "enables both deprecated and experimental warnings" do + ruby_exe('p Warning[:deprecated]; p Warning[:experimental]', options: '-w').should == "true\ntrue\n" + end end diff --git a/spec/ruby/command_line/dash_x_spec.rb b/spec/ruby/command_line/dash_x_spec.rb index ad6be23063..ae14b61070 100644 --- a/spec/ruby/command_line/dash_x_spec.rb +++ b/spec/ruby/command_line/dash_x_spec.rb @@ -9,7 +9,7 @@ describe "The -x command line option" do it "fails when /\#!.*ruby.*/-ish line in target file is not found" do bad_embedded_ruby = fixture __FILE__, "bin/bad_embedded_ruby.txt" - result = ruby_exe(bad_embedded_ruby, options: '-x', args: '2>&1') + result = ruby_exe(bad_embedded_ruby, options: '-x', args: '2>&1', exit_status: 1) result.should include "no Ruby script found in input" end @@ -18,6 +18,4 @@ describe "The -x command line option" do result = ruby_exe(embedded_ruby) result.should == "success\n" end - - it "needs to be reviewed for spec completeness" end diff --git a/spec/ruby/command_line/error_message_spec.rb b/spec/ruby/command_line/error_message_spec.rb index 5fee3ead44..02150f30ce 100644 --- a/spec/ruby/command_line/error_message_spec.rb +++ b/spec/ruby/command_line/error_message_spec.rb @@ -2,10 +2,10 @@ require_relative '../spec_helper' describe "The error message caused by an exception" do it "is not printed to stdout" do - out = ruby_exe("this_does_not_exist", args: "2> #{File::NULL}") - out.chomp.empty?.should == true + out = ruby_exe("this_does_not_exist", args: "2> #{File::NULL}", exit_status: 1) + out.chomp.should.empty? - out = ruby_exe("end #syntax error", args: "2> #{File::NULL}") - out.chomp.empty?.should == true + out = ruby_exe("end #syntax error", args: "2> #{File::NULL}", exit_status: 1) + out.chomp.should.empty? end end diff --git a/spec/ruby/command_line/feature_spec.rb b/spec/ruby/command_line/feature_spec.rb new file mode 100644 index 0000000000..4a24cc6795 --- /dev/null +++ b/spec/ruby/command_line/feature_spec.rb @@ -0,0 +1,71 @@ +require_relative '../spec_helper' + +describe "The --enable and --disable flags" do + before :all do + # Since some specs disable reading RUBYOPT, we instead pass its contents as :options for those specs + rubyopt = [ENV["RUBYOPT"]] + rubyopt << ENV["#{RUBY_ENGINE.upcase}OPT"] unless RUBY_ENGINE == 'ruby' + @rubyopt = RUBY_ENGINE == "ruby" ? "" : rubyopt.compact.join(" ") + end + + it "can be used with gems" do + ruby_exe("p defined?(Gem)", options: "--enable=gems").chomp.should == "\"constant\"" + ruby_exe("p defined?(Gem)", options: "--disable=gems").chomp.should == "nil" + ruby_exe("p defined?(Gem)", options: "--enable-gems").chomp.should == "\"constant\"" + ruby_exe("p defined?(Gem)", options: "--disable-gems").chomp.should == "nil" + end + + it "can be used with gem" do + ruby_exe("p defined?(Gem)", options: "--enable=gem").chomp.should == "\"constant\"" + ruby_exe("p defined?(Gem)", options: "--disable=gem").chomp.should == "nil" + ruby_exe("p defined?(Gem)", options: "--enable-gem").chomp.should == "\"constant\"" + ruby_exe("p defined?(Gem)", options: "--disable-gem").chomp.should == "nil" + end + + it "can be used with did_you_mean" do + ruby_exe("p defined?(DidYouMean)", options: "--enable=did_you_mean").chomp.should == "\"constant\"" + ruby_exe("p defined?(DidYouMean)", options: "--disable=did_you_mean").chomp.should == "nil" + ruby_exe("p defined?(DidYouMean)", options: "--enable-did_you_mean").chomp.should == "\"constant\"" + ruby_exe("p defined?(DidYouMean)", options: "--disable-did_you_mean").chomp.should == "nil" + end + + it "can be used with rubyopt" do + ruby_exe("p $VERBOSE", options: "--enable=rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "true" + ruby_exe("p $VERBOSE", options: "#{@rubyopt} --disable=rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "false" + ruby_exe("p $VERBOSE", options: "--enable-rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "true" + ruby_exe("p $VERBOSE", options: "#{@rubyopt} --disable-rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "false" + end + + it "can be used with frozen-string-literal" do + ruby_exe("p 'foo'.frozen?", options: "--enable=frozen-string-literal").chomp.should == "true" + ruby_exe("p 'foo'.frozen?", options: "--disable=frozen-string-literal").chomp.should == "false" + ruby_exe("p 'foo'.frozen?", options: "--enable-frozen-string-literal").chomp.should == "true" + ruby_exe("p 'foo'.frozen?", options: "--disable-frozen-string-literal").chomp.should == "false" + end + + # frequently hangs for >60s on GitHub Actions macos-latest + # MinGW's YJIT support seems broken + platform_is_not :darwin, :mingw do + it "can be used with all for enable" do + e = "p [defined?(Gem), defined?(DidYouMean), $VERBOSE, 'foo'.frozen?]" + env = {'RUBYOPT' => '-w'} + # Use a single variant here because it can be quite slow as it might enable jit, etc + ruby_exe(e, options: "--enable-all", env: env).chomp.should == "[\"constant\", \"constant\", true, true]" + end + end + + it "can be used with all for disable" do + e = "p [defined?(Gem), defined?(DidYouMean), $VERBOSE, 'foo'.frozen?]" + env = {'RUBYOPT' => '-w'} + ruby_exe(e, options: "#{@rubyopt} --disable=all", env: env).chomp.should == "[nil, nil, false, false]" + ruby_exe(e, options: "#{@rubyopt} --disable-all", env: env).chomp.should == "[nil, nil, false, false]" + end + + it "prints a warning for unknown features" do + ruby_exe("p 14", options: "--enable=ruby-spec-feature-does-not-exist 2>&1").chomp.should include('warning: unknown argument for --enable') + ruby_exe("p 14", options: "--disable=ruby-spec-feature-does-not-exist 2>&1").chomp.should include('warning: unknown argument for --disable') + ruby_exe("p 14", options: "--enable-ruby-spec-feature-does-not-exist 2>&1").chomp.should include('warning: unknown argument for --enable') + ruby_exe("p 14", options: "--disable-ruby-spec-feature-does-not-exist 2>&1").chomp.should include('warning: unknown argument for --disable') + end + +end diff --git a/spec/ruby/command_line/fixtures/backtrace.rb b/spec/ruby/command_line/fixtures/backtrace.rb new file mode 100644 index 0000000000..99acae95c8 --- /dev/null +++ b/spec/ruby/command_line/fixtures/backtrace.rb @@ -0,0 +1,35 @@ +def a + raise 'oops' +end + +def b + a +end + +def c + b +end + +def d + c +end + +arg = ARGV.first +$stderr.puts arg + +case arg +when 'full_message' + begin + d + rescue => exc + puts exc.full_message + end +when 'backtrace' + begin + d + rescue => exc + puts exc.backtrace + end +else + d +end diff --git a/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh b/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh index 0eede2a99f..fd3249f0e5 100644 --- a/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh +++ b/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -exec somehow this file +echo 'error' && exit 1 #!ruby puts 'success' diff --git a/spec/ruby/command_line/fixtures/dash_upper_c_script.rb b/spec/ruby/command_line/fixtures/change_directory_script.rb index abe244705f..abe244705f 100644 --- a/spec/ruby/command_line/fixtures/dash_upper_c_script.rb +++ b/spec/ruby/command_line/fixtures/change_directory_script.rb diff --git a/spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb b/spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb index 074092c9d9..f5547a5bae 100644 --- a/spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb +++ b/spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb @@ -1 +1 @@ -p "abc".object_id == "abc".object_id +p "abc".equal?("abc") diff --git a/spec/ruby/command_line/fixtures/test_file.rb b/spec/ruby/command_line/fixtures/test_file.rb index 961e3c0b0c..30a832299e 100644 --- a/spec/ruby/command_line/fixtures/test_file.rb +++ b/spec/ruby/command_line/fixtures/test_file.rb @@ -1 +1 @@ -"test file" +puts "REQUIRED" diff --git a/spec/ruby/command_line/frozen_strings_spec.rb b/spec/ruby/command_line/frozen_strings_spec.rb index b2631a4c76..647b69daed 100644 --- a/spec/ruby/command_line/frozen_strings_spec.rb +++ b/spec/ruby/command_line/frozen_strings_spec.rb @@ -22,7 +22,8 @@ end describe "The --debug flag produces" do it "debugging info on attempted frozen string modification" do error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '--debug', args: "2>&1") - error_str.should include("can't modify frozen String, created at ") + error_str.should include("can't modify frozen String") + error_str.should include("created at") error_str.should include("command_line/fixtures/debug_info.rb:2") end end diff --git a/spec/ruby/command_line/rubylib_spec.rb b/spec/ruby/command_line/rubylib_spec.rb index 20e9c2cf95..b45919b997 100644 --- a/spec/ruby/command_line/rubylib_spec.rb +++ b/spec/ruby/command_line/rubylib_spec.rb @@ -30,6 +30,7 @@ describe "The RUBYLIB environment variable" do dir = tmp("rubylib/incl_front") ENV["RUBYLIB"] = @pre + dir paths = ruby_exe("puts $LOAD_PATH").lines.map(&:chomp) + paths.shift if paths.first.end_with?('/gem-rehash') if PlatformGuard.implementation? :ruby # In a MRI checkout, $PWD and some extra -I entries end up as # the first entries in $LOAD_PATH. So just assert that it's not last. diff --git a/spec/ruby/command_line/rubyopt_spec.rb b/spec/ruby/command_line/rubyopt_spec.rb index 2db42f77ef..bbea4d557d 100644 --- a/spec/ruby/command_line/rubyopt_spec.rb +++ b/spec/ruby/command_line/rubyopt_spec.rb @@ -59,6 +59,24 @@ describe "Processing RUBYOPT" do ruby_exe("p $VERBOSE", escape: true).chomp.should == "true" end + it "suppresses deprecation warnings for '-W:no-deprecated'" do + ENV["RUBYOPT"] = '-W:no-deprecated' + result = ruby_exe('$; = ""', args: '2>&1') + result.should == "" + end + + it "suppresses experimental warnings for '-W:no-experimental'" do + ENV["RUBYOPT"] = '-W:no-experimental' + result = ruby_exe('case 0; in a; end', args: '2>&1') + result.should == "" + end + + it "suppresses deprecation and experimental warnings for '-W:no-deprecated -W:no-experimental'" do + ENV["RUBYOPT"] = '-W:no-deprecated -W:no-experimental' + result = ruby_exe('case ($; = ""); in a; end', args: '2>&1') + result.should == "" + end + it "requires the file for '-r'" do f = fixture __FILE__, "rubyopt" ENV["RUBYOPT"] = "-r#{f}" @@ -67,101 +85,101 @@ describe "Processing RUBYOPT" do it "raises a RuntimeError for '-a'" do ENV["RUBYOPT"] = '-a' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-p'" do ENV["RUBYOPT"] = '-p' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-n'" do ENV["RUBYOPT"] = '-n' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-y'" do ENV["RUBYOPT"] = '-y' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-c'" do ENV["RUBYOPT"] = '-c' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-s'" do ENV["RUBYOPT"] = '-s' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-h'" do ENV["RUBYOPT"] = '-h' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '--help'" do ENV["RUBYOPT"] = '--help' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-l'" do ENV["RUBYOPT"] = '-l' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-S'" do ENV["RUBYOPT"] = '-S irb' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-e'" do ENV["RUBYOPT"] = '-e0' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-i'" do ENV["RUBYOPT"] = '-i.bak' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-x'" do ENV["RUBYOPT"] = '-x' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-C'" do ENV["RUBYOPT"] = '-C' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-X'" do ENV["RUBYOPT"] = '-X.' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-F'" do ENV["RUBYOPT"] = '-F' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '-0'" do ENV["RUBYOPT"] = '-0' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '--copyright'" do ENV["RUBYOPT"] = '--copyright' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '--version'" do ENV["RUBYOPT"] = '--version' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end it "raises a RuntimeError for '--yydebug'" do ENV["RUBYOPT"] = '--yydebug' - ruby_exe("", args: '2>&1').should =~ /RuntimeError/ + ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/ end end diff --git a/spec/ruby/command_line/shared/change_directory.rb b/spec/ruby/command_line/shared/change_directory.rb new file mode 100644 index 0000000000..9cb6e90ac6 --- /dev/null +++ b/spec/ruby/command_line/shared/change_directory.rb @@ -0,0 +1,21 @@ +describe :command_line_change_directory, shared: true do + before :all do + @script = fixture(__FILE__, 'change_directory_script.rb') + @tempdir = File.dirname(@script) + end + + it 'changes the PWD when using a file' do + output = ruby_exe(@script, options: "#{@method} #{@tempdir}") + output.should == @tempdir + end + + it 'does not need a space after -C for the argument' do + output = ruby_exe(@script, options: "#{@method}#{@tempdir}") + output.should == @tempdir + end + + it 'changes the PWD when using -e' do + output = ruby_exe(nil, options: "#{@method} #{@tempdir} -e 'print Dir.pwd'") + output.should == @tempdir + end +end diff --git a/spec/ruby/command_line/shared/verbose.rb b/spec/ruby/command_line/shared/verbose.rb index 457fe3006a..c5c44c269e 100644 --- a/spec/ruby/command_line/shared/verbose.rb +++ b/spec/ruby/command_line/shared/verbose.rb @@ -4,6 +4,6 @@ describe :command_line_verbose, shared: true do end it "sets $VERBOSE to true" do - ruby_exe(@script, options: @method).chomp.split.last.should == "true" + ruby_exe(@script, options: @method).chomp.b.split.last.should == "true" end end diff --git a/spec/ruby/command_line/syntax_error_spec.rb b/spec/ruby/command_line/syntax_error_spec.rb index f61cfe928d..444ea9635c 100644 --- a/spec/ruby/command_line/syntax_error_spec.rb +++ b/spec/ruby/command_line/syntax_error_spec.rb @@ -2,12 +2,12 @@ require_relative '../spec_helper' describe "The interpreter" do it "prints an error when given a file with invalid syntax" do - out = ruby_exe(fixture(__FILE__, "bad_syntax.rb"), args: "2>&1") + out = ruby_exe(fixture(__FILE__, "bad_syntax.rb"), args: "2>&1", exit_status: 1) out.should include "syntax error" end it "prints an error when given code via -e with invalid syntax" do - out = ruby_exe(nil, args: "-e 'a{' 2>&1") + out = ruby_exe(nil, args: "-e 'a{' 2>&1", exit_status: 1) out.should include "syntax error" end end |
