1 require_relative '../spec_helper'
3 describe "Processing RUBYOPT" do
5 @rubyopt, ENV["RUBYOPT"] = ENV["RUBYOPT"], nil
9 ENV["RUBYOPT"] = @rubyopt
12 it "adds the -I path to $LOAD_PATH" do
13 ENV["RUBYOPT"] = "-Ioptrubyspecincl"
14 result = ruby_exe("puts $LOAD_PATH.grep(/byspecin/)")
15 result.chomp[-15..-1].should == "optrubyspecincl"
18 it "sets $DEBUG to true for '-d'" do
20 command = %[puts "value of $DEBUG is \#{$DEBUG}"]
21 result = ruby_exe(command, args: "2>&1")
22 result.should =~ /value of \$DEBUG is true/
25 guard -> { not CROSS_COMPILING } do
26 it "prints the version number for '-v'" do
28 ruby_exe("")[/\A.*/].should == RUBY_DESCRIPTION.sub("+PRISM ", "")
31 it "ignores whitespace around the option" do
32 ENV["RUBYOPT"] = ' -v '
33 ruby_exe("")[/\A.*/].should == RUBY_DESCRIPTION.sub("+PRISM ", "")
37 it "sets $VERBOSE to true for '-w'" do
39 ruby_exe("p $VERBOSE").chomp.should == "true"
42 it "sets $VERBOSE to true for '-W'" do
44 ruby_exe("p $VERBOSE").chomp.should == "true"
47 it "sets $VERBOSE to nil for '-W0'" do
48 ENV["RUBYOPT"] = '-W0'
49 ruby_exe("p $VERBOSE").chomp.should == "nil"
52 it "sets $VERBOSE to false for '-W1'" do
53 ENV["RUBYOPT"] = '-W1'
54 ruby_exe("p $VERBOSE").chomp.should == "false"
57 it "sets $VERBOSE to true for '-W2'" do
58 ENV["RUBYOPT"] = '-W2'
59 ruby_exe("p $VERBOSE").chomp.should == "true"
62 it "suppresses deprecation warnings for '-W:no-deprecated'" do
63 ENV["RUBYOPT"] = '-W:no-deprecated'
64 result = ruby_exe('$; = ""', args: '2>&1')
68 it "suppresses experimental warnings for '-W:no-experimental'" do
69 ENV["RUBYOPT"] = '-W:no-experimental'
70 result = ruby_exe('case 0; in a; end', args: '2>&1')
74 it "suppresses deprecation and experimental warnings for '-W:no-deprecated -W:no-experimental'" do
75 ENV["RUBYOPT"] = '-W:no-deprecated -W:no-experimental'
76 result = ruby_exe('case ($; = ""); in a; end', args: '2>&1')
80 it "requires the file for '-r'" do
81 f = fixture __FILE__, "rubyopt"
82 ENV["RUBYOPT"] = "-r#{f}"
83 ruby_exe("0", args: '2>&1').should =~ /^rubyopt.rb required/
86 it "raises a RuntimeError for '-a'" do
88 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
91 it "raises a RuntimeError for '-p'" do
93 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
96 it "raises a RuntimeError for '-n'" do
98 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
101 it "raises a RuntimeError for '-y'" do
102 ENV["RUBYOPT"] = '-y'
103 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
106 it "raises a RuntimeError for '-c'" do
107 ENV["RUBYOPT"] = '-c'
108 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
111 it "raises a RuntimeError for '-s'" do
112 ENV["RUBYOPT"] = '-s'
113 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
116 it "raises a RuntimeError for '-h'" do
117 ENV["RUBYOPT"] = '-h'
118 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
121 it "raises a RuntimeError for '--help'" do
122 ENV["RUBYOPT"] = '--help'
123 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
126 it "raises a RuntimeError for '-l'" do
127 ENV["RUBYOPT"] = '-l'
128 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
131 it "raises a RuntimeError for '-S'" do
132 ENV["RUBYOPT"] = '-S irb'
133 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
136 it "raises a RuntimeError for '-e'" do
137 ENV["RUBYOPT"] = '-e0'
138 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
141 it "raises a RuntimeError for '-i'" do
142 ENV["RUBYOPT"] = '-i.bak'
143 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
146 it "raises a RuntimeError for '-x'" do
147 ENV["RUBYOPT"] = '-x'
148 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
151 it "raises a RuntimeError for '-C'" do
152 ENV["RUBYOPT"] = '-C'
153 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
156 it "raises a RuntimeError for '-X'" do
157 ENV["RUBYOPT"] = '-X.'
158 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
161 it "raises a RuntimeError for '-F'" do
162 ENV["RUBYOPT"] = '-F'
163 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
166 it "raises a RuntimeError for '-0'" do
167 ENV["RUBYOPT"] = '-0'
168 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
171 it "raises a RuntimeError for '--copyright'" do
172 ENV["RUBYOPT"] = '--copyright'
173 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
176 it "raises a RuntimeError for '--version'" do
177 ENV["RUBYOPT"] = '--version'
178 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
181 it "raises a RuntimeError for '--yydebug'" do
182 ENV["RUBYOPT"] = '--yydebug'
183 ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/