mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	refine previous change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
		
							parent
							
								
									a9c2a18cc7
								
							
						
					
					
						commit
						4dc8ff965b
					
				
					 4 changed files with 105 additions and 99 deletions
				
			
		| 
						 | 
				
			
			@ -15,7 +15,8 @@ class TestSystem < Test::Unit::TestCase
 | 
			
		|||
    assert_equal("foobar\n", `echo foobar`)
 | 
			
		||||
    assert_equal('foobar', `#{ruby} -e 'print "foobar"'`)
 | 
			
		||||
 | 
			
		||||
    tmpfilename = "#{Dir.tmpdir}/ruby_script_tmp.#{$$}"
 | 
			
		||||
    Dir.mktmpdir("ruby_script_tmp") {|tmpdir|
 | 
			
		||||
      tmpfilename = "#{tmpdir}/ruby_script_tmp.#{$$}"
 | 
			
		||||
 | 
			
		||||
      tmp = open(tmpfilename, "w")
 | 
			
		||||
      tmp.print "print $zzz\n";
 | 
			
		||||
| 
						 | 
				
			
			@ -57,6 +58,7 @@ class TestSystem < Test::Unit::TestCase
 | 
			
		|||
 | 
			
		||||
      File.unlink tmpfilename or `/bin/rm -f "#{tmpfilename}"`
 | 
			
		||||
      File.unlink "#{tmpfilename}.bak" or `/bin/rm -f "#{tmpfilename}.bak"`
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_syntax
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,8 @@ require 'tmpdir'
 | 
			
		|||
 | 
			
		||||
class TestWhileuntil < Test::Unit::TestCase
 | 
			
		||||
  def test_while
 | 
			
		||||
    tmpfilename = "#{Dir.tmpdir}/ruby_while_tmp.#{$$}"
 | 
			
		||||
    Dir.mktmpdir("ruby_while_tmp") {|tmpdir|
 | 
			
		||||
      tmpfilename = "#{tmpdir}/ruby_while_tmp.#{$$}"
 | 
			
		||||
 | 
			
		||||
      tmp = open(tmpfilename, "w")
 | 
			
		||||
      tmp.print "tvi925\n";
 | 
			
		||||
| 
						 | 
				
			
			@ -68,6 +69,7 @@ class TestWhileuntil < Test::Unit::TestCase
 | 
			
		|||
 | 
			
		||||
      File.unlink tmpfilename or `/bin/rm -f "#{tmpfilename}"`
 | 
			
		||||
      assert(!File.exist?(tmpfilename))
 | 
			
		||||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_until
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -297,7 +297,7 @@ class TestIOScanf
 | 
			
		|||
  include Scanf
 | 
			
		||||
  extend ScanfTests
 | 
			
		||||
 | 
			
		||||
  tmpfilename = "#{Dir.tmpdir}/iotest.dat"
 | 
			
		||||
  tmpfilename = "#{Dir.tmpdir}/iotest.dat.#{$$}"
 | 
			
		||||
  
 | 
			
		||||
  i = 1
 | 
			
		||||
  self.tests.each do |test|
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -50,8 +50,9 @@ alias set_up setup
 | 
			
		|||
  end
 | 
			
		||||
 | 
			
		||||
  def test_io1
 | 
			
		||||
    File.open("#{Dir.tmpdir}/iotest.dat", "w") { |fh| fh.puts(@str) }
 | 
			
		||||
    fh = File.open("#{Dir.tmpdir}/iotest.dat", "rb")
 | 
			
		||||
    fn = "#{Dir.tmpdir}/iotest.dat.#{$$}"
 | 
			
		||||
    File.open(fn, "w") { |fh| fh.puts(@str) }
 | 
			
		||||
    fh = File.open(fn, "rb")
 | 
			
		||||
    res = fh.scanf("%s%d") { |name, year| "#{name} was born in #{year}." }
 | 
			
		||||
 | 
			
		||||
    assert_equal(
 | 
			
		||||
| 
						 | 
				
			
			@ -62,18 +63,19 @@ alias set_up setup
 | 
			
		|||
      "Brahms was born in 1833." ],res)
 | 
			
		||||
    fh.close
 | 
			
		||||
  ensure
 | 
			
		||||
    File.delete("#{Dir.tmpdir}/iotest.dat")  
 | 
			
		||||
    File.delete(fn)  
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_io2
 | 
			
		||||
    File.open("#{Dir.tmpdir}/iotest.dat", "w").close
 | 
			
		||||
    fh = File.open("#{Dir.tmpdir}/iotest.dat","rb")
 | 
			
		||||
    fn = "#{Dir.tmpdir}/iotest.dat.#{$$}"
 | 
			
		||||
    File.open(fn, "w").close
 | 
			
		||||
    fh = File.open(fn,"rb")
 | 
			
		||||
    assert_equal(fh.scanf("") {}, [])
 | 
			
		||||
    fh.seek(0)
 | 
			
		||||
    assert_equal(fh.scanf("%d%f%s") {}, [])
 | 
			
		||||
    fh.close
 | 
			
		||||
  ensure
 | 
			
		||||
    File.delete("#{Dir.tmpdir}/iotest.dat")  
 | 
			
		||||
    File.delete(fn)  
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue