Class: Gem::Package::TarTestCase
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Gem::TestCase,
MiniTest::Unit::TestCase
|
|
Instance Chain:
|
|
Inherits: |
Gem::TestCase
|
Defined in: | lib/rubygems/package/tar_test_case.rb |
Overview
A test case for Gem::Package::Tar* classes
Constant Summary
::Gem::TestCase - Inherited
Class Attribute Summary
::Gem::TestCase - Inherited
.vc_windows? | Returns whether or not we're on a version of Ruby built with VC++ (or Borland) versus Cygwin, Mingw, etc. |
.win_platform? | Is this test being run on a Windows platform? |
Class Method Summary
::Gem::TestCase - Inherited
.cert_path | Returns the path to the certificate named |
.key_path | Returns the path to the key named |
.load_cert | Loads certificate named |
.load_key | Loads an RSA private key named |
.make_command | Returns the make command for the current platform. |
.process_based_port | Allows tests to use a random (but controlled) port number instead of a hardcoded one. |
.rubybin | Finds the path to the Ruby executable. |
Instance Attribute Summary
::Gem::TestCase - Inherited
#have_git? | Skips this test unless you have a git executable. |
#nmake_found? | Returns whether or not the nmake command could be found. |
#vc_windows? | Returns whether or not we're on a version of Ruby built with VC++ (or Borland) versus Cygwin, Mingw, etc. |
#win_platform? | Is this test being run on a Windows platform? |
#fetcher, #gem_repo, #uri |
::Gem::DefaultUserInteraction - Included
Instance Method Summary
- ASCIIZ(str, length)
- #assert_headers_equal(expected, actual)
- #calc_checksum(header)
- #header(type, fname, dname, length, mode, mtime, checksum = nil, linkname = "")
- SP(s)
- SP_Z(s)
- #tar_dir_header(name, prefix, mode, mtime)
- #tar_file_header(fname, dname, mode, length, mtime)
- #tar_symlink_header(fname, prefix, mode, mtime, linkname)
- #to_oct(n, pad_size)
- #util_dir_entry
- #util_entry(tar)
- #util_symlink_entry
- Z(s)
::Gem::TestCase - Inherited
#add_to_fetcher | |
#all_spec_names, #assert_activate, #assert_contains_make_command, | |
#assert_path_exists | TODO: move to minitest. |
#build_rake_in | Allows the proper version of |
#common_installer_setup, #common_installer_teardown, | |
#create_tmpdir | creates a temporary directory with hax TODO: deprecate and remove. |
#dep | Construct a new ::Gem::Dependency. |
#dependency_request | Constructs a ::Gem::Resolver::DependencyRequest from a ::Gem::Dependency |
#enable_shared | Sets the ENABLE_SHARED entry in |
#git_gem | A git_gem is used with a gem dependencies file. |
#install_default_gems | Installs the provided default specs including writing the spec file. |
#install_default_specs | Install the provided default specs. |
#install_gem | Builds and installs the ::Gem::Specification #spec |
#install_gem_user | Builds and installs the ::Gem::Specification #spec into the user dir. |
#install_specs | Install the provided specs. |
#loaded_spec_names, | |
#make_command | Returns the make command for the current platform. |
#mu_pp | Enables pretty-print for all tests. |
#new_default_spec, #parse_make_command_line, | |
#process_based_port | See |
#quick_gem | Creates a ::Gem::Specification with a minimum of extra work. |
#read_binary | Reads a binary file at Gem.path |
#read_cache | Reads a Marshal file at Gem.path |
#refute_path_exists | TODO: move to minitest. |
#req | Constructs a new ::Gem::Requirement. |
#save_gemspec | create_gemspec creates gem specification in given |
#save_loaded_features, #scan_make_command_lines, | |
#setup |
|
#spec | Constructs a new ::Gem::Specification. |
#spec_fetcher | Creates a ::Gem::SpecFetcher pre-filled with the gems or specs defined in the block. |
#teardown |
|
#uninstall_gem | Uninstalls the ::Gem::Specification #spec |
#unresolved_names, | |
#util_build_gem | Builds a gem from #spec and places it in |
#util_clear_gems | Removes all installed gems from @gemhome. |
#util_gem | Creates a gem with |
#util_gzip | Gzips |
#util_make_gems | Creates several default gems which all have a lib/code.rb file. |
#util_remove_gem, #util_restore_RUBY_VERSION, | |
#util_set_arch | Set the platform to |
#util_set_RUBY_VERSION, | |
#util_setup_fake_fetcher | Sets up a fake fetcher using the gems from |
#util_setup_spec_fetcher | Sets up ::Gem::SpecFetcher to return information from the gems in |
#util_spec | Creates a spec with |
#util_zip | Deflates |
#v | Construct a new ::Gem::Version. |
#vendor_gem | A vendor_gem is used with a gem dependencies file. |
#wait_for_child_process_to_exit | In case we're building docs in a background process, this method waits for that process to exit (or if it's already been reaped, or never happened, swallows the |
#write_file | Writes a binary file to Gem.path which is relative to @gemhome. |
#in_path?, | |
#new_spec | new_spec is deprecated as it is never used. |
#quick_spec | TODO: remove in RubyGems 3.0. |
::Gem::DefaultUserInteraction - Included
::Gem::Text - Included
#clean_text | Remove any non-printable characters and make the text suitable for printing. |
#format_text | Wraps |
#levenshtein_distance | This code is based directly on the ::Gem::Text gem implementation Returns a value representing the “cost” of transforming str1 into str2. |
#truncate_text, #min3 |
Instance Method Details
ASCIIZ(str, length)
[ GitHub ]# File 'lib/rubygems/package/tar_test_case.rb', line 10
def ASCIIZ(str, length) str + "\0" * (length - str.length) end
#assert_headers_equal(expected, actual)
[ GitHub ]# File 'lib/rubygems/package/tar_test_case.rb', line 26
def assert_headers_equal(expected, actual) expected = expected.to_s unless String === expected actual = actual.to_s unless String === actual fields = %w[ name 100 mode 8 uid 8 gid 8 size 12 mtime 12 checksum 8 typeflag 1 linkname 100 magic 6 version 2 uname 32 gname 32 devmajor 8 devminor 8 prefix 155 ] offset = 0 until fields.empty? do name = fields.shift length = fields.shift.to_i if name == "checksum" then chksum_off = offset offset += length next end assert_equal expected[offset, length], actual[offset, length], "Field #{name} of the tar header differs." offset += length end assert_equal expected[chksum_off, 8], actual[chksum_off, 8] end
#calc_checksum(header)
[ GitHub ]#header(type, fname, dname, length, mode, mtime, checksum = nil, linkname = "")
[ GitHub ]# File 'lib/rubygems/package/tar_test_case.rb', line 75
def header(type, fname, dname, length, mode, mtime, checksum = nil, linkname = "") checksum ||= " " * 8 arr = [ # struct tarfile_entry_posix ASCIIZ(fname, 100), # char name[100]; ASCII + (Z unless filled) Z(to_oct(mode, 7)), # char mode[8]; 0 padded, octal null Z(to_oct(0, 7)), # char uid[8]; ditto Z(to_oct(0, 7)), # char gid[8]; ditto Z(to_oct(length, 11)), # char size[12]; 0 padded, octal, null Z(to_oct(mtime, 11)), # char mtime[12]; 0 padded, octal, null checksum, # char checksum[8]; 0 padded, octal, null, space type, # char typeflag[1]; file: "0" dir: "5" ASCIIZ(linkname, 100), # char linkname[100]; ASCII + (Z unless filled) "ustar\0", # char magic[6]; "ustar\0" "00", # char version[2]; "00" ASCIIZ("wheel", 32), # char uname[32]; ASCIIZ ASCIIZ("wheel", 32), # char gname[32]; ASCIIZ Z(to_oct(0, 7)), # char devmajor[8]; 0 padded, octal, null Z(to_oct(0, 7)), # char devminor[8]; 0 padded, octal, null ASCIIZ(dname, 155) # char prefix[155]; ASCII + (Z unless filled) ] format = "C100C8C8C8C12C12C8CC100C6C2C32C32C8C8C155" h = if RUBY_VERSION >= "1.9" then arr.join else arr = arr.join("").split(//).map{|x| x[0]} arr.pack format end ret = h + "\0" * (512 - h.size) assert_equal(512, ret.size) ret end
SP(s)
[ GitHub ]# File 'lib/rubygems/package/tar_test_case.rb', line 14
def SP(s) s + " " end
SP_Z(s)
[ GitHub ]# File 'lib/rubygems/package/tar_test_case.rb', line 18
def SP_Z(s) s + " \0" end
#tar_dir_header(name, prefix, mode, mtime)
[ GitHub ]#tar_file_header(fname, dname, mode, length, mtime)
[ GitHub ]# File 'lib/rubygems/package/tar_test_case.rb', line 115
def tar_file_header(fname, dname, mode, length, mtime) h = header("0", fname, dname, length, mode, mtime) checksum = calc_checksum(h) header("0", fname, dname, length, mode, mtime, checksum) end
#tar_symlink_header(fname, prefix, mode, mtime, linkname)
[ GitHub ]#to_oct(n, pad_size)
[ GitHub ]# File 'lib/rubygems/package/tar_test_case.rb', line 127
def to_oct(n, pad_size) "%0#{pad_size}o" % n end
#util_dir_entry
[ GitHub ]# File 'lib/rubygems/package/tar_test_case.rb', line 139
def util_dir_entry util_entry tar_dir_header("foo", "bar", 0, Time.now) end
#util_entry(tar)
[ GitHub ]#util_symlink_entry
[ GitHub ]# File 'lib/rubygems/package/tar_test_case.rb', line 143
def util_symlink_entry util_entry tar_symlink_header("foo", "bar", 0, Time.now, "link") end
Z(s)
[ GitHub ]# File 'lib/rubygems/package/tar_test_case.rb', line 22
def Z(s) s + "\0" end