1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59092 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-06-15 12:48:26 +00:00
parent bd8412b74f
commit 5ccf36c7ec
41 changed files with 547 additions and 650 deletions

View file

@ -22,7 +22,6 @@ class MSpecCI < MSpecScript
options.chdir
options.prefix
options.configure { |f| load f }
options.name
options.pretend
options.interrupt

View file

@ -32,7 +32,6 @@ class MSpecRun < MSpecScript
options.chdir
options.prefix
options.configure { |f| load f }
options.name
options.randomize
options.repeat
options.pretend

View file

@ -30,7 +30,6 @@ class MSpecTag < MSpecScript
options.doc "\n How to modify the execution"
options.configure { |f| load f }
options.name
options.pretend
options.unguarded
options.interrupt

View file

@ -1,4 +1,3 @@
require 'mspec/utils/ruby_name'
require 'mspec/guards/block_device'
require 'mspec/guards/bug'
require 'mspec/guards/conflict'

View file

@ -11,8 +11,6 @@ class BlockDeviceGuard < SpecGuard
end
end
class Object
def with_block_device(&block)
BlockDeviceGuard.new.run_if(:with_block_device, &block)
end
def with_block_device(&block)
BlockDeviceGuard.new.run_if(:with_block_device, &block)
end

View file

@ -23,8 +23,6 @@ class BugGuard < VersionGuard
end
end
class Object
def ruby_bug(bug, version, &block)
BugGuard.new(bug, version).run_unless(:ruby_bug, &block)
end
def ruby_bug(bug, version, &block)
BugGuard.new(bug, version).run_unless(:ruby_bug, &block)
end

View file

@ -8,12 +8,10 @@ class ConflictsGuard < SpecGuard
end
end
class Object
# In some cases, libraries will modify another Ruby method's
# behavior. The specs for the method's behavior will then fail
# if that library is loaded. This guard will not run if any of
# the specified constants exist in Object.constants.
def conflicts_with(*modules, &block)
ConflictsGuard.new(*modules).run_unless(:conflicts_with, &block)
end
# In some cases, libraries will modify another Ruby method's
# behavior. The specs for the method's behavior will then fail
# if that library is loaded. This guard will not run if any of
# the specified constants exist in Object.constants.
def conflicts_with(*modules, &block)
ConflictsGuard.new(*modules).run_unless(:conflicts_with, &block)
end

View file

@ -16,12 +16,10 @@ class BigEndianGuard < EndianGuard
end
end
class Object
def big_endian(&block)
BigEndianGuard.new.run_if(:big_endian, &block)
end
def little_endian(&block)
BigEndianGuard.new.run_unless(:little_endian, &block)
end
def big_endian(&block)
BigEndianGuard.new.run_if(:big_endian, &block)
end
def little_endian(&block)
BigEndianGuard.new.run_unless(:little_endian, &block)
end

View file

@ -10,34 +10,32 @@ class FeatureGuard < SpecGuard
end
end
class Object
# Provides better documentation in the specs by
# naming sets of features that work together as
# a whole. Examples include :encoding, :fiber,
# :continuation, :fork.
#
# Usage example:
#
# with_feature :encoding do
# # specs for a method that provides aspects
# # of the encoding feature
# end
#
# Multiple features must all be enabled for the
# guard to run:
#
# with_feature :one, :two do
# # these specs will run if features :one AND
# # :two are enabled.
# end
#
# The implementation must explicitly enable a feature
# by adding code like the following to the .mspec
# configuration file:
#
# MSpec.enable_feature :encoding
#
def with_feature(*features, &block)
FeatureGuard.new(*features).run_if(:with_feature, &block)
end
# Provides better documentation in the specs by
# naming sets of features that work together as
# a whole. Examples include :encoding, :fiber,
# :continuation, :fork.
#
# Usage example:
#
# with_feature :encoding do
# # specs for a method that provides aspects
# # of the encoding feature
# end
#
# Multiple features must all be enabled for the
# guard to run:
#
# with_feature :one, :two do
# # these specs will run if features :one AND
# # :two are enabled.
# end
#
# The implementation must explicitly enable a feature
# by adding code like the following to the .mspec
# configuration file:
#
# MSpec.enable_feature :encoding
#
def with_feature(*features, &block)
FeatureGuard.new(*features).run_if(:with_feature, &block)
end

View file

@ -1,6 +1,5 @@
require 'mspec/runner/mspec'
require 'mspec/runner/actions/tally'
require 'mspec/utils/ruby_name'
class SpecGuard
def self.report

View file

@ -5,9 +5,9 @@ class PlatformGuard < SpecGuard
args.any? do |name|
case name
when :rubinius
RUBY_NAME.start_with?('rbx')
RUBY_ENGINE.start_with?('rbx')
when :ruby, :jruby, :truffleruby, :ironruby, :macruby, :maglev, :topaz, :opal
RUBY_NAME.start_with?(name.to_s)
RUBY_ENGINE.start_with?(name.to_s)
else
raise "unknown implementation #{name}"
end
@ -67,12 +67,10 @@ class PlatformGuard < SpecGuard
end
end
class Object
def platform_is(*args, &block)
PlatformGuard.new(*args).run_if(:platform_is, &block)
end
def platform_is_not(*args, &block)
PlatformGuard.new(*args).run_unless(:platform_is_not, &block)
end
def platform_is(*args, &block)
PlatformGuard.new(*args).run_if(:platform_is, &block)
end
def platform_is_not(*args, &block)
PlatformGuard.new(*args).run_unless(:platform_is_not, &block)
end

View file

@ -6,8 +6,6 @@ class QuarantineGuard < SpecGuard
end
end
class Object
def quarantine!(&block)
QuarantineGuard.new.run_unless(:quarantine!, &block)
end
def quarantine!(&block)
QuarantineGuard.new.run_unless(:quarantine!, &block)
end

View file

@ -6,12 +6,10 @@ class SuperUserGuard < SpecGuard
end
end
class Object
def as_superuser(&block)
SuperUserGuard.new.run_if(:as_superuser, &block)
end
def as_user(&block)
SuperUserGuard.new.run_unless(:as_user, &block)
end
def as_superuser(&block)
SuperUserGuard.new.run_if(:as_superuser, &block)
end
def as_user(&block)
SuperUserGuard.new.run_unless(:as_user, &block)
end

View file

@ -9,8 +9,6 @@ class SupportedGuard < SpecGuard
end
end
class Object
def not_supported_on(*args, &block)
SupportedGuard.new(*args).run_unless(:not_supported_on, &block)
end
def not_supported_on(*args, &block)
SupportedGuard.new(*args).run_unless(:not_supported_on, &block)
end

View file

@ -32,8 +32,6 @@ class VersionGuard < SpecGuard
end
end
class Object
def ruby_version_is(*args, &block)
VersionGuard.new(*args).run_if(:ruby_version_is, &block)
end
def ruby_version_is(*args, &block)
VersionGuard.new(*args).run_if(:ruby_version_is, &block)
end

View file

@ -1,37 +1,35 @@
class Object
# Convenience helper for specs using ARGF.
# Set @argf to an instance of ARGF.class with the given +argv+.
# That instance must be used instead of ARGF as ARGF is global
# and it is not always possible to reset its state correctly.
#
# The helper yields to the block and then close
# the files open by the instance. Example:
#
# describe "That" do
# it "does something" do
# argf ['a', 'b'] do
# # do something
# end
# end
# end
def argf(argv)
if argv.empty? or argv.length > 2
raise "Only 1 or 2 filenames are allowed for the argf helper so files can be properly closed: #{argv.inspect}"
end
@argf ||= nil
raise "Cannot nest calls to the argf helper" if @argf
# Convenience helper for specs using ARGF.
# Set @argf to an instance of ARGF.class with the given +argv+.
# That instance must be used instead of ARGF as ARGF is global
# and it is not always possible to reset its state correctly.
#
# The helper yields to the block and then close
# the files open by the instance. Example:
#
# describe "That" do
# it "does something" do
# argf ['a', 'b'] do
# # do something
# end
# end
# end
def argf(argv)
if argv.empty? or argv.length > 2
raise "Only 1 or 2 filenames are allowed for the argf helper so files can be properly closed: #{argv.inspect}"
end
@argf ||= nil
raise "Cannot nest calls to the argf helper" if @argf
@argf = ARGF.class.new(*argv)
@__mspec_saved_argf_file__ = @argf.file
begin
yield
ensure
file1 = @__mspec_saved_argf_file__
file2 = @argf.file # Either the first file or the second
file1.close if !file1.closed? and file1 != STDIN
file2.close if !file2.closed? and file2 != STDIN
@argf = nil
@__mspec_saved_argf_file__ = nil
end
@argf = ARGF.class.new(*argv)
@__mspec_saved_argf_file__ = @argf.file
begin
yield
ensure
file1 = @__mspec_saved_argf_file__
file2 = @argf.file # Either the first file or the second
file1.close if !file1.closed? and file1 != STDIN
file2.close if !file2.closed? and file2 != STDIN
@argf = nil
@__mspec_saved_argf_file__ = nil
end
end

View file

@ -1,45 +1,43 @@
class Object
# Convenience helper for altering ARGV. Saves the
# value of ARGV and sets it to +args+. If a block
# is given, yields to the block and then restores
# the value of ARGV. The previously saved value of
# ARGV can be restored by passing +:restore+. The
# former is useful in a single spec. The latter is
# useful in before/after actions. For example:
#
# describe "This" do
# before do
# argv ['a', 'b']
# end
#
# after do
# argv :restore
# end
#
# it "does something" do
# # do something
# end
# end
#
# describe "That" do
# it "does something" do
# argv ['a', 'b'] do
# # do something
# end
# end
# end
def argv(args)
if args == :restore
ARGV.replace(@__mspec_saved_argv__ || [])
else
@__mspec_saved_argv__ = ARGV.dup
ARGV.replace args
if block_given?
begin
yield
ensure
argv :restore
end
# Convenience helper for altering ARGV. Saves the
# value of ARGV and sets it to +args+. If a block
# is given, yields to the block and then restores
# the value of ARGV. The previously saved value of
# ARGV can be restored by passing +:restore+. The
# former is useful in a single spec. The latter is
# useful in before/after actions. For example:
#
# describe "This" do
# before do
# argv ['a', 'b']
# end
#
# after do
# argv :restore
# end
#
# it "does something" do
# # do something
# end
# end
#
# describe "That" do
# it "does something" do
# argv ['a', 'b'] do
# # do something
# end
# end
# end
def argv(args)
if args == :restore
ARGV.replace(@__mspec_saved_argv__ || [])
else
@__mspec_saved_argv__ = ARGV.dup
ARGV.replace args
if block_given?
begin
yield
ensure
argv :restore
end
end
end

View file

@ -1,51 +1,47 @@
class Object
# The new_datetime helper makes writing DateTime specs more simple by
# providing default constructor values and accepting a Hash of only the
# constructor values needed for the particular spec. For example:
#
# new_datetime :hour => 1, :minute => 20
#
# Possible keys are:
# :year, :month, :day, :hour, :minute, :second, :offset and :sg.
# The new_datetime helper makes writing DateTime specs more simple by
# providing default constructor values and accepting a Hash of only the
# constructor values needed for the particular spec. For example:
#
# new_datetime :hour => 1, :minute => 20
#
# Possible keys are:
# :year, :month, :day, :hour, :minute, :second, :offset and :sg.
def new_datetime(opts={})
require 'date'
def new_datetime(opts={})
require 'date'
value = {
:year => -4712,
:month => 1,
:day => 1,
:hour => 0,
:minute => 0,
:second => 0,
:offset => 0,
:sg => Date::ITALY
}.merge opts
DateTime.new value[:year], value[:month], value[:day], value[:hour],
value[:minute], value[:second], value[:offset], value[:sg]
end
def with_timezone(name, offset = nil, daylight_saving_zone = "")
zone = name.dup
if offset
# TZ convention is backwards
offset = -offset
zone += offset.to_s
zone += ":00:00"
end
zone += daylight_saving_zone
old = ENV["TZ"]
ENV["TZ"] = zone
begin
yield
ensure
ENV["TZ"] = old
end
end
value = {
:year => -4712,
:month => 1,
:day => 1,
:hour => 0,
:minute => 0,
:second => 0,
:offset => 0,
:sg => Date::ITALY
}.merge opts
DateTime.new value[:year], value[:month], value[:day], value[:hour],
value[:minute], value[:second], value[:offset], value[:sg]
end
def with_timezone(name, offset = nil, daylight_saving_zone = "")
zone = name.dup
if offset
# TZ convention is backwards
offset = -offset
zone += offset.to_s
zone += ":00:00"
end
zone += daylight_saving_zone
old = ENV["TZ"]
ENV["TZ"] = zone
begin
yield
ensure
ENV["TZ"] = old
end
end

View file

@ -1,26 +1,24 @@
class Object
# Returns the name of a fixture file by adjoining the directory
# of the +file+ argument with "fixtures" and the contents of the
# +args+ array. For example,
#
# +file+ == "some/example_spec.rb"
#
# and
#
# +args+ == ["subdir", "file.txt"]
#
# then the result is the expanded path of
#
# "some/fixtures/subdir/file.txt".
def fixture(file, *args)
path = File.dirname(file)
path = path[0..-7] if path[-7..-1] == "/shared"
fixtures = path[-9..-1] == "/fixtures" ? "" : "fixtures"
if File.respond_to?(:realpath)
path = File.realpath(path)
else
path = File.expand_path(path)
end
File.join(path, fixtures, args)
# Returns the name of a fixture file by adjoining the directory
# of the +file+ argument with "fixtures" and the contents of the
# +args+ array. For example,
#
# +file+ == "some/example_spec.rb"
#
# and
#
# +args+ == ["subdir", "file.txt"]
#
# then the result is the expanded path of
#
# "some/fixtures/subdir/file.txt".
def fixture(file, *args)
path = File.dirname(file)
path = path[0..-7] if path[-7..-1] == "/shared"
fixtures = path[-9..-1] == "/fixtures" ? "" : "fixtures"
if File.respond_to?(:realpath)
path = File.realpath(path)
else
path = File.expand_path(path)
end
File.join(path, fixtures, args)
end

View file

@ -1,5 +1,3 @@
class Object
def flunk(msg="This example is a failure")
SpecExpectation.fail_with "Failed:", msg
end
def flunk(msg="This example is a failure")
SpecExpectation.fail_with "Failed:", msg
end

View file

@ -1,72 +1,70 @@
class Object
# Copies a file
def cp(source, dest)
File.open(dest, "wb") do |d|
File.open(source, "rb") do |s|
while data = s.read(1024)
d.write data
end
# Copies a file
def cp(source, dest)
File.open(dest, "wb") do |d|
File.open(source, "rb") do |s|
while data = s.read(1024)
d.write data
end
end
end
# Creates each directory in path that does not exist.
def mkdir_p(path)
parts = File.expand_path(path).split %r[/|\\]
name = parts.shift
parts.each do |part|
name = File.join name, part
if File.file? name
raise ArgumentError, "path component of #{path} is a file"
end
unless File.directory? name
begin
Dir.mkdir name
rescue Errno::EEXIST => e
if File.directory? name
# OK, another process/thread created the same directory
else
raise e
end
end
end
end
end
# Recursively removes all files and directories in +path+
# if +path+ is a directory. Removes the file if +path+ is
# a file.
def rm_r(*paths)
paths.each do |path|
path = File.expand_path path
prefix = SPEC_TEMP_DIR
unless path[0, prefix.size] == prefix
raise ArgumentError, "#{path} is not prefixed by #{prefix}"
end
# File.symlink? needs to be checked first as
# File.exist? returns false for dangling symlinks
if File.symlink? path
File.unlink path
elsif File.directory? path
Dir.entries(path).each { |x| rm_r "#{path}/#{x}" unless x =~ /^\.\.?$/ }
Dir.rmdir path
elsif File.exist? path
File.delete path
end
end
end
# Creates a file +name+. Creates the directory for +name+
# if it does not exist.
def touch(name, mode="w")
mkdir_p File.dirname(name)
File.open(name, mode) do |f|
yield f if block_given?
end
end
end
# Creates each directory in path that does not exist.
def mkdir_p(path)
parts = File.expand_path(path).split %r[/|\\]
name = parts.shift
parts.each do |part|
name = File.join name, part
if File.file? name
raise ArgumentError, "path component of #{path} is a file"
end
unless File.directory? name
begin
Dir.mkdir name
rescue Errno::EEXIST => e
if File.directory? name
# OK, another process/thread created the same directory
else
raise e
end
end
end
end
end
# Recursively removes all files and directories in +path+
# if +path+ is a directory. Removes the file if +path+ is
# a file.
def rm_r(*paths)
paths.each do |path|
path = File.expand_path path
prefix = SPEC_TEMP_DIR
unless path[0, prefix.size] == prefix
raise ArgumentError, "#{path} is not prefixed by #{prefix}"
end
# File.symlink? needs to be checked first as
# File.exist? returns false for dangling symlinks
if File.symlink? path
File.unlink path
elsif File.directory? path
Dir.entries(path).each { |x| rm_r "#{path}/#{x}" unless x =~ /^\.\.?$/ }
Dir.rmdir path
elsif File.exist? path
File.delete path
end
end
end
# Creates a file +name+. Creates the directory for +name+
# if it does not exist.
def touch(name, mode="w")
mkdir_p File.dirname(name)
File.open(name, mode) do |f|
yield f if block_given?
end
end

View file

@ -61,53 +61,51 @@ class IOStub
end
end
class Object
# Creates a "bare" file descriptor (i.e. one that is not associated
# with any Ruby object). The file descriptor can safely be passed
# to IO.new without creating a Ruby object alias to the fd.
def new_fd(name, mode="w:utf-8")
mode = options_or_mode(mode)
# Creates a "bare" file descriptor (i.e. one that is not associated
# with any Ruby object). The file descriptor can safely be passed
# to IO.new without creating a Ruby object alias to the fd.
def new_fd(name, mode="w:utf-8")
mode = options_or_mode(mode)
if mode.kind_of? Hash
if mode.key? :mode
mode = mode[:mode]
else
raise ArgumentError, "new_fd options Hash must include :mode"
end
end
IO.sysopen name, fmode(mode)
end
# Creates an IO instance for a temporary file name. The file
# must be deleted.
def new_io(name, mode="w:utf-8")
IO.new new_fd(name, options_or_mode(mode)), options_or_mode(mode)
end
# This helper simplifies passing file access modes regardless of
# whether the :encoding feature is enabled. Only the access specifier
# itself will be returned if :encoding is not enabled. Otherwise,
# the full mode string will be returned (i.e. the helper is a no-op).
def fmode(mode)
if FeatureGuard.enabled? :encoding
mode
if mode.kind_of? Hash
if mode.key? :mode
mode = mode[:mode]
else
mode.split(':').first
raise ArgumentError, "new_fd options Hash must include :mode"
end
end
# This helper simplifies passing file access modes or options regardless of
# whether the :encoding feature is enabled. Only the access specifier itself
# will be returned if :encoding is not enabled. Otherwise, the full mode
# string or option will be returned (i.e. the helper is a no-op).
def options_or_mode(oom)
return fmode(oom) if oom.kind_of? String
IO.sysopen name, fmode(mode)
end
if FeatureGuard.enabled? :encoding
oom
else
fmode(oom[:mode] || "r:utf-8")
end
# Creates an IO instance for a temporary file name. The file
# must be deleted.
def new_io(name, mode="w:utf-8")
IO.new new_fd(name, options_or_mode(mode)), options_or_mode(mode)
end
# This helper simplifies passing file access modes regardless of
# whether the :encoding feature is enabled. Only the access specifier
# itself will be returned if :encoding is not enabled. Otherwise,
# the full mode string will be returned (i.e. the helper is a no-op).
def fmode(mode)
if FeatureGuard.enabled? :encoding
mode
else
mode.split(':').first
end
end
# This helper simplifies passing file access modes or options regardless of
# whether the :encoding feature is enabled. Only the access specifier itself
# will be returned if :encoding is not enabled. Otherwise, the full mode
# string or option will be returned (i.e. the helper is a no-op).
def options_or_mode(oom)
return fmode(oom) if oom.kind_of? String
if FeatureGuard.enabled? :encoding
oom
else
fmode(oom[:mode] || "r:utf-8")
end
end

View file

@ -1,8 +1,6 @@
class Object
def mock_to_path(path)
# Cannot use our Object#mock here since it conflicts with RSpec
obj = MockObject.new('path')
obj.should_receive(:to_path).and_return(path)
obj
end
def mock_to_path(path)
# Cannot use our Object#mock here since it conflicts with RSpec
obj = MockObject.new('path')
obj.should_receive(:to_path).and_return(path)
obj
end

View file

@ -1,72 +1,70 @@
require 'mspec/guards/platform'
class Object
def nan_value
0/0.0
def nan_value
0/0.0
end
def infinity_value
1/0.0
end
def bignum_value(plus=0)
0x8000_0000_0000_0000 + plus
end
# This is a bit hairy, but we need to be able to write specs that cover the
# boundary between Fixnum and Bignum for operations like Fixnum#<<. Since
# this boundary is implementation-dependent, we use these helpers to write
# specs based on the relationship between values rather than specific
# values.
if PlatformGuard.standard? or PlatformGuard.implementation? :topaz
if PlatformGuard.wordsize? 32
def fixnum_max
(2**30) - 1
end
def fixnum_min
-(2**30)
end
elsif PlatformGuard.wordsize? 64
def fixnum_max
(2**62) - 1
end
def fixnum_min
-(2**62)
end
end
elsif PlatformGuard.implementation? :opal
def fixnum_max
Integer::MAX
end
def infinity_value
1/0.0
def fixnum_min
Integer::MIN
end
elsif PlatformGuard.implementation? :rubinius
def fixnum_max
Fixnum::MAX
end
def bignum_value(plus=0)
0x8000_0000_0000_0000 + plus
def fixnum_min
Fixnum::MIN
end
elsif PlatformGuard.implementation?(:jruby) || PlatformGuard.implementation?(:truffleruby)
def fixnum_max
9223372036854775807
end
# This is a bit hairy, but we need to be able to write specs that cover the
# boundary between Fixnum and Bignum for operations like Fixnum#<<. Since
# this boundary is implementation-dependent, we use these helpers to write
# specs based on the relationship between values rather than specific
# values.
if PlatformGuard.standard? or PlatformGuard.implementation? :topaz
if PlatformGuard.wordsize? 32
def fixnum_max
(2**30) - 1
end
def fixnum_min
-9223372036854775808
end
else
def fixnum_max
raise "unknown implementation for fixnum_max() helper"
end
def fixnum_min
-(2**30)
end
elsif PlatformGuard.wordsize? 64
def fixnum_max
(2**62) - 1
end
def fixnum_min
-(2**62)
end
end
elsif PlatformGuard.implementation? :opal
def fixnum_max
Integer::MAX
end
def fixnum_min
Integer::MIN
end
elsif PlatformGuard.implementation? :rubinius
def fixnum_max
Fixnum::MAX
end
def fixnum_min
Fixnum::MIN
end
elsif PlatformGuard.implementation?(:jruby) || PlatformGuard.implementation?(:truffleruby)
def fixnum_max
9223372036854775807
end
def fixnum_min
-9223372036854775808
end
else
def fixnum_max
raise "unknown implementation for fixnum_max() helper"
end
def fixnum_min
raise "unknown implementation for fixnum_min() helper"
end
def fixnum_min
raise "unknown implementation for fixnum_min() helper"
end
end

View file

@ -1,4 +1,3 @@
require 'mspec/utils/ruby_name'
require 'mspec/guards/platform'
require 'mspec/helpers/tmp'
@ -46,8 +45,8 @@ require 'mspec/helpers/tmp'
# constructed as follows:
#
# 1. the value of ENV['RUBY_EXE']
# 2. an explicit value based on RUBY_NAME
# 3. cwd/(RUBY_NAME + $(EXEEXT) || $(exeext) || '')
# 2. an explicit value based on RUBY_ENGINE
# 3. cwd/(RUBY_ENGINE + $(EXEEXT) || $(exeext) || '')
# 4. $(bindir)/$(RUBY_INSTALL_NAME)
#
# The value will only be used if the file exists and is executable.
@ -64,8 +63,7 @@ require 'mspec/helpers/tmp'
# 2. Running the specs while developing an alternative
# Ruby implementation. This explicitly names the
# executable in the development directory based on
# the value of RUBY_NAME, which is probably initialized
# from the value of RUBY_ENGINE.
# the value of RUBY_ENGINE.
# 3. Running the specs within the source directory for
# some implementation. (E.g. a local build directory.)
# 4. Running the specs against some installed Ruby
@ -76,103 +74,101 @@ require 'mspec/helpers/tmp'
# will be appended to RUBY_EXE so that the interpreter
# is always called with those flags.
class Object
def ruby_exe_options(option)
case option
when :env
ENV['RUBY_EXE']
when :engine
case RUBY_NAME
when 'rbx'
"bin/rbx"
when 'jruby'
"bin/jruby"
when 'maglev'
"maglev-ruby"
when 'topaz'
"topaz"
when 'ironruby'
"ir"
end
when :name
require 'rbconfig'
bin = RUBY_NAME + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
File.join(".", bin)
when :install_name
require 'rbconfig'
bin = RbConfig::CONFIG["RUBY_INSTALL_NAME"] || RbConfig::CONFIG["ruby_install_name"]
bin << (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
File.join(RbConfig::CONFIG['bindir'], bin)
def ruby_exe_options(option)
case option
when :env
ENV['RUBY_EXE']
when :engine
case RUBY_ENGINE
when 'rbx'
"bin/rbx"
when 'jruby'
"bin/jruby"
when 'maglev'
"maglev-ruby"
when 'topaz'
"topaz"
when 'ironruby'
"ir"
end
end
def resolve_ruby_exe
[:env, :engine, :name, :install_name].each do |option|
next unless exe = ruby_exe_options(option)
if File.file?(exe) and File.executable?(exe)
exe = File.expand_path(exe)
exe = exe.tr('/', '\\') if PlatformGuard.windows?
flags = ENV['RUBY_FLAGS']
if flags and !flags.empty?
return exe + ' ' + flags
else
return exe
end
end
end
raise Exception, "Unable to find a suitable ruby executable."
end
def ruby_exe(code, opts = {})
if opts[:dir]
raise "ruby_exe(..., dir: dir) is no longer supported, use Dir.chdir"
end
env = opts[:env] || {}
saved_env = {}
env.each do |key, value|
key = key.to_s
saved_env[key] = ENV[key] if ENV.key? key
ENV[key] = value
end
escape = opts.delete(:escape)
if code and !File.exist?(code) and escape != false
tmpfile = tmp("rubyexe.rb")
File.open(tmpfile, "w") { |f| f.write(code) }
code = tmpfile
end
begin
platform_is_not :opal do
`#{ruby_cmd(code, opts)}`
end
ensure
saved_env.each { |key, value| ENV[key] = value }
env.keys.each do |key|
key = key.to_s
ENV.delete key unless saved_env.key? key
end
File.delete tmpfile if tmpfile
end
end
def ruby_cmd(code, opts = {})
body = code
if opts[:escape]
raise "escape: true is no longer supported in ruby_cmd, use ruby_exe or a fixture"
end
if code and !File.exist?(code)
body = "-e #{code.inspect}"
end
[RUBY_EXE, opts[:options], body, opts[:args]].compact.join(' ')
end
unless Object.const_defined?(:RUBY_EXE) and RUBY_EXE
RUBY_EXE = resolve_ruby_exe
when :name
require 'rbconfig'
bin = RUBY_ENGINE + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
File.join(".", bin)
when :install_name
require 'rbconfig'
bin = RbConfig::CONFIG["RUBY_INSTALL_NAME"] || RbConfig::CONFIG["ruby_install_name"]
bin << (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
File.join(RbConfig::CONFIG['bindir'], bin)
end
end
def resolve_ruby_exe
[:env, :engine, :name, :install_name].each do |option|
next unless exe = ruby_exe_options(option)
if File.file?(exe) and File.executable?(exe)
exe = File.expand_path(exe)
exe = exe.tr('/', '\\') if PlatformGuard.windows?
flags = ENV['RUBY_FLAGS']
if flags and !flags.empty?
return exe + ' ' + flags
else
return exe
end
end
end
raise Exception, "Unable to find a suitable ruby executable."
end
def ruby_exe(code, opts = {})
if opts[:dir]
raise "ruby_exe(..., dir: dir) is no longer supported, use Dir.chdir"
end
env = opts[:env] || {}
saved_env = {}
env.each do |key, value|
key = key.to_s
saved_env[key] = ENV[key] if ENV.key? key
ENV[key] = value
end
escape = opts.delete(:escape)
if code and !File.exist?(code) and escape != false
tmpfile = tmp("rubyexe.rb")
File.open(tmpfile, "w") { |f| f.write(code) }
code = tmpfile
end
begin
platform_is_not :opal do
`#{ruby_cmd(code, opts)}`
end
ensure
saved_env.each { |key, value| ENV[key] = value }
env.keys.each do |key|
key = key.to_s
ENV.delete key unless saved_env.key? key
end
File.delete tmpfile if tmpfile
end
end
def ruby_cmd(code, opts = {})
body = code
if opts[:escape]
raise "escape: true is no longer supported in ruby_cmd, use ruby_exe or a fixture"
end
if code and !File.exist?(code)
body = "-e #{code.inspect}"
end
[RUBY_EXE, opts[:options], body, opts[:args]].compact.join(' ')
end
unless Object.const_defined?(:RUBY_EXE) and RUBY_EXE
RUBY_EXE = resolve_ruby_exe
end

View file

@ -30,16 +30,14 @@ all specs are cleaning up temporary files:
end
end
class Object
def tmp(name, uniquify=true)
Dir.mkdir SPEC_TEMP_DIR unless Dir.exist? SPEC_TEMP_DIR
def tmp(name, uniquify=true)
Dir.mkdir SPEC_TEMP_DIR unless Dir.exist? SPEC_TEMP_DIR
if uniquify and !name.empty?
slash = name.rindex "/"
index = slash ? slash + 1 : 0
name.insert index, "#{SPEC_TEMP_UNIQUIFIER.succ!}-"
end
File.join SPEC_TEMP_DIR, name
if uniquify and !name.empty?
slash = name.rindex "/"
index = slash ? slash + 1 : 0
name.insert index, "#{SPEC_TEMP_UNIQUIFIER.succ!}-"
end
File.join SPEC_TEMP_DIR, name
end

View file

@ -1,9 +1,7 @@
class Object
def suppress_warning
verbose = $VERBOSE
$VERBOSE = nil
yield
ensure
$VERBOSE = verbose
end
def suppress_warning
verbose = $VERBOSE
$VERBOSE = nil
yield
ensure
$VERBOSE = verbose
end

View file

@ -15,7 +15,7 @@ class HtmlFormatter < DottedFormatter
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Spec Output For #{RUBY_NAME} (#{RUBY_VERSION})</title>
<title>Spec Output For #{RUBY_ENGINE} (#{RUBY_VERSION})</title>
<style type="text/css">
ul {
list-style: none;

View file

@ -1,5 +1,4 @@
require 'mspec/expectations/expectations'
require 'mspec/utils/ruby_name'
require 'mspec/runner/formatters/yaml'
class JUnitFormatter < YamlFormatter
@ -39,7 +38,7 @@ class JUnitFormatter < YamlFormatter
errors="#{errors}"
failures="#{failures}"
time="#{time}"
name="Spec Output For #{::RUBY_NAME} (#{::RUBY_VERSION})">
name="Spec Output For #{::RUBY_ENGINE} (#{::RUBY_VERSION})">
XML
@tests.each do |h|
description = encode_for_xml h[:test].description

View file

@ -200,13 +200,6 @@ class MSpecOptions
"Load FILE containing configuration options", &block)
end
def name
on("-n", "--name", "RUBY_NAME",
"Set the value of RUBY_NAME (used to determine the implementation)") do |n|
Object.const_set :RUBY_NAME, n
end
end
def targets
on("-t", "--target", "TARGET",
"Implementation to run the specs, where TARGET is:") do |t|
@ -469,7 +462,6 @@ class MSpecOptions
# Generated with:
# puts File.read(__FILE__).scan(/def (\w+).*\n\s*on\(/)
configure {}
name
targets
formatters
filters

View file

@ -1,8 +0,0 @@
unless Object.const_defined?(:RUBY_NAME) and RUBY_NAME
if Object.const_defined?(:RUBY_ENGINE) and RUBY_ENGINE
RUBY_NAME = RUBY_ENGINE
else
require 'rbconfig'
RUBY_NAME = RbConfig::CONFIG["RUBY_INSTALL_NAME"] || RbConfig::CONFIG["ruby_install_name"]
end
end

View file

@ -33,11 +33,6 @@ describe MSpecCI, "#options" do
@script.options ["-B", "cfg.mspec"]
end
it "enables the name option" do
@options.should_receive(:name)
@script.options
end
it "enables the dry run option" do
@options.should_receive(:pretend)
@script.options

View file

@ -56,11 +56,6 @@ describe MSpecRun, "#options" do
@script.options ["-B", "cfg.mspec", one_spec]
end
it "enables the name option" do
@options.should_receive(:name)
@script.options @argv
end
it "enables the randomize option to runs specs in random order" do
@options.should_receive(:randomize)
@script.options @argv

View file

@ -61,11 +61,6 @@ describe MSpecTag, "#options" do
@script.options ["-B", "cfg.mspec", one_spec]
end
it "enables the name option" do
@options.should_receive(:name)
@script.options @argv
end
it "enables the dry run option" do
@options.should_receive(:pretend)
@script.options @argv

View file

@ -14,12 +14,12 @@ describe BugGuard, "#match? when #implementation? is 'ruby'" do
before :each do
hide_deprecation_warnings
stub_const "VersionGuard::FULL_RUBY_VERSION", SpecVersion.new('1.8.6')
@ruby_name = Object.const_get :RUBY_NAME
Object.const_set :RUBY_NAME, 'ruby'
@ruby_engine = Object.const_get :RUBY_ENGINE
Object.const_set :RUBY_ENGINE, 'ruby'
end
after :each do
Object.const_set :RUBY_NAME, @ruby_name
Object.const_set :RUBY_ENGINE, @ruby_engine
end
it "returns false when version argument is less than RUBY_VERSION" do
@ -76,15 +76,15 @@ describe BugGuard, "#match? when #implementation? is not 'ruby'" do
before :each do
hide_deprecation_warnings
@ruby_version = Object.const_get :RUBY_VERSION
@ruby_name = Object.const_get :RUBY_NAME
@ruby_engine = Object.const_get :RUBY_ENGINE
Object.const_set :RUBY_VERSION, '1.8.6'
Object.const_set :RUBY_NAME, 'jruby'
Object.const_set :RUBY_ENGINE, 'jruby'
end
after :each do
Object.const_set :RUBY_VERSION, @ruby_version
Object.const_set :RUBY_NAME, @ruby_name
Object.const_set :RUBY_ENGINE, @ruby_engine
end
it "returns false when version argument is less than RUBY_VERSION" do

View file

@ -120,56 +120,56 @@ describe PlatformGuard, ".implementation?" do
end
before :each do
@ruby_name = Object.const_get :RUBY_NAME
@ruby_engine = Object.const_get :RUBY_ENGINE
end
after :each do
Object.const_set :RUBY_NAME, @ruby_name
Object.const_set :RUBY_ENGINE, @ruby_engine
end
it "returns true if passed :ruby and RUBY_NAME == 'ruby'" do
Object.const_set :RUBY_NAME, 'ruby'
it "returns true if passed :ruby and RUBY_ENGINE == 'ruby'" do
Object.const_set :RUBY_ENGINE, 'ruby'
PlatformGuard.implementation?(:ruby).should == true
end
it "returns true if passed :rubinius and RUBY_NAME == 'rbx'" do
Object.const_set :RUBY_NAME, 'rbx'
it "returns true if passed :rubinius and RUBY_ENGINE == 'rbx'" do
Object.const_set :RUBY_ENGINE, 'rbx'
PlatformGuard.implementation?(:rubinius).should == true
end
it "returns true if passed :jruby and RUBY_NAME == 'jruby'" do
Object.const_set :RUBY_NAME, 'jruby'
it "returns true if passed :jruby and RUBY_ENGINE == 'jruby'" do
Object.const_set :RUBY_ENGINE, 'jruby'
PlatformGuard.implementation?(:jruby).should == true
end
it "returns true if passed :ironruby and RUBY_NAME == 'ironruby'" do
Object.const_set :RUBY_NAME, 'ironruby'
it "returns true if passed :ironruby and RUBY_ENGINE == 'ironruby'" do
Object.const_set :RUBY_ENGINE, 'ironruby'
PlatformGuard.implementation?(:ironruby).should == true
end
it "returns true if passed :maglev and RUBY_NAME == 'maglev'" do
Object.const_set :RUBY_NAME, 'maglev'
it "returns true if passed :maglev and RUBY_ENGINE == 'maglev'" do
Object.const_set :RUBY_ENGINE, 'maglev'
PlatformGuard.implementation?(:maglev).should == true
end
it "returns true if passed :topaz and RUBY_NAME == 'topaz'" do
Object.const_set :RUBY_NAME, 'topaz'
it "returns true if passed :topaz and RUBY_ENGINE == 'topaz'" do
Object.const_set :RUBY_ENGINE, 'topaz'
PlatformGuard.implementation?(:topaz).should == true
end
it "returns true if passed :ruby and RUBY_NAME matches /^ruby/" do
Object.const_set :RUBY_NAME, 'ruby'
it "returns true if passed :ruby and RUBY_ENGINE matches /^ruby/" do
Object.const_set :RUBY_ENGINE, 'ruby'
PlatformGuard.implementation?(:ruby).should == true
Object.const_set :RUBY_NAME, 'ruby1.8'
Object.const_set :RUBY_ENGINE, 'ruby1.8'
PlatformGuard.implementation?(:ruby).should == true
Object.const_set :RUBY_NAME, 'ruby1.9'
Object.const_set :RUBY_ENGINE, 'ruby1.9'
PlatformGuard.implementation?(:ruby).should == true
end
it "raises an error when passed an unrecognized name" do
Object.const_set :RUBY_NAME, 'ruby'
Object.const_set :RUBY_ENGINE, 'ruby'
lambda {
PlatformGuard.implementation?(:python)
}.should raise_error(/unknown implementation/)

View file

@ -5,15 +5,15 @@ describe Object, "#not_supported_on" do
before :all do
@verbose = $VERBOSE
$VERBOSE = nil
@ruby_name = Object.const_get :RUBY_NAME if Object.const_defined? :RUBY_NAME
@ruby_engine = Object.const_get :RUBY_ENGINE if Object.const_defined? :RUBY_ENGINE
end
after :all do
$VERBOSE = @verbose
if @ruby_name
Object.const_set :RUBY_NAME, @ruby_name
if @ruby_engine
Object.const_set :RUBY_ENGINE, @ruby_engine
else
Object.send :remove_const, :RUBY_NAME
Object.send :remove_const, :RUBY_ENGINE
end
end
@ -22,7 +22,7 @@ describe Object, "#not_supported_on" do
end
it "raises an Exception when passed :ruby" do
Object.const_set :RUBY_NAME, "jruby"
Object.const_set :RUBY_ENGINE, "jruby"
lambda {
not_supported_on(:ruby) { ScratchPad.record :yield }
}.should raise_error(Exception)
@ -30,19 +30,19 @@ describe Object, "#not_supported_on" do
end
it "does not yield when #implementation? returns true" do
Object.const_set :RUBY_NAME, "jruby"
Object.const_set :RUBY_ENGINE, "jruby"
not_supported_on(:jruby) { ScratchPad.record :yield }
ScratchPad.recorded.should_not == :yield
end
it "yields when #standard? returns true" do
Object.const_set :RUBY_NAME, "ruby"
Object.const_set :RUBY_ENGINE, "ruby"
not_supported_on(:rubinius) { ScratchPad.record :yield }
ScratchPad.recorded.should == :yield
end
it "yields when #implementation? returns false" do
Object.const_set :RUBY_NAME, "jruby"
Object.const_set :RUBY_ENGINE, "jruby"
not_supported_on(:rubinius) { ScratchPad.record :yield }
ScratchPad.recorded.should == :yield
end

View file

@ -4,6 +4,10 @@ require 'mspec/helpers'
require 'rbconfig'
class RubyExeSpecs
public :ruby_exe_options
public :resolve_ruby_exe
public :ruby_cmd
public :ruby_exe
end
describe "#ruby_exe_options" do
@ -11,14 +15,14 @@ describe "#ruby_exe_options" do
@verbose = $VERBOSE
$VERBOSE = nil
@ruby_name = Object.const_get :RUBY_NAME
@ruby_engine = Object.const_get :RUBY_ENGINE
@ruby_exe_env = ENV['RUBY_EXE']
@script = RubyExeSpecs.new
end
after :all do
Object.const_set :RUBY_NAME, @ruby_name
Object.const_set :RUBY_ENGINE, @ruby_engine
ENV['RUBY_EXE'] = @ruby_exe_env
$VERBOSE = @verbose
end
@ -32,33 +36,33 @@ describe "#ruby_exe_options" do
@script.ruby_exe_options(:env).should == "kowabunga"
end
it "returns 'bin/jruby' when passed :engine and RUBY_NAME is 'jruby'" do
Object.const_set :RUBY_NAME, 'jruby'
it "returns 'bin/jruby' when passed :engine and RUBY_ENGINE is 'jruby'" do
Object.const_set :RUBY_ENGINE, 'jruby'
@script.ruby_exe_options(:engine).should == 'bin/jruby'
end
it "returns 'bin/rbx' when passed :engine, RUBY_NAME is 'rbx'" do
Object.const_set :RUBY_NAME, 'rbx'
it "returns 'bin/rbx' when passed :engine, RUBY_ENGINE is 'rbx'" do
Object.const_set :RUBY_ENGINE, 'rbx'
@script.ruby_exe_options(:engine).should == 'bin/rbx'
end
it "returns 'ir' when passed :engine and RUBY_NAME is 'ironruby'" do
Object.const_set :RUBY_NAME, 'ironruby'
it "returns 'ir' when passed :engine and RUBY_ENGINE is 'ironruby'" do
Object.const_set :RUBY_ENGINE, 'ironruby'
@script.ruby_exe_options(:engine).should == 'ir'
end
it "returns 'maglev-ruby' when passed :engine and RUBY_NAME is 'maglev'" do
Object.const_set :RUBY_NAME, 'maglev'
it "returns 'maglev-ruby' when passed :engine and RUBY_ENGINE is 'maglev'" do
Object.const_set :RUBY_ENGINE, 'maglev'
@script.ruby_exe_options(:engine).should == 'maglev-ruby'
end
it "returns 'topaz' when passed :engine and RUBY_NAME is 'topaz'" do
Object.const_set :RUBY_NAME, 'topaz'
it "returns 'topaz' when passed :engine and RUBY_ENGINE is 'topaz'" do
Object.const_set :RUBY_ENGINE, 'topaz'
@script.ruby_exe_options(:engine).should == 'topaz'
end
it "returns RUBY_NAME + $(EXEEXT) when passed :name" do
bin = RUBY_NAME + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
it "returns RUBY_ENGINE + $(EXEEXT) when passed :name" do
bin = RUBY_ENGINE + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
name = File.join ".", bin
@script.ruby_exe_options(:name).should == name
end

View file

@ -1,5 +1,4 @@
require File.dirname(__FILE__) + '/../../spec_helper'
require 'mspec/utils/ruby_name'
require 'mspec/guards/guard'
require 'mspec/runner/formatters/html'
require 'mspec/runner/mspec'
@ -32,14 +31,14 @@ describe HtmlFormatter, "#start" do
it "prints the HTML head" do
@formatter.start
ruby_name = RUBY_NAME
ruby_name.should =~ /^#{ruby_name}/
ruby_engine = RUBY_ENGINE
ruby_engine.should =~ /^#{ruby_engine}/
@out.should ==
%[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Spec Output For #{ruby_name} (#{RUBY_VERSION})</title>
<title>Spec Output For #{ruby_engine} (#{RUBY_VERSION})</title>
<style type="text/css">
ul {
list-style: none;

View file

@ -507,30 +507,6 @@ describe "The --prefix STR option" do
end
end
describe "The -n, --name RUBY_NAME option" do
before :each do
@verbose, $VERBOSE = $VERBOSE, nil
@options, @config = new_option
end
after :each do
$VERBOSE = @verbose
end
it "is enabled with #name" do
@options.should_receive(:on).with("-n", "--name", "RUBY_NAME",
an_instance_of(String))
@options.name
end
it "sets RUBY_NAME when invoked" do
Object.should_receive(:const_set).with(:RUBY_NAME, "name").twice
@options.name
@options.parse ["-n", "name"]
@options.parse ["--name", "name"]
end
end
describe "The -t, --target TARGET option" do
before :each do
@options, @config = new_option

View file

@ -24,6 +24,9 @@ raise RUBYSPEC_REPO unless Dir.exist?(RUBYSPEC_REPO)
NOW = Time.now
BRIGHT_YELLOW = "\e[33;1m"
RESET = "\e[0m"
class RubyImplementation
attr_reader :name
@ -110,7 +113,7 @@ def rebase_commits(impl)
rebased = impl.rebased_branch
if branch?(rebased)
puts "#{rebased} already exists, assuming it correct"
puts "#{BRIGHT_YELLOW}#{rebased} already exists, assuming it correct#{RESET}"
sh "git", "checkout", rebased
else
sh "git", "checkout", impl.name
@ -118,7 +121,7 @@ def rebase_commits(impl)
if ENV["LAST_MERGE"]
last_merge = `git log -n 1 --format='%H %ct' #{ENV["LAST_MERGE"]}`
else
last_merge = `git log --grep='#{impl.last_merge_message}' -n 1 --format='%H %ct'`
last_merge = `git log --grep='^#{impl.last_merge_message}' -n 1 --format='%H %ct'`
end
last_merge, commit_timestamp = last_merge.chomp.split(' ')