Skip to content

Commit

Permalink
Updated MSpec source to �[33m4d5.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yorick Peterse committed Dec 26, 2015
1 parent a2d2919 commit dfa4f06
Show file tree
Hide file tree
Showing 97 changed files with 834 additions and 865 deletions.
8 changes: 0 additions & 8 deletions mspec/lib/mspec/commands/mspec.rb
Expand Up @@ -37,10 +37,6 @@ def options(argv=ARGV)

options.targets

options.on("-D", "--gdb", "Run under gdb") do
config[:use_gdb] = true
end

options.on("-A", "--valgrind", "Run under valgrind") do
config[:use_valgrind] = true
end
Expand Down Expand Up @@ -162,12 +158,8 @@ def run
else
if config[:use_valgrind]
more = ["--child-silent-after-fork=yes",
"--db-attach=#{config[:use_gdb] ? 'yes' : 'no'}",
config[:target]] + argv
exec "valgrind", *more
elsif config[:use_gdb]
more = ["--args", config[:target]] + argv
exec "gdb", *more
else
cmd, *rest = config[:target].split(/\s+/)
argv = rest + argv unless rest.empty?
Expand Down
2 changes: 1 addition & 1 deletion mspec/lib/mspec/guards/block_device.rb
Expand Up @@ -2,7 +2,7 @@

class BlockDeviceGuard < SpecGuard
def match?
platform_is_not :freebsd, :windows do
platform_is_not :freebsd, :windows, :opal do
block = `find /dev /devices -type b 2> /dev/null`
return !(block.nil? || block.empty?)
end
Expand Down
4 changes: 4 additions & 0 deletions mspec/lib/mspec/guards/platform.rb
Expand Up @@ -5,6 +5,10 @@ def self.windows?
PlatformGuard.new(:os => :windows).match?
end

def self.opal?
PlatformGuard.new(:opal)
end

def initialize(*args)
if args.last.is_a?(Hash)
@options, @platforms = args.last, args[0..-2]
Expand Down
25 changes: 15 additions & 10 deletions mspec/lib/mspec/helpers/environment.rb
Expand Up @@ -2,27 +2,29 @@

class Object
def env
env = ""
if PlatformGuard.windows?
env = Hash[*`cmd.exe /C set`.split("\n").map { |e| e.split("=", 2) }.flatten]
Hash[*`cmd.exe /C set`.split("\n").map { |e| e.split("=", 2) }.flatten]
elsif PlatformGuard.opal?
{}
else
env = Hash[*`env`.split("\n").map { |e| e.split("=", 2) }.flatten]
Hash[*`env`.split("\n").map { |e| e.split("=", 2) }.flatten]
end
env
end

def windows_env_echo(var)
`cmd.exe /C ECHO %#{var}%`.strip
platform_is_not :opal do
`cmd.exe /C ECHO %#{var}%`.strip
end
end

def username
user = ""
if PlatformGuard.windows?
user = windows_env_echo('USERNAME')
windows_env_echo('USERNAME')
elsif PlatformGuard.opal?
""
else
user = `whoami`.strip
`whoami`.strip
end
user
end

def home_directory
Expand All @@ -41,7 +43,10 @@ def dev_null
def hostname
commands = ['hostname', 'uname -n']
commands.each do |command|
name = `#{command}`
name = ''
platform_is_not :opal do
name = `#{command}`
end
return name.strip if $?.success?
end
raise Exception, "hostname: unable to find a working command"
Expand Down
37 changes: 36 additions & 1 deletion mspec/lib/mspec/helpers/io.rb
@@ -1,14 +1,36 @@
require 'mspec/guards/feature'

class IOStub < String
class IOStub
def initialize
@buffer = []
@output = ''
end

def write(*str)
self << str.join
end

def << str
@buffer << str
self
end

def print(*str)
write(str.join + $\.to_s)
end

def method_missing(name, *args, &block)
to_s.send(name, *args, &block)
end

def == other
to_s == other
end

def =~ other
to_s =~ other
end

def puts(*str)
if str.empty?
write "\n"
Expand All @@ -22,8 +44,21 @@ def printf(format, *args)
end

def flush
@output += @buffer.join('')
@buffer.clear
self
end

def to_s
flush
@output
end

alias_method :to_str, :to_s

def inspect
to_s.inspect
end
end

class Object
Expand Down
4 changes: 3 additions & 1 deletion mspec/lib/mspec/helpers/mock_to_path.rb
@@ -1,6 +1,8 @@
require 'mspec/mocks/proxy'

class Object
def mock_to_path(path)
obj = mock('path')
obj = MockObject.new('path')
obj.should_receive(:to_path).and_return(path)
obj
end
Expand Down
2 changes: 1 addition & 1 deletion mspec/lib/mspec/helpers/numeric.rb
Expand Up @@ -18,7 +18,7 @@ def bignum_value(plus=0)
# values.
guard = SpecGuard.new

if guard.standard? or guard.implementation? :topaz
if guard.standard? or guard.implementation? :topaz or guard.implementation? :opal
if guard.wordsize? 32
def fixnum_max()
(2**30) - 1
Expand Down
15 changes: 11 additions & 4 deletions mspec/lib/mspec/helpers/ruby_exe.rb
Expand Up @@ -128,7 +128,9 @@ def ruby_exe(code, opts = {})
end

begin
`#{ruby_cmd(code, opts)}`
platform_is_not :opal do
`#{ruby_cmd(code, opts)}`
end
ensure
saved_env.each { |key, value| ENV[key] = value }
env.keys.each do |key|
Expand All @@ -144,11 +146,16 @@ def ruby_cmd(code, opts = {})

if code and not File.exist?(code)
if opts[:escape]
code = "'#{code}'"
heredoc_separator = "END_OF_RUBYCODE"
lines = code.lines
until lines.none? {|line| line.start_with? heredoc_separator }
heredoc_separator << heredoc_separator
end

body = %Q!-e "$(cat <<'#{heredoc_separator}'\n#{code}\n#{heredoc_separator}\n)"!
else
code = code.inspect
body = "-e #{code.inspect}"
end
body = "-e #{code}"
end

[RUBY_EXE, ENV['RUBY_FLAGS'], opts[:options], body, opts[:args]].compact.join(' ')
Expand Down
2 changes: 1 addition & 1 deletion mspec/lib/mspec/helpers/tmp.rb
Expand Up @@ -3,7 +3,7 @@
# should clean up any temporary files created so that the temp
# directory is empty when the process exits.

SPEC_TEMP_DIR = "#{File.expand_path(Dir.pwd)}/rubyspec_temp"
SPEC_TEMP_DIR = ENV["SPEC_TEMP_DIR"] || "#{File.expand_path(Dir.pwd)}/rubyspec_temp"

SPEC_TEMP_UNIQUIFIER = "0"

Expand Down
1 change: 1 addition & 0 deletions mspec/lib/mspec/matchers.rb
Expand Up @@ -36,3 +36,4 @@
require 'mspec/matchers/output_to_fd'
require 'mspec/matchers/respond_to'
require 'mspec/matchers/signed_zero'
require 'mspec/matchers/block_caller'
34 changes: 34 additions & 0 deletions mspec/lib/mspec/matchers/block_caller.rb
@@ -0,0 +1,34 @@
class BlockingMatcher
def initialize(timeout = 0.1)
@timeout = timeout
end

def matches?(block)
blocking = true

thread = Thread.new do
block.call

blocking = false
end

thread.join(@timeout)
thread.kill

blocking
end

def failure_message
['Expected the given Proc', 'to block the caller']
end

def negative_failure_message
['Expected the given Proc', 'to not block the caller']
end
end

class Object
def block_caller(timeout = 0.1)
BlockingMatcher.new(timeout)
end
end
12 changes: 6 additions & 6 deletions mspec/lib/mspec/matchers/output.rb
Expand Up @@ -42,20 +42,20 @@ def failure_message
expected_out = "\n"
actual_out = "\n"
unless @out.nil?
expected_out << " $stdout: #{@out.inspect}\n"
actual_out << " $stdout: #{@stdout.chomp.inspect}\n"
expected_out += " $stdout: #{@out.inspect}\n"
actual_out += " $stdout: #{@stdout.inspect}\n"
end
unless @err.nil?
expected_out << " $stderr: #{@err.inspect}\n"
actual_out << " $stderr: #{@stderr.chomp.inspect}\n"
expected_out += " $stderr: #{@err.inspect}\n"
actual_out += " $stderr: #{@stderr.inspect}\n"
end
["Expected:#{expected_out}", " got:#{actual_out}"]
end

def negative_failure_message
out = ""
out << " $stdout: #{@stdout.chomp.dump}\n" unless @out.nil?
out << " $stderr: #{@stderr.chomp.dump}\n" unless @err.nil?
out += " $stdout: #{@stdout.chomp.dump}\n" unless @out.nil?
out += " $stderr: #{@stderr.chomp.dump}\n" unless @err.nil?
["Expected output not to be:\n", out]
end
end
Expand Down
8 changes: 4 additions & 4 deletions mspec/lib/mspec/mocks/mock.rb
Expand Up @@ -62,11 +62,11 @@ def self.install_method(obj, sym, type=nil)
meta.__send__ :alias_method, key.first, sym
end

meta.class_eval <<-END
def #{sym}(*args, &block)
Mock.verify_call self, :#{sym}, *args, &block
meta.class_eval {
define_method(sym) do |*args, &block|
Mock.verify_call self, sym, *args, &block
end
END
}

proxy = MockProxy.new type

Expand Down
1 change: 0 additions & 1 deletion mspec/lib/mspec/runner/actions.rb
Expand Up @@ -4,4 +4,3 @@
require 'mspec/runner/actions/tag'
require 'mspec/runner/actions/taglist'
require 'mspec/runner/actions/tagpurge'
require 'mspec/runner/actions/gdb'
17 changes: 0 additions & 17 deletions mspec/lib/mspec/runner/actions/gdb.rb

This file was deleted.

8 changes: 6 additions & 2 deletions mspec/lib/mspec/runner/actions/timer.rb
Expand Up @@ -5,11 +5,11 @@ def register
end

def start
@start = Time.now
@start = current_time
end

def finish
@stop = Time.now
@stop = current_time
end

def elapsed
Expand All @@ -19,4 +19,8 @@ def elapsed
def format
"Finished in %f seconds" % elapsed
end

def current_time
Time.now
end
end
2 changes: 1 addition & 1 deletion mspec/lib/mspec/runner/context.rb
Expand Up @@ -6,7 +6,7 @@
#--
# A note on naming: this is named _ContextState_ rather
# than _DescribeState_ because +describe+ is the keyword
# in the DSL for refering to the context in which an example
# in the DSL for referring to the context in which an example
# is evaluated, just as +it+ refers to the example itself.
#++
class ContextState
Expand Down
4 changes: 2 additions & 2 deletions mspec/lib/mspec/runner/exception.rb
Expand Up @@ -6,8 +6,8 @@ def initialize(state, location, exception)

@description = location ? "An exception occurred during: #{location}" : ""
if state
@description << "\n" unless @description.empty?
@description << state.description
@description += "\n" unless @description.empty?
@description += state.description
@describe = state.describe
@it = state.it
else
Expand Down

3 comments on commit dfa4f06

@heftig
Copy link
Contributor

@heftig heftig commented on dfa4f06 Dec 26, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the ANSI escape doing in the commit subject?

@yorickpeterse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@heftig I think that's because I have colours enabled when running git log.

@yorickpeterse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1142534

Please sign in to comment.