mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Move spec/rubyspec to spec/ruby for consistency
* Other ruby implementations use the spec/ruby directory. [Misc #13792] [ruby-core:82287] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
75bfc6440d
commit
1d15d5f080
4370 changed files with 0 additions and 0 deletions
17
spec/ruby/command_line/dash_a_spec.rb
Normal file
17
spec/ruby/command_line/dash_a_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
describe "The -a command line option" do
|
||||
before :each do
|
||||
@names = fixture __FILE__, "full_names.txt"
|
||||
end
|
||||
|
||||
it "runs the code in loop conditional on Kernel.gets()" do
|
||||
ruby_exe("puts $F.last", options: "-n -a", escape: true,
|
||||
args: " < #{@names}").should ==
|
||||
"jones\nfield\ngrey\n"
|
||||
end
|
||||
|
||||
it "sets $-a" do
|
||||
ruby_exe("puts $-a", options: "-n -a", escape: true,
|
||||
args: " < #{@names}").should ==
|
||||
"true\ntrue\ntrue\n"
|
||||
end
|
||||
end
|
13
spec/ruby/command_line/dash_c_spec.rb
Normal file
13
spec/ruby/command_line/dash_c_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
describe "The -c command line option" do
|
||||
it "checks syntax in given file" do
|
||||
ruby_exe(nil, args: "-c #{__FILE__}").chomp.should == "Syntax OK"
|
||||
end
|
||||
|
||||
it "checks syntax in -e strings" do
|
||||
ruby_exe(nil, args: "-c -e 'puts 1' -e 'hello world'").chomp.should == "Syntax OK"
|
||||
end
|
||||
|
||||
#Also needs spec for reading from STDIN
|
||||
end
|
22
spec/ruby/command_line/dash_d_spec.rb
Normal file
22
spec/ruby/command_line/dash_d_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
describe "The -d command line option" do
|
||||
before :each do
|
||||
@script = fixture __FILE__, "debug.rb"
|
||||
end
|
||||
|
||||
it "sets $DEBUG to true" do
|
||||
ruby_exe(@script, options: "-d",
|
||||
args: "0 2> #{File::NULL}").chomp.should == "$DEBUG true"
|
||||
end
|
||||
|
||||
it "sets $VERBOSE to true" do
|
||||
ruby_exe(@script, options: "-d",
|
||||
args: "1 2> #{File::NULL}").chomp.should == "$VERBOSE true"
|
||||
end
|
||||
|
||||
it "sets $-d to true" do
|
||||
ruby_exe(@script, options: "-d",
|
||||
args: "2 2> #{File::NULL}").chomp.should == "$-d true"
|
||||
end
|
||||
end
|
41
spec/ruby/command_line/dash_e_spec.rb
Normal file
41
spec/ruby/command_line/dash_e_spec.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
describe "The -e command line option" do
|
||||
it "evaluates the given string" do
|
||||
ruby_exe("puts 'foo'").chomp.should == "foo"
|
||||
end
|
||||
|
||||
it "joins multiple strings with newlines" do
|
||||
ruby_exe(nil, args: %Q{-e "puts 'hello" -e "world'" 2>&1}).chomp.should == "hello\nworld"
|
||||
end
|
||||
|
||||
it "uses 'main' as self" do
|
||||
ruby_exe("puts self", escape: false).chomp.should == "main"
|
||||
end
|
||||
|
||||
it "uses '-e' as file" do
|
||||
ruby_exe("puts __FILE__", escape: false).chomp.should == "-e"
|
||||
end
|
||||
|
||||
it "uses '-e' in $0" do
|
||||
system(*ruby_exe, '-e', 'exit $0 == "-e"').should == true
|
||||
end
|
||||
|
||||
#needs to test return => LocalJumpError
|
||||
|
||||
describe "with -n and a Fixnum range" do
|
||||
before :each do
|
||||
@script = "-ne 'print if %s' #{fixture(__FILE__, "conditional_range.txt")}"
|
||||
end
|
||||
|
||||
it "mimics an awk conditional by comparing an inclusive-end range with $." do
|
||||
ruby_exe(nil, args: (@script % "2..3")).should == "2\n3\n"
|
||||
ruby_exe(nil, args: (@script % "2..2")).should == "2\n"
|
||||
end
|
||||
|
||||
it "mimics a sed conditional by comparing an exclusive-end range with $." do
|
||||
ruby_exe(nil, args: (@script % "2...3")).should == "2\n3\n"
|
||||
ruby_exe(nil, args: (@script % "2...2")).should == "2\n3\n4\n5\n"
|
||||
end
|
||||
end
|
||||
end
|
34
spec/ruby/command_line/dash_n_spec.rb
Normal file
34
spec/ruby/command_line/dash_n_spec.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
describe "The -n command line option" do
|
||||
before :each do
|
||||
@names = fixture __FILE__, "names.txt"
|
||||
end
|
||||
|
||||
it "runs the code in loop conditional on Kernel.gets()" do
|
||||
ruby_exe("puts $_", options: "-n", escape: true,
|
||||
args: " < #{@names}").should ==
|
||||
"alice\nbob\njames\n"
|
||||
end
|
||||
|
||||
it "only evaluates BEGIN blocks once" do
|
||||
ruby_exe("BEGIN { puts \"hi\" }; puts $_", options: "-n", escape: true,
|
||||
args: " < #{@names}").should ==
|
||||
"hi\nalice\nbob\njames\n"
|
||||
end
|
||||
|
||||
it "only evaluates END blocks once" do
|
||||
ruby_exe("puts $_; END {puts \"bye\"}", options: "-n", escape: true,
|
||||
args: " < #{@names}").should ==
|
||||
"alice\nbob\njames\nbye\n"
|
||||
end
|
||||
|
||||
it "allows summing over a whole file" do
|
||||
script = <<-script
|
||||
BEGIN { $total = 0 }
|
||||
$total += 1
|
||||
END { puts $total }
|
||||
script
|
||||
ruby_exe(script, options: "-n", escape: true,
|
||||
args: " < #{@names}").should ==
|
||||
"3\n"
|
||||
end
|
||||
end
|
17
spec/ruby/command_line/dash_p_spec.rb
Normal file
17
spec/ruby/command_line/dash_p_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
describe "The -p command line option" do
|
||||
before :each do
|
||||
@names = fixture __FILE__, "names.txt"
|
||||
end
|
||||
|
||||
it "runs the code in loop conditional on Kernel.gets() and prints $_" do
|
||||
ruby_exe("$_ = $_.upcase", options: "-p", escape: true,
|
||||
args: " < #{@names}").should ==
|
||||
"ALICE\nBOB\nJAMES\n"
|
||||
end
|
||||
|
||||
it "sets $-p" do
|
||||
ruby_exe("$_ = $-p", options: "-p", escape: true,
|
||||
args: " < #{@names}").should ==
|
||||
"truetruetrue"
|
||||
end
|
||||
end
|
13
spec/ruby/command_line/dash_r_spec.rb
Normal file
13
spec/ruby/command_line/dash_r_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
describe "The -r command line option" do
|
||||
before :each do
|
||||
@script = fixture __FILE__, "require.rb"
|
||||
@test_file = fixture __FILE__, "test_file"
|
||||
end
|
||||
|
||||
it "requires the specified file" do
|
||||
result = ruby_exe(@script, options: "-r #{@test_file}")
|
||||
result.should include(@test_file + ".rb")
|
||||
end
|
||||
end
|
52
spec/ruby/command_line/dash_s_spec.rb
Normal file
52
spec/ruby/command_line/dash_s_spec.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
describe "The -s command line option" do
|
||||
describe "when using -- to stop parsing" do
|
||||
it "sets the value to true without an explicit value" do
|
||||
ruby_exe(nil, options: "-s -e 'p $n'",
|
||||
args: "-- -n").chomp.should == "true"
|
||||
end
|
||||
|
||||
it "parses single letter args into globals" do
|
||||
ruby_exe(nil, options: "-s -e 'puts $n'",
|
||||
args: "-- -n=blah").chomp.should == "blah"
|
||||
end
|
||||
|
||||
it "parses long args into globals" do
|
||||
ruby_exe(nil, options: "-s -e 'puts $_name'",
|
||||
args: "-- --name=blah").chomp.should == "blah"
|
||||
end
|
||||
|
||||
it "converts extra dashes into underscores" do
|
||||
ruby_exe(nil, options: "-s -e 'puts $___name__test__'",
|
||||
args: "-- ----name--test--=blah").chomp.should == "blah"
|
||||
end
|
||||
end
|
||||
|
||||
describe "when running a script" do
|
||||
before :all do
|
||||
@script = fixture __FILE__, "dash_s_script.rb"
|
||||
end
|
||||
|
||||
it "sets the value to true without an explicit value" do
|
||||
ruby_exe(@script, options: "-s",
|
||||
args: "-n 0").chomp.should == "true"
|
||||
end
|
||||
|
||||
it "parses single letter args into globals" do
|
||||
ruby_exe(@script, options: "-s",
|
||||
args: "-n=blah 1").chomp.should == "blah"
|
||||
end
|
||||
|
||||
it "parses long args into globals" do
|
||||
ruby_exe(@script, options: "-s",
|
||||
args: "--name=blah 2").chomp.should == "blah"
|
||||
end
|
||||
|
||||
it "converts extra dashes into underscores" do
|
||||
ruby_exe(@script, options: "-s",
|
||||
args: "----name--test--=blah 3").chomp.should == "blah"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
18
spec/ruby/command_line/dash_upper_c_spec.rb
Normal file
18
spec/ruby/command_line/dash_upper_c_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
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 'changes the PWD when using -e' do
|
||||
output = ruby_exe(nil, options: "-C #{@tempdir} -e 'print Dir.pwd'")
|
||||
output.should == @tempdir
|
||||
end
|
||||
end
|
7
spec/ruby/command_line/dash_upper_e_spec.rb
Normal file
7
spec/ruby/command_line/dash_upper_e_spec.rb
Normal file
|
@ -0,0 +1,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/
|
||||
end
|
||||
end
|
11
spec/ruby/command_line/dash_upper_f_spec.rb
Normal file
11
spec/ruby/command_line/dash_upper_f_spec.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
describe "the -F command line option" do
|
||||
before :each do
|
||||
@passwd = fixture __FILE__, "passwd_file.txt"
|
||||
end
|
||||
|
||||
it "specifies the field separator pattern for -a" do
|
||||
ruby_exe("puts $F[0]", options: "-naF:", escape: true,
|
||||
args: " < #{@passwd}").should ==
|
||||
"nobody\nroot\ndaemon\n"
|
||||
end
|
||||
end
|
11
spec/ruby/command_line/dash_upper_i_spec.rb
Normal file
11
spec/ruby/command_line/dash_upper_i_spec.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
describe "The -I command line option" do
|
||||
before :each do
|
||||
@script = fixture __FILE__, "loadpath.rb"
|
||||
end
|
||||
|
||||
it "adds the path to the load path ($:)" do
|
||||
ruby_exe(@script, options: "-I fixtures").should include("fixtures")
|
||||
end
|
||||
end
|
33
spec/ruby/command_line/dash_upper_k_spec.rb
Normal file
33
spec/ruby/command_line/dash_upper_k_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
describe 'The -K command line option sets __ENCODING__' do
|
||||
it "to Encoding::ASCII_8BIT with -Ka" do
|
||||
ruby_exe("print __ENCODING__", options: '-Ka').should == Encoding::ASCII_8BIT.to_s
|
||||
end
|
||||
|
||||
it "to Encoding::ASCII_8BIT with -KA" do
|
||||
ruby_exe("print __ENCODING__", options: '-KA').should == Encoding::ASCII_8BIT.to_s
|
||||
end
|
||||
|
||||
it "to Encoding::EUC_JP with -Ke" do
|
||||
ruby_exe("print __ENCODING__", options: '-Ke').should == Encoding::EUC_JP.to_s
|
||||
end
|
||||
|
||||
it "to Encoding::EUC_JP with -KE" do
|
||||
ruby_exe("print __ENCODING__", options: '-KE').should == Encoding::EUC_JP.to_s
|
||||
end
|
||||
|
||||
it "to Encoding::UTF_8 with -Ku" do
|
||||
ruby_exe("print __ENCODING__", options: '-Ku').should == Encoding::UTF_8.to_s
|
||||
end
|
||||
|
||||
it "to Encoding::UTF_8 with -KU" do
|
||||
ruby_exe("print __ENCODING__", options: '-KU').should == Encoding::UTF_8.to_s
|
||||
end
|
||||
|
||||
it "to Encoding::Windows_31J with -Ks" do
|
||||
ruby_exe("print __ENCODING__", options: '-Ks').should == Encoding::Windows_31J.to_s
|
||||
end
|
||||
|
||||
it "to Encoding::Windows_31J with -KS" do
|
||||
ruby_exe("print __ENCODING__", options: '-KS').should == Encoding::Windows_31J.to_s
|
||||
end
|
||||
end
|
29
spec/ruby/command_line/dash_upper_s_spec.rb
Normal file
29
spec/ruby/command_line/dash_upper_s_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
describe 'The -S command line option' do
|
||||
before :each do
|
||||
@path = [ENV['PATH'], fixture(__FILE__, "bin")].join(':')
|
||||
end
|
||||
|
||||
platform_is_not :windows do
|
||||
# On VirtualBox shared directory (vboxsf) all files are world writable
|
||||
# and MRI shows warning when including world writable path in ENV['PATH'].
|
||||
# This is why we are using /success$/ matching in the following cases.
|
||||
|
||||
it "runs launcher found in PATH, but only code after the first /\#!.*ruby.*/-ish line in target file" do
|
||||
result = ruby_exe(nil, options: '-S hybrid_launcher.sh', env: { 'PATH' => @path }, args: '2>&1')
|
||||
result.should =~ /success$/
|
||||
end
|
||||
|
||||
it "runs launcher found in PATH" do
|
||||
result = ruby_exe(nil, options: '-S launcher.rb', env: { 'PATH' => @path }, args: '2>&1')
|
||||
result.should =~ /success$/
|
||||
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.should =~ /\bdie\b/
|
||||
$?.exitstatus.should == 1
|
||||
end
|
||||
end
|
||||
end
|
41
spec/ruby/command_line/dash_upper_u_spec.rb
Normal file
41
spec/ruby/command_line/dash_upper_u_spec.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
describe "ruby -U" do
|
||||
it "sets Encoding.default_internal to UTF-8" do
|
||||
ruby_exe('print Encoding.default_internal.name',
|
||||
options: '-U').should == 'UTF-8'
|
||||
end
|
||||
|
||||
it "does nothing different if specified multiple times" do
|
||||
ruby_exe('print Encoding.default_internal.name',
|
||||
options: '-U -U').should == 'UTF-8'
|
||||
end
|
||||
|
||||
it "is overruled by Encoding.default_internal=" do
|
||||
ruby_exe('Encoding.default_internal="ascii"; print Encoding.default_internal.name',
|
||||
options: '-U').should == 'US-ASCII'
|
||||
end
|
||||
|
||||
it "does not affect the default external encoding" do
|
||||
ruby_exe('Encoding.default_external="ascii"; print Encoding.default_external.name',
|
||||
options: '-U').should == 'US-ASCII'
|
||||
end
|
||||
|
||||
it "does not affect the source encoding" do
|
||||
ruby_exe("print __ENCODING__.name",
|
||||
options: '-U -KE').should == 'EUC-JP'
|
||||
ruby_exe("print __ENCODING__.name",
|
||||
options: '-KE -U').should == 'EUC-JP'
|
||||
end
|
||||
|
||||
# I assume IO redirection will break on Windows...
|
||||
it "raises a RuntimeError if used with -Eext:int" do
|
||||
ruby_exe("p 1",
|
||||
options: '-U -Eascii:ascii',
|
||||
args: '2>&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/
|
||||
end
|
||||
end
|
20
spec/ruby/command_line/dash_upper_w_spec.rb
Normal file
20
spec/ruby/command_line/dash_upper_w_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/verbose', __FILE__)
|
||||
|
||||
describe "The -W command line option" do
|
||||
before :each do
|
||||
@script = fixture __FILE__, "verbose.rb"
|
||||
end
|
||||
|
||||
it "with 0 sets $VERBOSE to nil" do
|
||||
ruby_exe(@script, options: "-W0").chomp.should == "nil"
|
||||
end
|
||||
|
||||
it "with 1 sets $VERBOSE to false" do
|
||||
ruby_exe(@script, options: "-W1").chomp.should == "false"
|
||||
end
|
||||
end
|
||||
|
||||
describe "The -W command line option with 2" do
|
||||
it_behaves_like :command_line_verbose, "-W2"
|
||||
end
|
13
spec/ruby/command_line/dash_v_spec.rb
Normal file
13
spec/ruby/command_line/dash_v_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/verbose', __FILE__)
|
||||
|
||||
describe "The -v command line option" do
|
||||
it_behaves_like :command_line_verbose, "-v"
|
||||
|
||||
describe "when used alone" do
|
||||
it "prints version and ends" do
|
||||
version = ruby_exe(nil, args: '--version')
|
||||
ruby_exe(nil, args: '-v').should == version
|
||||
end
|
||||
end
|
||||
end
|
6
spec/ruby/command_line/dash_w_spec.rb
Normal file
6
spec/ruby/command_line/dash_w_spec.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
require File.expand_path('../shared/verbose', __FILE__)
|
||||
|
||||
describe "The -w command line option" do
|
||||
it_behaves_like :command_line_verbose, "-w"
|
||||
end
|
21
spec/ruby/command_line/dash_x_spec.rb
Normal file
21
spec/ruby/command_line/dash_x_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
describe "The -x command line option" do
|
||||
it "runs code after the first /\#!.*ruby.*/-ish line in target file" do
|
||||
embedded_ruby = fixture __FILE__, "bin/embedded_ruby.txt"
|
||||
result = ruby_exe(embedded_ruby, options: '-x')
|
||||
result.should == "success\n"
|
||||
end
|
||||
|
||||
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.should include "no Ruby script found in input"
|
||||
end
|
||||
|
||||
it "behaves as -x was set when non-ruby shebang is encountered on first line" do
|
||||
embedded_ruby = fixture __FILE__, "bin/hybrid_launcher.sh"
|
||||
result = ruby_exe(embedded_ruby)
|
||||
result.should == "success\n"
|
||||
end
|
||||
|
||||
it "needs to be reviewed for spec completeness"
|
||||
end
|
11
spec/ruby/command_line/error_message_spec.rb
Normal file
11
spec/ruby/command_line/error_message_spec.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
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("end #syntax error", args: "2> #{File::NULL}")
|
||||
out.chomp.empty?.should == true
|
||||
end
|
||||
end
|
1
spec/ruby/command_line/fixtures/bad_syntax.rb
Normal file
1
spec/ruby/command_line/fixtures/bad_syntax.rb
Normal file
|
@ -0,0 +1 @@
|
|||
f {
|
|
@ -0,0 +1,3 @@
|
|||
@@@This line is not value Ruby
|
||||
#!rub_y
|
||||
puts 'success'
|
1
spec/ruby/command_line/fixtures/bin/dash_s_fail
Normal file
1
spec/ruby/command_line/fixtures/bin/dash_s_fail
Normal file
|
@ -0,0 +1 @@
|
|||
raise 'die'
|
3
spec/ruby/command_line/fixtures/bin/embedded_ruby.txt
Normal file
3
spec/ruby/command_line/fixtures/bin/embedded_ruby.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
@@@This line is not value Ruby
|
||||
#!ruby
|
||||
puts 'success'
|
4
spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh
Normal file
4
spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/env bash
|
||||
exec somehow this file
|
||||
#!ruby
|
||||
puts 'success'
|
2
spec/ruby/command_line/fixtures/bin/launcher.rb
Normal file
2
spec/ruby/command_line/fixtures/bin/launcher.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
#!ruby
|
||||
puts 'success'
|
5
spec/ruby/command_line/fixtures/conditional_range.txt
Normal file
5
spec/ruby/command_line/fixtures/conditional_range.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
12
spec/ruby/command_line/fixtures/dash_s_script.rb
Normal file
12
spec/ruby/command_line/fixtures/dash_s_script.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
which = ARGV.shift.to_i
|
||||
|
||||
case which
|
||||
when 0
|
||||
p $n
|
||||
when 1
|
||||
puts $n
|
||||
when 2
|
||||
puts $_name
|
||||
when 3
|
||||
puts $___name__test__
|
||||
end
|
1
spec/ruby/command_line/fixtures/dash_upper_c_script.rb
Normal file
1
spec/ruby/command_line/fixtures/dash_upper_c_script.rb
Normal file
|
@ -0,0 +1 @@
|
|||
print Dir.pwd
|
10
spec/ruby/command_line/fixtures/debug.rb
Normal file
10
spec/ruby/command_line/fixtures/debug.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
which = ARGV.first.to_i
|
||||
|
||||
case which
|
||||
when 0
|
||||
puts "$DEBUG #{$DEBUG}"
|
||||
when 1
|
||||
puts "$VERBOSE #{$VERBOSE}"
|
||||
when 2
|
||||
puts "$-d #{$-d}"
|
||||
end
|
11
spec/ruby/command_line/fixtures/debug_info.rb
Normal file
11
spec/ruby/command_line/fixtures/debug_info.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
a = 'string'
|
||||
b = a
|
||||
c = b
|
||||
d = c
|
||||
e = d
|
||||
begin
|
||||
a << 'new part'
|
||||
rescue Exception => e
|
||||
print e.message
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
require_relative 'freeze_flag_required'
|
||||
|
||||
p "abc".object_id == $second_literal_id
|
|
@ -0,0 +1,3 @@
|
|||
require_relative 'freeze_flag_required_diff_enc'
|
||||
|
||||
p "abc".object_id != $second_literal_id
|
|
@ -0,0 +1,2 @@
|
|||
ids = Array.new(2) { "abc".object_id }
|
||||
p ids.first == ids.last
|
1
spec/ruby/command_line/fixtures/freeze_flag_required.rb
Normal file
1
spec/ruby/command_line/fixtures/freeze_flag_required.rb
Normal file
|
@ -0,0 +1 @@
|
|||
$second_literal_id = "abc".object_id
|
BIN
spec/ruby/command_line/fixtures/freeze_flag_required_diff_enc.rb
Normal file
BIN
spec/ruby/command_line/fixtures/freeze_flag_required_diff_enc.rb
Normal file
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
p "abc".object_id == "abc".object_id
|
3
spec/ruby/command_line/fixtures/full_names.txt
Normal file
3
spec/ruby/command_line/fixtures/full_names.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
alice jones
|
||||
bob field
|
||||
james grey
|
1
spec/ruby/command_line/fixtures/loadpath.rb
Normal file
1
spec/ruby/command_line/fixtures/loadpath.rb
Normal file
|
@ -0,0 +1 @@
|
|||
puts $:
|
3
spec/ruby/command_line/fixtures/names.txt
Normal file
3
spec/ruby/command_line/fixtures/names.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
alice
|
||||
bob
|
||||
james
|
3
spec/ruby/command_line/fixtures/passwd_file.txt
Normal file
3
spec/ruby/command_line/fixtures/passwd_file.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false
|
||||
root:*:0:0:System Administrator:/var/root:/bin/sh
|
||||
daemon:*:1:1:System Services:/var/root:/usr/bin/false
|
1
spec/ruby/command_line/fixtures/require.rb
Normal file
1
spec/ruby/command_line/fixtures/require.rb
Normal file
|
@ -0,0 +1 @@
|
|||
puts $"
|
1
spec/ruby/command_line/fixtures/rubyopt.rb
Normal file
1
spec/ruby/command_line/fixtures/rubyopt.rb
Normal file
|
@ -0,0 +1 @@
|
|||
puts "rubyopt.rb required"
|
1
spec/ruby/command_line/fixtures/test_file.rb
Normal file
1
spec/ruby/command_line/fixtures/test_file.rb
Normal file
|
@ -0,0 +1 @@
|
|||
"test file"
|
1
spec/ruby/command_line/fixtures/verbose.rb
Normal file
1
spec/ruby/command_line/fixtures/verbose.rb
Normal file
|
@ -0,0 +1 @@
|
|||
puts $VERBOSE.inspect
|
30
spec/ruby/command_line/frozen_strings_spec.rb
Normal file
30
spec/ruby/command_line/frozen_strings_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
ruby_version_is "2.3" do
|
||||
describe "The --enable-frozen-string-literal flag causes string literals to" do
|
||||
|
||||
it "produce the same object each time" do
|
||||
ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
|
||||
end
|
||||
|
||||
it "produce the same object for literals with the same content" do
|
||||
ruby_exe(fixture(__FILE__, "freeze_flag_two_literals.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
|
||||
end
|
||||
|
||||
it "produce the same object for literals with the same content in different files" do
|
||||
ruby_exe(fixture(__FILE__, "freeze_flag_across_files.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
|
||||
end
|
||||
|
||||
it "produce different objects for literals with the same content in different files if they have different encodings" do
|
||||
ruby_exe(fixture(__FILE__, "freeze_flag_across_files_diff_enc.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
|
||||
end
|
||||
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("command_line/fixtures/debug_info.rb:2")
|
||||
end
|
||||
end
|
||||
end
|
160
spec/ruby/command_line/rubyopt_spec.rb
Normal file
160
spec/ruby/command_line/rubyopt_spec.rb
Normal file
|
@ -0,0 +1,160 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
describe "Processing RUBYOPT" do
|
||||
before (:each) do
|
||||
@rubyopt, ENV["RUBYOPT"] = ENV["RUBYOPT"], nil
|
||||
end
|
||||
|
||||
after (:each) do
|
||||
ENV["RUBYOPT"] = @rubyopt
|
||||
end
|
||||
|
||||
it "adds the -I path to $LOAD_PATH" do
|
||||
ENV["RUBYOPT"] = "-Ioptrubyspecincl"
|
||||
result = ruby_exe("puts $LOAD_PATH.grep(/byspecin/)", escape: true)
|
||||
result.chomp[-15..-1].should == "optrubyspecincl"
|
||||
end
|
||||
|
||||
it "sets $DEBUG to true for '-d'" do
|
||||
ENV["RUBYOPT"] = '-d'
|
||||
command = %[puts "value of $DEBUG is \#{$DEBUG}"]
|
||||
result = ruby_exe(command, escape: true, args: "2>&1")
|
||||
result.should =~ /value of \$DEBUG is true/
|
||||
end
|
||||
|
||||
it "prints the version number for '-v'" do
|
||||
ENV["RUBYOPT"] = '-v'
|
||||
ruby_exe("")[/\A.*/].should == RUBY_DESCRIPTION
|
||||
end
|
||||
|
||||
it "sets $VERBOSE to true for '-w'" do
|
||||
ENV["RUBYOPT"] = '-w'
|
||||
ruby_exe("p $VERBOSE", escape: true).chomp.should == "true"
|
||||
end
|
||||
|
||||
it "sets $VERBOSE to true for '-W'" do
|
||||
ENV["RUBYOPT"] = '-W'
|
||||
ruby_exe("p $VERBOSE", escape: true).chomp.should == "true"
|
||||
end
|
||||
|
||||
it "sets $VERBOSE to nil for '-W0'" do
|
||||
ENV["RUBYOPT"] = '-W0'
|
||||
ruby_exe("p $VERBOSE", escape: true).chomp.should == "nil"
|
||||
end
|
||||
|
||||
it "sets $VERBOSE to false for '-W1'" do
|
||||
ENV["RUBYOPT"] = '-W1'
|
||||
ruby_exe("p $VERBOSE", escape: true).chomp.should == "false"
|
||||
end
|
||||
|
||||
it "sets $VERBOSE to true for '-W2'" do
|
||||
ENV["RUBYOPT"] = '-W2'
|
||||
ruby_exe("p $VERBOSE", escape: true).chomp.should == "true"
|
||||
end
|
||||
|
||||
it "requires the file for '-r'" do
|
||||
f = fixture __FILE__, "rubyopt"
|
||||
ENV["RUBYOPT"] = "-r#{f}"
|
||||
ruby_exe("0", args: '2>&1').should =~ /^rubyopt.rb required/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-a'" do
|
||||
ENV["RUBYOPT"] = '-a'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-p'" do
|
||||
ENV["RUBYOPT"] = '-p'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-n'" do
|
||||
ENV["RUBYOPT"] = '-n'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-y'" do
|
||||
ENV["RUBYOPT"] = '-y'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-c'" do
|
||||
ENV["RUBYOPT"] = '-c'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-s'" do
|
||||
ENV["RUBYOPT"] = '-s'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-h'" do
|
||||
ENV["RUBYOPT"] = '-h'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '--help'" do
|
||||
ENV["RUBYOPT"] = '--help'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-l'" do
|
||||
ENV["RUBYOPT"] = '-l'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-S'" do
|
||||
ENV["RUBYOPT"] = '-S irb'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-e'" do
|
||||
ENV["RUBYOPT"] = '-e0'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-i'" do
|
||||
ENV["RUBYOPT"] = '-i.bak'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-x'" do
|
||||
ENV["RUBYOPT"] = '-x'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-C'" do
|
||||
ENV["RUBYOPT"] = '-C'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-X'" do
|
||||
ENV["RUBYOPT"] = '-X.'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-F'" do
|
||||
ENV["RUBYOPT"] = '-F'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '-0'" do
|
||||
ENV["RUBYOPT"] = '-0'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '--copyright'" do
|
||||
ENV["RUBYOPT"] = '--copyright'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '--version'" do
|
||||
ENV["RUBYOPT"] = '--version'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
|
||||
it "raises a RuntimeError for '--yydebug'" do
|
||||
ENV["RUBYOPT"] = '--yydebug'
|
||||
ruby_exe("", args: '2>&1').should =~ /RuntimeError/
|
||||
end
|
||||
end
|
9
spec/ruby/command_line/shared/verbose.rb
Normal file
9
spec/ruby/command_line/shared/verbose.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
describe :command_line_verbose, shared: true do
|
||||
before :each do
|
||||
@script = fixture __FILE__, "verbose.rb"
|
||||
end
|
||||
|
||||
it "sets $VERBOSE to true" do
|
||||
ruby_exe(@script, options: @method).chomp.split.last.should == "true"
|
||||
end
|
||||
end
|
13
spec/ruby/command_line/syntax_error_spec.rb
Normal file
13
spec/ruby/command_line/syntax_error_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
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.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.should include "syntax error"
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue