summaryrefslogtreecommitdiff
path: root/test/ruby/test_rubyoptions.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-20 23:03:52 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-20 23:03:52 +0000
commit8f671120f1d99b47f28d67183855d634d006389a (patch)
tree5a6a943efb8bfb690d7cf5a5f05d2aa701d114ac /test/ruby/test_rubyoptions.rb
parent65261bda4d964c081fc3a510bfaa094a7647e8bc (diff)
* test/csv/test_features.rb, test/logger/test_logger.rb
test/mkmf/test_have_macro.rb, test/net/http/test_http.rb, test/openssl/test_config.rb, test/psych/test_encoding.rb, test/psych/test_exception.rb, test/psych/test_psych.rb, test/psych/test_tainted.rb, test/readline/test_readline.rb, test/rexml/test_contrib.rb, test/ruby/test_autoload.rb, test/ruby/test_beginendblock.rb, test/ruby/test_exception.rb, test/ruby/test_file.rb, test/ruby/test_io.rb, test/ruby/test_marshal.rb, test/ruby/test_process.rb, test/ruby/test_require.rb, test/ruby/test_rubyoptions.rb, test/syslog/test_syslog_logger.rb, test/webrick/test_httpauth.rb, test/zlib/test_zlib.rb: Use Tempfile.create. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_rubyoptions.rb')
-rw-r--r--test/ruby/test_rubyoptions.rb193
1 files changed, 95 insertions, 98 deletions
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index cd100de3bd..fbc18f3ef0 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -271,20 +271,21 @@ class TestRubyOptions < Test::Unit::TestCase
rubypath_orig = ENV['RUBYPATH']
path_orig = ENV['PATH']
- t = Tempfile.new(["test_ruby_test_rubyoption", ".rb"])
- t.puts "p 1"
- t.close
+ Tempfile.create(["test_ruby_test_rubyoption", ".rb"]) {|t|
+ t.puts "p 1"
+ t.close
- @verbose = $VERBOSE
- $VERBOSE = nil
+ @verbose = $VERBOSE
+ $VERBOSE = nil
- ENV['PATH'] = File.dirname(t.path)
+ ENV['PATH'] = File.dirname(t.path)
- assert_in_out_err(%w(-S) + [File.basename(t.path)], "", %w(1), [])
+ assert_in_out_err(%w(-S) + [File.basename(t.path)], "", %w(1), [])
- ENV['RUBYPATH'] = File.dirname(t.path)
+ ENV['RUBYPATH'] = File.dirname(t.path)
- assert_in_out_err(%w(-S) + [File.basename(t.path)], "", %w(1), [])
+ assert_in_out_err(%w(-S) + [File.basename(t.path)], "", %w(1), [])
+ }
ensure
if rubypath_orig
@@ -297,7 +298,6 @@ class TestRubyOptions < Test::Unit::TestCase
else
ENV.delete('PATH')
end
- t.close(true) if t
$VERBOSE = @verbose
end
@@ -333,81 +333,79 @@ class TestRubyOptions < Test::Unit::TestCase
end
def test_assignment_in_conditional
- t = Tempfile.new(["test_ruby_test_rubyoption", ".rb"])
- t.puts "if a = 1"
- t.puts "end"
- t.puts "0.times do"
- t.puts " if b = 2"
- t.puts " a += b"
- t.puts " end"
- t.puts "end"
- t.close
- warning = ' warning: found = in conditional, should be =='
- err = ["#{t.path}:1:#{warning}",
- "#{t.path}:4:#{warning}",
- ]
- bug2136 = '[ruby-dev:39363]'
- assert_in_out_err(["-w", t.path], "", [], err, bug2136)
- assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err, bug2136)
-
- t.open
- t.truncate(0)
- t.puts "if a = ''; end"
- t.puts "if a = []; end"
- t.puts "if a = [1]; end"
- t.puts "if a = [a]; end"
- t.puts "if a = {}; end"
- t.puts "if a = {1=>2}; end"
- t.puts "if a = {3=>a}; end"
- t.close
- err = ["#{t.path}:1:#{warning}",
- "#{t.path}:2:#{warning}",
- "#{t.path}:3:#{warning}",
- "#{t.path}:5:#{warning}",
- "#{t.path}:6:#{warning}",
- ]
- feature4299 = '[ruby-dev:43083]'
- assert_in_out_err(["-w", t.path], "", [], err, feature4299)
- assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err, feature4299)
- ensure
- t.close(true) if t
+ Tempfile.create(["test_ruby_test_rubyoption", ".rb"]) {|t|
+ t.puts "if a = 1"
+ t.puts "end"
+ t.puts "0.times do"
+ t.puts " if b = 2"
+ t.puts " a += b"
+ t.puts " end"
+ t.puts "end"
+ t.flush
+ warning = ' warning: found = in conditional, should be =='
+ err = ["#{t.path}:1:#{warning}",
+ "#{t.path}:4:#{warning}",
+ ]
+ bug2136 = '[ruby-dev:39363]'
+ assert_in_out_err(["-w", t.path], "", [], err, bug2136)
+ assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err, bug2136)
+
+ t.rewind
+ t.truncate(0)
+ t.puts "if a = ''; end"
+ t.puts "if a = []; end"
+ t.puts "if a = [1]; end"
+ t.puts "if a = [a]; end"
+ t.puts "if a = {}; end"
+ t.puts "if a = {1=>2}; end"
+ t.puts "if a = {3=>a}; end"
+ t.flush
+ err = ["#{t.path}:1:#{warning}",
+ "#{t.path}:2:#{warning}",
+ "#{t.path}:3:#{warning}",
+ "#{t.path}:5:#{warning}",
+ "#{t.path}:6:#{warning}",
+ ]
+ feature4299 = '[ruby-dev:43083]'
+ assert_in_out_err(["-w", t.path], "", [], err, feature4299)
+ assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err, feature4299)
+ }
end
def test_indentation_check
- t = Tempfile.new(["test_ruby_test_rubyoption", ".rb"])
- t.puts "begin"
- t.puts " end"
- t.close
- err = ["#{t.path}:2: warning: mismatched indentations at 'end' with 'begin' at 1"]
- assert_in_out_err(["-w", t.path], "", [], err)
- assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err)
-
- t.open
- t.puts "# -*- warn-indent: false -*-"
- t.puts "begin"
- t.puts " end"
- t.close
- assert_in_out_err(["-w", t.path], "", [], [], '[ruby-core:25442]')
-
- err = ["#{t.path}:4: warning: mismatched indentations at 'end' with 'begin' at 3"]
- t.open
- t.puts "# -*- warn-indent: false -*-"
- t.puts "# -*- warn-indent: true -*-"
- t.puts "begin"
- t.puts " end"
- t.close
- assert_in_out_err(["-w", t.path], "", [], err, '[ruby-core:25442]')
-
- err = ["#{t.path}:4: warning: mismatched indentations at 'end' with 'begin' at 2"]
- t.open
- t.puts "# -*- warn-indent: true -*-"
- t.puts "begin"
- t.puts "# -*- warn-indent: false -*-"
- t.puts " end"
- t.close
- assert_in_out_err(["-w", t.path], "", [], [], '[ruby-core:25442]')
- ensure
- t.close(true) if t
+ Tempfile.create(["test_ruby_test_rubyoption", ".rb"]) {|t|
+ t.puts "begin"
+ t.puts " end"
+ t.flush
+ err = ["#{t.path}:2: warning: mismatched indentations at 'end' with 'begin' at 1"]
+ assert_in_out_err(["-w", t.path], "", [], err)
+ assert_in_out_err(["-wr", t.path, "-e", ""], "", [], err)
+
+ t.rewind
+ t.puts "# -*- warn-indent: false -*-"
+ t.puts "begin"
+ t.puts " end"
+ t.flush
+ assert_in_out_err(["-w", t.path], "", [], [], '[ruby-core:25442]')
+
+ err = ["#{t.path}:4: warning: mismatched indentations at 'end' with 'begin' at 3"]
+ t.rewind
+ t.puts "# -*- warn-indent: false -*-"
+ t.puts "# -*- warn-indent: true -*-"
+ t.puts "begin"
+ t.puts " end"
+ t.flush
+ assert_in_out_err(["-w", t.path], "", [], err, '[ruby-core:25442]')
+
+ err = ["#{t.path}:4: warning: mismatched indentations at 'end' with 'begin' at 2"]
+ t.rewind
+ t.puts "# -*- warn-indent: true -*-"
+ t.puts "begin"
+ t.puts "# -*- warn-indent: false -*-"
+ t.puts " end"
+ t.flush
+ assert_in_out_err(["-w", t.path], "", [], [], '[ruby-core:25442]')
+ }
end
def test_notfound
@@ -523,25 +521,24 @@ class TestRubyOptions < Test::Unit::TestCase
assert_not_predicate(status, :success?, "segv but success #{bug7402}")
bug7597 = '[ruby-dev:46786]'
- t = Tempfile.new(["test_ruby_test_bug7597", ".rb"])
- t.write "f" * 100
- t.flush
- assert_in_out_err(["-e", "$0=ARGV[0]; Process.kill :SEGV, $$", t.path],
- "", [], expected_stderr, bug7597, opts)
- t.close(true)
+ Tempfile.create(["test_ruby_test_bug7597", ".rb"]) {|t|
+ t.write "f" * 100
+ t.flush
+ assert_in_out_err(["-e", "$0=ARGV[0]; Process.kill :SEGV, $$", t.path],
+ "", [], expected_stderr, bug7597, opts)
+ }
end
def test_DATA
- t = Tempfile.new(["test_ruby_test_rubyoption", ".rb"])
- t.puts "puts DATA.read.inspect"
- t.puts "__END__"
- t.puts "foo"
- t.puts "bar"
- t.puts "baz"
- t.close
- assert_in_out_err([t.path], "", %w("foo\\nbar\\nbaz\\n"), [])
- ensure
- t.close(true) if t
+ Tempfile.create(["test_ruby_test_rubyoption", ".rb"]) {|t|
+ t.puts "puts DATA.read.inspect"
+ t.puts "__END__"
+ t.puts "foo"
+ t.puts "bar"
+ t.puts "baz"
+ t.flush
+ assert_in_out_err([t.path], "", %w("foo\\nbar\\nbaz\\n"), [])
+ }
end
def test_unused_variable