mkvtoolnix/tests/test.d/util.rb

55 lines
1022 B
Ruby
Raw Normal View History

2012-01-26 19:02:25 +00:00
$message_mutex = Mutex.new
def show_message message
$message_mutex.lock
puts message
$message_mutex.unlock
end
def error_and_exit text, exit_code = 2
show_message text
exit exit_code
end
2012-01-27 18:29:02 +00:00
def constantize camel_cased_word
names = camel_cased_word.split('::')
names.shift if names.empty? || names.first.empty?
constant = Object
names.each do |name|
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
end
constant
end
def file_name_to_class_name file_name
"T_" + file_name.gsub(/^test-/, "").gsub(/\.rb$/, "")
end
def class_name_to_file_name class_name
class_name.gsub(/^T_/, "test-") + ".rb"
end
2012-01-27 18:29:02 +00:00
class Array
def extract_options!
last.is_a?(::Hash) ? pop : {}
end
end
2014-03-10 19:02:51 +00:00
class String
def md5
Digest::MD5.hexdigest self
end
end
2012-01-27 18:29:02 +00:00
# install md5 handler
case RUBY_PLATFORM
when /darwin/
def md5 name
`/sbin/md5 #{name}`.chomp.gsub(/.*=\s*/, "")
end
else
def md5 name
`md5sum #{name}`.chomp.gsub(/\s+.*/, "")
end
end