mspec 1.5.17 → 1.5.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +27 -0
- data/Gemfile +4 -0
- data/README +39 -159
- data/Rakefile +4 -44
- data/bin/mkspec.bat +1 -0
- data/bin/mspec-ci.bat +1 -0
- data/bin/mspec-run.bat +1 -0
- data/bin/mspec-tag.bat +1 -0
- data/bin/mspec.bat +1 -0
- data/lib/mspec/commands/mkspec.rb +2 -2
- data/lib/mspec/commands/mspec-run.rb +4 -0
- data/lib/mspec/commands/mspec.rb +18 -3
- data/lib/mspec/guards.rb +1 -0
- data/lib/mspec/guards/block_device.rb +22 -0
- data/lib/mspec/guards/guard.rb +14 -2
- data/lib/mspec/helpers.rb +5 -5
- data/lib/mspec/helpers/const_lookup.rb +6 -1
- data/lib/mspec/helpers/datetime.rb +28 -0
- data/lib/mspec/helpers/ducktype.rb +4 -4
- data/lib/mspec/helpers/environment.rb +19 -2
- data/lib/mspec/helpers/fs.rb +5 -1
- data/lib/mspec/helpers/io.rb +39 -1
- data/lib/mspec/helpers/numeric.rb +89 -0
- data/lib/mspec/helpers/pack.rb +3 -0
- data/lib/mspec/helpers/ruby_exe.rb +53 -15
- data/lib/mspec/helpers/singleton_class.rb +7 -0
- data/lib/mspec/helpers/stasy.rb +33 -0
- data/lib/mspec/helpers/tmp.rb +16 -3
- data/lib/mspec/matchers.rb +8 -0
- data/lib/mspec/matchers/be_computed_by.rb +37 -0
- data/lib/mspec/matchers/be_computed_by_function.rb +35 -0
- data/lib/mspec/matchers/be_nan.rb +20 -0
- data/lib/mspec/matchers/be_valid_dns_name.rb +25 -0
- data/lib/mspec/matchers/have_data.rb +6 -5
- data/lib/mspec/matchers/have_private_method.rb +24 -0
- data/lib/mspec/matchers/have_singleton_method.rb +24 -0
- data/lib/mspec/matchers/infinity.rb +28 -0
- data/lib/mspec/matchers/match_yaml.rb +5 -5
- data/lib/mspec/matchers/raise_error.rb +5 -3
- data/lib/mspec/matchers/signed_zero.rb +28 -0
- data/lib/mspec/mocks/mock.rb +15 -9
- data/lib/mspec/mocks/object.rb +4 -0
- data/lib/mspec/mocks/proxy.rb +26 -1
- data/lib/mspec/runner/actions.rb +0 -1
- data/lib/mspec/runner/context.rb +18 -16
- data/lib/mspec/runner/formatters.rb +2 -0
- data/lib/mspec/runner/formatters/dotted.rb +13 -1
- data/lib/mspec/runner/formatters/junit.rb +96 -0
- data/lib/mspec/runner/formatters/profile.rb +70 -0
- data/lib/mspec/runner/mspec.rb +11 -0
- data/lib/mspec/runner/shared.rb +1 -1
- data/lib/mspec/utils/options.rb +33 -9
- data/lib/mspec/utils/ruby_name.rb +1 -1
- data/lib/mspec/utils/script.rb +2 -1
- data/lib/mspec/version.rb +1 -1
- data/mspec.gemspec +40 -0
- data/spec/commands/mkspec_spec.rb +4 -3
- data/spec/commands/mspec_ci_spec.rb +1 -6
- data/spec/commands/mspec_run_spec.rb +1 -6
- data/spec/commands/mspec_spec.rb +14 -6
- data/spec/commands/mspec_tag_spec.rb +28 -27
- data/spec/expectations/expectations_spec.rb +1 -1
- data/spec/expectations/should_spec.rb +4 -4
- data/spec/guards/background_spec.rb +2 -2
- data/spec/guards/block_device_spec.rb +46 -0
- data/spec/guards/bug_spec.rb +2 -3
- data/spec/guards/compliance_spec.rb +2 -2
- data/spec/guards/conflict_spec.rb +2 -2
- data/spec/guards/endian_spec.rb +2 -2
- data/spec/guards/extensions_spec.rb +2 -2
- data/spec/guards/feature_spec.rb +2 -2
- data/spec/guards/guard_spec.rb +80 -22
- data/spec/guards/noncompliance_spec.rb +2 -2
- data/spec/guards/platform_spec.rb +2 -2
- data/spec/guards/quarantine_spec.rb +2 -2
- data/spec/guards/runner_spec.rb +2 -2
- data/spec/guards/specified_spec.rb +2 -2
- data/spec/guards/superuser_spec.rb +2 -2
- data/spec/guards/support_spec.rb +2 -2
- data/spec/guards/tty_spec.rb +2 -2
- data/spec/guards/user_spec.rb +2 -2
- data/spec/guards/version_spec.rb +2 -2
- data/spec/helpers/argv_spec.rb +3 -2
- data/spec/helpers/const_lookup_spec.rb +3 -2
- data/spec/helpers/datetime_spec.rb +44 -0
- data/spec/helpers/ducktype_spec.rb +3 -2
- data/spec/helpers/encode_spec.rb +3 -2
- data/spec/helpers/enumerator_class_spec.rb +5 -5
- data/spec/helpers/environment_spec.rb +15 -3
- data/spec/helpers/fixture_spec.rb +3 -2
- data/spec/helpers/flunk_spec.rb +4 -3
- data/spec/helpers/fs_spec.rb +35 -18
- data/spec/helpers/hash_spec.rb +3 -2
- data/spec/helpers/io_spec.rb +75 -6
- data/spec/helpers/language_version_spec.rb +3 -2
- data/spec/helpers/mock_to_path_spec.rb +3 -2
- data/spec/helpers/numeric_spec.rb +25 -0
- data/spec/helpers/ruby_exe_spec.rb +115 -29
- data/spec/helpers/scratch_spec.rb +3 -1
- data/spec/helpers/stasy_spec.rb +59 -0
- data/spec/helpers/tmp_spec.rb +21 -4
- data/spec/matchers/base_spec.rb +2 -2
- data/spec/matchers/be_an_instance_of_spec.rb +2 -2
- data/spec/matchers/be_ancestor_of_spec.rb +2 -2
- data/spec/matchers/be_close_spec.rb +2 -2
- data/spec/matchers/be_computed_by_function_spec.rb +36 -0
- data/spec/matchers/be_computed_by_spec.rb +42 -0
- data/spec/matchers/be_empty_spec.rb +2 -2
- data/spec/matchers/be_false_spec.rb +3 -3
- data/spec/matchers/be_kind_of_spec.rb +2 -2
- data/spec/matchers/be_nan_spec.rb +28 -0
- data/spec/matchers/be_nil_spec.rb +3 -3
- data/spec/matchers/be_true_spec.rb +3 -3
- data/spec/matchers/be_valid_dns_name_spec.rb +50 -0
- data/spec/matchers/complain_spec.rb +2 -2
- data/spec/matchers/eql_spec.rb +2 -2
- data/spec/matchers/equal_element_spec.rb +2 -2
- data/spec/matchers/equal_spec.rb +2 -2
- data/spec/matchers/equal_utf16_spec.rb +2 -2
- data/spec/matchers/have_class_variable_spec.rb +3 -3
- data/spec/matchers/have_constant_spec.rb +2 -2
- data/spec/matchers/have_data_spec.rb +8 -5
- data/spec/matchers/have_instance_method_spec.rb +2 -2
- data/spec/matchers/have_instance_variable_spec.rb +3 -3
- data/spec/matchers/have_method_spec.rb +2 -2
- data/spec/matchers/have_private_instance_method_spec.rb +3 -3
- data/spec/matchers/have_private_method_spec.rb +44 -0
- data/spec/matchers/have_protected_instance_method_spec.rb +2 -2
- data/spec/matchers/have_public_instance_method_spec.rb +2 -2
- data/spec/matchers/have_singleton_method_spec.rb +45 -0
- data/spec/matchers/include_spec.rb +2 -2
- data/spec/matchers/infinity_spec.rb +34 -0
- data/spec/matchers/match_yaml_spec.rb +3 -3
- data/spec/matchers/output_spec.rb +2 -2
- data/spec/matchers/output_to_fd_spec.rb +2 -2
- data/spec/matchers/raise_error_spec.rb +24 -3
- data/spec/matchers/respond_to_spec.rb +2 -2
- data/spec/matchers/signed_zero_spec.rb +32 -0
- data/spec/matchers/stringsymboladapter_spec.rb +2 -2
- data/spec/mocks/mock_spec.rb +12 -12
- data/spec/mocks/proxy_spec.rb +1 -1
- data/spec/runner/actions/gdb_spec.rb +1 -1
- data/spec/runner/actions/tag_spec.rb +1 -1
- data/spec/runner/actions/taglist_spec.rb +1 -1
- data/spec/runner/context_spec.rb +27 -27
- data/spec/runner/example_spec.rb +1 -1
- data/spec/runner/exception_spec.rb +1 -1
- data/spec/runner/filters/tag_spec.rb +2 -2
- data/spec/runner/formatters/describe_spec.rb +1 -1
- data/spec/runner/formatters/dotted_spec.rb +2 -2
- data/spec/runner/formatters/html_spec.rb +2 -2
- data/spec/runner/formatters/junit_spec.rb +147 -0
- data/spec/runner/formatters/unit_spec.rb +2 -2
- data/spec/runner/formatters/yaml_spec.rb +3 -3
- data/spec/runner/mspec_spec.rb +22 -21
- data/spec/runner/shared_spec.rb +9 -1
- data/spec/runner/tag_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -7
- data/spec/utils/name_map_spec.rb +1 -2
- data/spec/utils/options_spec.rb +58 -27
- data/spec/utils/script_spec.rb +5 -13
- data/spec/utils/version_spec.rb +1 -1
- metadata +254 -64
- data/lib/mspec/helpers/bignum.rb +0 -5
- data/lib/mspec/helpers/fmode.rb +0 -15
- data/lib/mspec/helpers/infinity.rb +0 -5
- data/lib/mspec/helpers/metaclass.rb +0 -7
- data/lib/mspec/helpers/nan.rb +0 -5
- data/lib/mspec/runner/actions/debug.rb +0 -17
- data/spec/helpers/bignum_spec.rb +0 -11
- data/spec/helpers/fmode_spec.rb +0 -14
- data/spec/helpers/infinity_spec.rb +0 -8
- data/spec/helpers/nan_spec.rb +0 -8
- data/spec/runner/actions/debug_spec.rb +0 -62
data/lib/mspec/guards.rb
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'mspec/guards/guard'
|
|
2
|
+
|
|
3
|
+
class BlockDeviceGuard < SpecGuard
|
|
4
|
+
def match?
|
|
5
|
+
platform_is_not :freebsd, :windows do
|
|
6
|
+
block = `find /dev /devices -type b 2> /dev/null`
|
|
7
|
+
return !(block.nil? || block.empty?)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
false
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class Object
|
|
15
|
+
def with_block_device
|
|
16
|
+
g = BlockDeviceGuard.new
|
|
17
|
+
g.name = :with_block_device
|
|
18
|
+
yield if g.yield?
|
|
19
|
+
ensure
|
|
20
|
+
g.unregister
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/mspec/guards/guard.rb
CHANGED
|
@@ -32,6 +32,16 @@ class SpecGuard
|
|
|
32
32
|
@guards = []
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
+
@@ruby_version_override = nil
|
|
36
|
+
|
|
37
|
+
def self.ruby_version_override=(version)
|
|
38
|
+
@@ruby_version_override = version
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.ruby_version_override
|
|
42
|
+
@@ruby_version_override
|
|
43
|
+
end
|
|
44
|
+
|
|
35
45
|
# Returns a partial Ruby version string based on +which+. For example,
|
|
36
46
|
# if RUBY_VERSION = 8.2.3 and RUBY_PATCHLEVEL = 71:
|
|
37
47
|
#
|
|
@@ -54,7 +64,7 @@ class SpecGuard
|
|
|
54
64
|
|
|
55
65
|
patch = RUBY_PATCHLEVEL.to_i
|
|
56
66
|
patch = 0 if patch < 0
|
|
57
|
-
version = "#{RUBY_VERSION}.#{patch}"
|
|
67
|
+
version = "#{ruby_version_override || RUBY_VERSION}.#{patch}"
|
|
58
68
|
version.split('.')[0,n].join('.')
|
|
59
69
|
end
|
|
60
70
|
|
|
@@ -123,6 +133,8 @@ class SpecGuard
|
|
|
123
133
|
RUBY_NAME =~ /^macruby/
|
|
124
134
|
when :maglev
|
|
125
135
|
RUBY_NAME =~ /^maglev/
|
|
136
|
+
when :topaz
|
|
137
|
+
RUBY_NAME =~ /^topaz/
|
|
126
138
|
else
|
|
127
139
|
false
|
|
128
140
|
end
|
|
@@ -153,7 +165,7 @@ class SpecGuard
|
|
|
153
165
|
|
|
154
166
|
def os?(*oses)
|
|
155
167
|
oses.any? do |os|
|
|
156
|
-
host_os =
|
|
168
|
+
host_os = RbConfig::CONFIG['host_os'] || RUBY_PLATFORM
|
|
157
169
|
host_os.downcase!
|
|
158
170
|
host_os.match(os.to_s) || windows?(os, host_os)
|
|
159
171
|
end
|
data/lib/mspec/helpers.rb
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
require 'mspec/helpers/argv'
|
|
2
|
-
require 'mspec/helpers/bignum'
|
|
3
2
|
require 'mspec/helpers/const_lookup'
|
|
3
|
+
require 'mspec/helpers/datetime'
|
|
4
4
|
require 'mspec/helpers/ducktype'
|
|
5
5
|
require 'mspec/helpers/encode'
|
|
6
6
|
require 'mspec/helpers/enumerator_class'
|
|
7
7
|
require 'mspec/helpers/environment'
|
|
8
8
|
require 'mspec/helpers/fixture'
|
|
9
9
|
require 'mspec/helpers/flunk'
|
|
10
|
-
require 'mspec/helpers/fmode'
|
|
11
10
|
require 'mspec/helpers/fs'
|
|
12
11
|
require 'mspec/helpers/hash'
|
|
13
|
-
require 'mspec/helpers/infinity'
|
|
14
12
|
require 'mspec/helpers/io'
|
|
15
13
|
require 'mspec/helpers/language_version'
|
|
16
|
-
require 'mspec/helpers/metaclass'
|
|
17
14
|
require 'mspec/helpers/mock_to_path'
|
|
18
|
-
require 'mspec/helpers/
|
|
15
|
+
require 'mspec/helpers/numeric'
|
|
16
|
+
require 'mspec/helpers/pack'
|
|
19
17
|
require 'mspec/helpers/ruby_exe'
|
|
20
18
|
require 'mspec/helpers/scratch'
|
|
19
|
+
require 'mspec/helpers/stasy'
|
|
20
|
+
require 'mspec/helpers/singleton_class'
|
|
21
21
|
require 'mspec/helpers/tmp'
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
require 'mspec/utils/version'
|
|
2
|
+
|
|
1
3
|
module Kernel
|
|
2
4
|
def const_lookup(c)
|
|
5
|
+
extra_arg = SpecVersion.new(RUBY_VERSION) >= "1.9"
|
|
6
|
+
|
|
3
7
|
names = c.split '::'
|
|
4
8
|
names.shift if names.first.empty?
|
|
9
|
+
|
|
5
10
|
names.inject(Object) do |m, n|
|
|
6
|
-
defined =
|
|
11
|
+
defined = extra_arg ? m.const_defined?(n, false) : m.const_defined?(n)
|
|
7
12
|
defined ? m.const_get(n) : m.const_missing(n)
|
|
8
13
|
end
|
|
9
14
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class Object
|
|
2
|
+
# The new_datetime helper makes writing DateTime specs more simple by
|
|
3
|
+
# providing default constructor values and accepting a Hash of only the
|
|
4
|
+
# constructor values needed for the particular spec. For example:
|
|
5
|
+
#
|
|
6
|
+
# new_datetime :hour => 1, :minute => 20
|
|
7
|
+
#
|
|
8
|
+
# Possible keys are:
|
|
9
|
+
# :year, :month, :day, :hour, :minute, :second, :offset and :sg.
|
|
10
|
+
|
|
11
|
+
def new_datetime(opts={})
|
|
12
|
+
require 'date'
|
|
13
|
+
|
|
14
|
+
value = {
|
|
15
|
+
:year => -4712,
|
|
16
|
+
:month => 1,
|
|
17
|
+
:day => 1,
|
|
18
|
+
:hour => 0,
|
|
19
|
+
:minute => 0,
|
|
20
|
+
:second => 0,
|
|
21
|
+
:offset => 0,
|
|
22
|
+
:sg => Date::ITALY
|
|
23
|
+
}.merge opts
|
|
24
|
+
|
|
25
|
+
DateTime.new value[:year], value[:month], value[:day], value[:hour],
|
|
26
|
+
value[:minute], value[:second], value[:offset], value[:sg]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class Object
|
|
2
2
|
def responds_to(sym)
|
|
3
|
-
|
|
3
|
+
singleton_class.class_eval <<-END
|
|
4
4
|
def respond_to?(sym, include_private=false)
|
|
5
5
|
sym.to_sym == #{sym.to_sym.inspect} ? true : super
|
|
6
6
|
end
|
|
@@ -8,7 +8,7 @@ class Object
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def does_not_respond_to(sym)
|
|
11
|
-
|
|
11
|
+
singleton_class.class_eval <<-END
|
|
12
12
|
def respond_to?(sym, include_private=false)
|
|
13
13
|
sym.to_sym == #{sym.to_sym.inspect} ? false : super
|
|
14
14
|
end
|
|
@@ -16,7 +16,7 @@ class Object
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def undefine(sym)
|
|
19
|
-
|
|
19
|
+
singleton_class.class_eval <<-END
|
|
20
20
|
undef_method #{sym.to_sym.inspect}
|
|
21
21
|
END
|
|
22
22
|
end
|
|
@@ -24,7 +24,7 @@ class Object
|
|
|
24
24
|
def fake!(sym, value=nil)
|
|
25
25
|
responds_to sym
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
singleton_class.class_eval <<-END
|
|
28
28
|
def method_missing(sym, *args)
|
|
29
29
|
return #{value.inspect} if sym.to_sym == #{sym.to_sym.inspect}
|
|
30
30
|
end
|
|
@@ -13,7 +13,7 @@ class Object
|
|
|
13
13
|
|
|
14
14
|
def windows_env_echo(var)
|
|
15
15
|
`cmd.exe /C ECHO %#{var}%`.strip
|
|
16
|
-
end
|
|
16
|
+
end
|
|
17
17
|
|
|
18
18
|
def username
|
|
19
19
|
user = ""
|
|
@@ -28,5 +28,22 @@ class Object
|
|
|
28
28
|
def home_directory
|
|
29
29
|
return ENV['HOME'] unless PlatformGuard.windows?
|
|
30
30
|
windows_env_echo('HOMEDRIVE') + windows_env_echo('HOMEPATH')
|
|
31
|
-
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def dev_null
|
|
34
|
+
if PlatformGuard.windows?
|
|
35
|
+
"NUL"
|
|
36
|
+
else
|
|
37
|
+
"/dev/null"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def hostname
|
|
42
|
+
commands = ['hostname', 'uname -n']
|
|
43
|
+
commands.each do |command|
|
|
44
|
+
name = `#{command}`
|
|
45
|
+
return name.strip if $?.success?
|
|
46
|
+
end
|
|
47
|
+
raise Exception, "hostname: unable to find a working command"
|
|
48
|
+
end
|
|
32
49
|
end
|
data/lib/mspec/helpers/fs.rb
CHANGED
|
@@ -37,7 +37,11 @@ class Object
|
|
|
37
37
|
raise ArgumentError, "#{path} is not prefixed by #{prefix}"
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
# File.symlink? needs to be checked first as
|
|
41
|
+
# File.exists? returns false for dangling symlinks
|
|
42
|
+
if File.symlink? path
|
|
43
|
+
File.unlink path
|
|
44
|
+
elsif File.directory? path
|
|
41
45
|
Dir.entries(path).each { |x| rm_r "#{path}/#{x}" unless x =~ /^\.\.?$/ }
|
|
42
46
|
Dir.rmdir path
|
|
43
47
|
elsif File.exists? path
|
data/lib/mspec/helpers/io.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'mspec/guards/feature'
|
|
2
|
+
|
|
1
3
|
class IOStub < String
|
|
2
4
|
def write(*str)
|
|
3
5
|
self << str.join
|
|
@@ -25,12 +27,48 @@ class Object
|
|
|
25
27
|
# with any Ruby object). The file descriptor can safely be passed
|
|
26
28
|
# to IO.new without creating a Ruby object alias to the fd.
|
|
27
29
|
def new_fd(name, mode="w:utf-8")
|
|
30
|
+
mode = options_or_mode(mode)
|
|
31
|
+
|
|
32
|
+
if mode.kind_of? Hash
|
|
33
|
+
if mode.key? :mode
|
|
34
|
+
mode = mode[:mode]
|
|
35
|
+
else
|
|
36
|
+
raise ArgumentError, "new_fd options Hash must include :mode"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
28
40
|
IO.sysopen name, fmode(mode)
|
|
29
41
|
end
|
|
30
42
|
|
|
31
43
|
# Creates an IO instance for a temporary file name. The file
|
|
32
44
|
# must be deleted.
|
|
33
45
|
def new_io(name, mode="w:utf-8")
|
|
34
|
-
IO.new new_fd(name,
|
|
46
|
+
IO.new new_fd(name, options_or_mode(mode)), options_or_mode(mode)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# This helper simplifies passing file access modes regardless of
|
|
50
|
+
# whether the :encoding feature is enabled. Only the access specifier
|
|
51
|
+
# itself will be returned if :encoding is not enabled. Otherwise,
|
|
52
|
+
# the full mode string will be returned (i.e. the helper is a no-op).
|
|
53
|
+
def fmode(mode)
|
|
54
|
+
if FeatureGuard.enabled? :encoding
|
|
55
|
+
mode
|
|
56
|
+
else
|
|
57
|
+
mode.split(':').first
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# This helper simplifies passing file access modes or options regardless of
|
|
62
|
+
# whether the :encoding feature is enabled. Only the access specifier itself
|
|
63
|
+
# will be returned if :encoding is not enabled. Otherwise, the full mode
|
|
64
|
+
# string or option will be returned (i.e. the helper is a no-op).
|
|
65
|
+
def options_or_mode(oom)
|
|
66
|
+
return fmode(oom) if oom.kind_of? String
|
|
67
|
+
|
|
68
|
+
if FeatureGuard.enabled? :encoding
|
|
69
|
+
oom
|
|
70
|
+
else
|
|
71
|
+
fmode(oom[:mode] || "r:utf-8")
|
|
72
|
+
end
|
|
35
73
|
end
|
|
36
74
|
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
class Object
|
|
2
|
+
def nan_value
|
|
3
|
+
0/0.0
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def infinity_value
|
|
7
|
+
1/0.0
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def bignum_value(plus=0)
|
|
11
|
+
0x8000_0000_0000_0000 + plus
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# This is a bit hairy, but we need to be able to write specs that cover the
|
|
15
|
+
# boundary between Fixnum and Bignum for operations like Fixnum#<<. Since
|
|
16
|
+
# this boundary is implementation-dependent, we use these helpers to write
|
|
17
|
+
# specs based on the relationship between values rather than specific
|
|
18
|
+
# values.
|
|
19
|
+
guard = SpecGuard.new
|
|
20
|
+
|
|
21
|
+
if guard.standard? or guard.implementation? :topaz
|
|
22
|
+
if guard.wordsize? 32
|
|
23
|
+
def fixnum_max()
|
|
24
|
+
(2**30) - 1
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def fixnum_min()
|
|
28
|
+
-(2**30)
|
|
29
|
+
end
|
|
30
|
+
elsif guard.wordsize? 64
|
|
31
|
+
def fixnum_max()
|
|
32
|
+
(2**62) - 1
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def fixnum_min()
|
|
36
|
+
-(2**62)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
elsif guard.implementation? :rubinius
|
|
40
|
+
def fixnum_max()
|
|
41
|
+
Fixnum::MAX
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def fixnum_min()
|
|
45
|
+
Fixnum::MIN
|
|
46
|
+
end
|
|
47
|
+
elsif guard.implementation? :jruby
|
|
48
|
+
# Values from jruby/test/testFixnumBignumAutoconversion.rb
|
|
49
|
+
def fixnum_max()
|
|
50
|
+
9223372036854775807
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def fixnum_min()
|
|
54
|
+
-9223372036854775808
|
|
55
|
+
end
|
|
56
|
+
elsif guard.implementation? :ironruby
|
|
57
|
+
def fixnum_max()
|
|
58
|
+
raise "fixnum_max() helper not implemented"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def fixnum_min()
|
|
62
|
+
raise "fixnum_min() helper not implemented"
|
|
63
|
+
end
|
|
64
|
+
elsif guard.implementation? :maglev
|
|
65
|
+
def fixnum_max()
|
|
66
|
+
raise "fixnum_max() helper not implemented"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def fixnum_min()
|
|
70
|
+
raise "fixnum_min() helper not implemented"
|
|
71
|
+
end
|
|
72
|
+
elsif guard.implementation? :macruby
|
|
73
|
+
def fixnum_max()
|
|
74
|
+
raise "fixnum_max() helper not implemented"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def fixnum_min()
|
|
78
|
+
raise "fixnum_min() helper not implemented"
|
|
79
|
+
end
|
|
80
|
+
else
|
|
81
|
+
def fixnum_max()
|
|
82
|
+
raise "unknown implementation for fixnum_max() helper"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def fixnum_min()
|
|
86
|
+
raise "unknown implementation for fixnum_min() helper"
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -22,15 +22,19 @@ require 'mspec/guards/platform'
|
|
|
22
22
|
#
|
|
23
23
|
# `#{RUBY_EXE} -e #{'puts "hello, world."'}`
|
|
24
24
|
#
|
|
25
|
-
# The ruby_exe helper also accepts an options hash with
|
|
26
|
-
# keys: :options and :
|
|
25
|
+
# The ruby_exe helper also accepts an options hash with three
|
|
26
|
+
# keys: :options, :args and :env. For example:
|
|
27
27
|
#
|
|
28
|
-
# ruby_exe('file.rb', :options => "-w",
|
|
28
|
+
# ruby_exe('file.rb', :options => "-w",
|
|
29
|
+
# :args => "> file.txt",
|
|
30
|
+
# :env => { :FOO => "bar" })
|
|
29
31
|
#
|
|
30
32
|
# will be executed as
|
|
31
33
|
#
|
|
32
34
|
# `#{RUBY_EXE} -w #{'file.rb'} > file.txt`
|
|
33
35
|
#
|
|
36
|
+
# with access to ENV["FOO"] with value "bar".
|
|
37
|
+
#
|
|
34
38
|
# If +nil+ is passed for the first argument, the command line
|
|
35
39
|
# will be built only from the options hash.
|
|
36
40
|
#
|
|
@@ -73,47 +77,81 @@ class Object
|
|
|
73
77
|
when :engine
|
|
74
78
|
case RUBY_NAME
|
|
75
79
|
when 'rbx'
|
|
76
|
-
"
|
|
80
|
+
if SpecGuard.ruby_version < "1.9"
|
|
81
|
+
"bin/rbx"
|
|
82
|
+
else
|
|
83
|
+
"bin/rbx -X19"
|
|
84
|
+
end
|
|
77
85
|
when 'jruby'
|
|
78
86
|
"bin/jruby"
|
|
79
87
|
when 'maglev'
|
|
80
88
|
"maglev-ruby"
|
|
89
|
+
when 'topaz'
|
|
90
|
+
"topaz"
|
|
81
91
|
when 'ironruby'
|
|
82
92
|
"ir"
|
|
83
93
|
end
|
|
84
94
|
when :name
|
|
85
|
-
bin = RUBY_NAME + (
|
|
95
|
+
bin = RUBY_NAME + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
|
|
86
96
|
File.join(".", bin)
|
|
87
97
|
when :install_name
|
|
88
|
-
bin =
|
|
89
|
-
bin << (
|
|
90
|
-
File.join(
|
|
98
|
+
bin = RbConfig::CONFIG["RUBY_INSTALL_NAME"] || RbConfig::CONFIG["ruby_install_name"]
|
|
99
|
+
bin << (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
|
|
100
|
+
File.join(RbConfig::CONFIG['bindir'], bin)
|
|
91
101
|
end
|
|
92
102
|
end
|
|
93
103
|
|
|
94
104
|
def resolve_ruby_exe
|
|
95
105
|
[:env, :engine, :name, :install_name].each do |option|
|
|
96
106
|
next unless cmd = ruby_exe_options(option)
|
|
97
|
-
exe = cmd.split
|
|
107
|
+
exe, *rest = cmd.split(" ")
|
|
98
108
|
|
|
99
109
|
# It has been reported that File.executable is not reliable
|
|
100
110
|
# on Windows platforms (see commit 56bc555c). So, we check the
|
|
101
|
-
# platform.
|
|
111
|
+
# platform.
|
|
102
112
|
if File.exists?(exe) and (PlatformGuard.windows? or File.executable?(exe))
|
|
103
|
-
return
|
|
113
|
+
return [File.expand_path(exe), *rest].join(" ")
|
|
104
114
|
end
|
|
105
115
|
end
|
|
106
116
|
nil
|
|
107
117
|
end
|
|
108
118
|
|
|
109
119
|
def ruby_exe(code, opts = {})
|
|
110
|
-
|
|
120
|
+
env = opts[:env] || {}
|
|
111
121
|
working_dir = opts[:dir] || "."
|
|
112
122
|
Dir.chdir(working_dir) do
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
123
|
+
saved_env = {}
|
|
124
|
+
env.each do |key, value|
|
|
125
|
+
key = key.to_s
|
|
126
|
+
saved_env[key] = ENV[key] if ENV.key? key
|
|
127
|
+
ENV[key] = value
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
begin
|
|
131
|
+
`#{ruby_cmd(code, opts)}`
|
|
132
|
+
ensure
|
|
133
|
+
saved_env.each { |key, value| ENV[key] = value }
|
|
134
|
+
env.keys.each do |key|
|
|
135
|
+
key = key.to_s
|
|
136
|
+
ENV.delete key unless saved_env.key? key
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def ruby_cmd(code, opts = {})
|
|
143
|
+
body = code
|
|
144
|
+
|
|
145
|
+
if code and not File.exists?(code)
|
|
146
|
+
if opts[:escape]
|
|
147
|
+
code = "'#{code}'"
|
|
148
|
+
else
|
|
149
|
+
code = code.inspect
|
|
150
|
+
end
|
|
151
|
+
body = "-e #{code}"
|
|
116
152
|
end
|
|
153
|
+
|
|
154
|
+
[RUBY_EXE, ENV['RUBY_FLAGS'], opts[:options], body, opts[:args]].compact.join(' ')
|
|
117
155
|
end
|
|
118
156
|
|
|
119
157
|
unless Object.const_defined?(:RUBY_EXE) and RUBY_EXE
|