Sha256: 470d48171218771957a1ed51a94615319d0bc5aaf6b58245370c145bbe4bd8b1

Contents?: true

Size: 1.6 KB

Versions: 13

Compression:

Stored size: 1.6 KB

Contents

#####################################################################
# test_is_sparse.rb
#
# Test case for the File.sparse? method. You should run this test
# via the 'rake test:is_sparse' task.
#####################################################################
require 'test-unit'
require 'ptools'

class TC_IsSparse < Test::Unit::TestCase
  def self.startup
    Dir.chdir("test") if File.exist?("test")
    @@win = File::ALT_SEPARATOR
    @@osx = RbConfig::CONFIG['host_os'] =~ /darwin|osx/i
    system("dd of=test_sparse bs=1k seek=5120 count=0 2>/dev/null") unless @@win
  end

  def setup
    @sparse_file = 'test_sparse'
    @non_sparse_file = File.expand_path(File.basename(__FILE__))
  end

  test "is_sparse basic functionality" do
    omit_if(@@win, "File.sparse? tests skipped on MS Windows")
    omit_if(@@osx, "File.sparse? tests skipped on OS X")

    assert_respond_to(File, :sparse?)
    assert_nothing_raised{ File.sparse?(@sparse_file) }
    assert_boolean(File.sparse?(@sparse_file))
  end

  test "is_sparse returns the expected results" do
    omit_if(@@win, "File.sparse? tests skipped on MS Windows")
    omit_if(@@osx, "File.sparse? tests skipped on OS X")

    assert_true(File.sparse?(@sparse_file))
    assert_false(File.sparse?(@non_sparse_file))
  end

  test "is_sparse only accepts one argument" do
    omit_if(@@win, "File.sparse? tests skipped on MS Windows")
    assert_raise(ArgumentError){ File.sparse?(@sparse_file, @sparse_file) }
  end

  def teardown
    @sparse_file = nil
    @non_sparse_file = nil
  end

  def self.shutdown
    File.delete('test_sparse') if File.exist?('test_sparse')
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ptools-1.3.7 test/test_is_sparse.rb
ptools-1.3.6 test/test_is_sparse.rb
ptools-1.3.5 test/test_is_sparse.rb
ptools-1.3.4 test/test_is_sparse.rb
ptools-1.3.3 test/test_is_sparse.rb
ptools-1.3.2 test/test_is_sparse.rb
ptools-1.3.2-universal-mingw32 test/test_is_sparse.rb
ptools-1.3.1 test/test_is_sparse.rb
ptools-1.3.0 test/test_is_sparse.rb
ptools-1.2.7 test/test_is_sparse.rb
ptools-1.2.6 test/test_is_sparse.rb
ptools-1.2.6-universal-mingw32 test/test_is_sparse.rb
ptools-1.2.5-universal-mingw32 test/test_is_sparse.rb