mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
4ae3df42f7
This version contains the some style changes by RuboCop. *9d810be0ed
*61ea98a727
*795893dce3
*9be7858f7f
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
78 lines
2.4 KiB
Ruby
78 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
require 'rubygems/test_case'
|
|
require 'rubygems/util'
|
|
|
|
class TestGemUtil < Gem::TestCase
|
|
|
|
def test_class_popen
|
|
assert_equal "0\n", Gem::Util.popen(Gem.ruby, '-I', File.expand_path('../../../lib', __FILE__), '-e', 'p 0')
|
|
|
|
assert_raises Errno::ECHILD do
|
|
Process.wait(-1)
|
|
end
|
|
end
|
|
|
|
def test_silent_system
|
|
assert_silent do
|
|
Gem::Util.silent_system Gem.ruby, '-I', File.expand_path('../../../lib', __FILE__), '-e', 'puts "hello"; warn "hello"'
|
|
end
|
|
end
|
|
|
|
def test_traverse_parents
|
|
FileUtils.mkdir_p 'a/b/c'
|
|
|
|
enum = Gem::Util.traverse_parents 'a/b/c'
|
|
|
|
assert_equal File.join(@tempdir, 'a/b/c'), enum.next
|
|
assert_equal File.join(@tempdir, 'a/b'), enum.next
|
|
assert_equal File.join(@tempdir, 'a'), enum.next
|
|
loop { break if enum.next.nil? } # exhaust the enumerator
|
|
end
|
|
|
|
def test_traverse_parents_does_not_crash_on_permissions_error
|
|
skip 'skipped on MS Windows (chmod has no effect)' if win_platform?
|
|
|
|
FileUtils.mkdir_p 'd/e/f'
|
|
# remove 'execute' permission from "e" directory and make it
|
|
# impossible to cd into it and its children
|
|
FileUtils.chmod(0666, 'd/e')
|
|
|
|
skip 'skipped in root privilege' if Process.uid.zero?
|
|
|
|
paths = Gem::Util.traverse_parents('d/e/f').to_a
|
|
|
|
assert_equal File.join(@tempdir, 'd'), paths[0]
|
|
assert_equal @tempdir, paths[1]
|
|
assert_equal File.realpath(Dir.tmpdir), paths[2]
|
|
assert_equal File.realpath("..", Dir.tmpdir), paths[3]
|
|
ensure
|
|
# restore default permissions, allow the directory to be removed
|
|
FileUtils.chmod(0775, 'd/e') unless win_platform?
|
|
end
|
|
|
|
def test_linked_list_find
|
|
list = [1,2,3,4,5].inject(Gem::List.new(0)) do |m,o|
|
|
Gem::List.new o, m
|
|
end
|
|
assert_equal 5, list.find { |x| x == 5 }
|
|
assert_equal 4, list.find { |x| x == 4 }
|
|
end
|
|
|
|
def test_glob_files_in_dir
|
|
FileUtils.mkdir_p 'g'
|
|
FileUtils.touch File.join('g', 'h.rb')
|
|
FileUtils.touch File.join('g', 'i.rb')
|
|
|
|
expected_paths = [
|
|
File.join(@tempdir, 'g/h.rb'),
|
|
File.join(@tempdir, 'g/i.rb'),
|
|
]
|
|
|
|
files_with_absolute_base = Gem::Util.glob_files_in_dir('*.rb', File.join(@tempdir, 'g'))
|
|
assert_equal expected_paths.to_set, files_with_absolute_base.to_set
|
|
|
|
files_with_relative_base = Gem::Util.glob_files_in_dir('*.rb', 'g')
|
|
assert_equal expected_paths.to_set, files_with_relative_base.to_set
|
|
end
|
|
|
|
end
|