Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix tests & use rubyspecs

  • Loading branch information...
commit 120a57c6041c383a7aa90e16da087f71a325b784 1 parent 846bd09
@marcandre authored
View
2  .gitignore
@@ -5,4 +5,4 @@ coverage
rdoc
pkg
assets
-rs
+rs
View
3  .gitmodules
@@ -0,0 +1,3 @@
+[submodule "rubyspec"]
+ path = rubyspec
+ url = git://github.com/rubyspec/rubyspec.git
View
4 .travis.yml
@@ -9,6 +9,7 @@ rvm:
- jruby-19mode
- rbx-18mode
- rbx-19mode
+
matrix:
allow_failures:
- rvm: "2.0.0" # Must wait for 2.0.0p0...
@@ -16,3 +17,6 @@ matrix:
- rvm: jruby-19mode
- rvm: rbx-18mode
- rvm: rbx-19mode
+
+before_install:
+ - git submodule update --init --recursive
View
1  Gemfile
@@ -8,6 +8,7 @@ gemspec
# jquery-rails is used by the dummy application
group :test do
gem "rake"
+ gem 'mspec', :git => 'git://github.com/rubyspec/mspec.git'
end
# Declare any dependencies that are still in development here instead of in
View
8 Gemfile.lock
@@ -1,3 +1,9 @@
+GIT
+ remote: git://github.com/rubyspec/mspec.git
+ revision: 69c388b1187789f4996eda7dec4c1404fcd6b742
+ specs:
+ mspec (1.5.18)
+
PATH
remote: .
specs:
@@ -10,7 +16,9 @@ GEM
PLATFORMS
java
+ ruby
DEPENDENCIES
backports!
+ mspec!
rake
View
102 Rakefile
@@ -1,7 +1,7 @@
begin
require "bundler/gem_tasks"
rescue LoadError
- warn "bundler not installed"
+ # bundler not installed
end
require 'rake/testtask'
@@ -10,4 +10,102 @@ Rake::TestTask.new(:test) do |test|
test.pattern = 'test/**/*_test.rb'
test.verbose = false
end
-task :default => :test
+
+task :spec, :path, :action do |t, args|
+ args.with_defaults(:path => '*/*', :action => 'ci')
+ stats = [[0] * 5]
+ not_found = []
+ mspec_cmds(args[:path], args[:action]) do |cmd, path|
+ result = `#{cmd}`
+ match = result.match(/(\d+) files?, (\d+) examples?, (\d+) expectations?, (\d+) failures?, (\d+) errors?/)
+ if match.nil?
+ puts "*** mspec returned with unexpected results:"
+ puts result
+ puts "Command was:", cmd
+ puts "Mspec version: " + `mspec --version`
+ puts "Testing basic mspec:", `mspec rubyspec/core/array/append_spec.rb`
+ puts "Testing basic mspec:", `mspec ci rubyspec/core/array/append_spec.rb`
+ puts "Testing basic mspec:", `mspec ci -r rbconfig rubyspec/core/array/append_spec.rb`
+ puts "Testing basic mspec:", `mspec ci -r rbconfig -I lib -r set_version/2.0.0 rubyspec/core/array/append_spec.rb`
+ puts "Testing basic mspec:", `mspec ci -r rbconfig -I lib -r set_version/2.0.0 -r backports/2.0.0/nil/to_h rubyspec/core/array/append_spec.rb`
+ fail "Unexpected output from mspec"
+ end
+ _, ex, p, f, e = data = match.captures.map{|x| x.to_i}
+ not_found << path if ex == 0
+ stats << data
+ if f + e > 0
+ puts cmd
+ puts result
+ else
+ print "."
+ STDOUT.flush
+ end
+ end
+ $:.unshift 'lib'
+ require 'backports/rails'
+ _, ex, p, f, e = stats = stats.transpose.map{|x| x.sum}
+ puts "*** Overall:", stats.zip(%w[files examples expectations failures errors]).map{|a| a.join(' ')}.join(', ')
+ puts "No spec found for #{not_found.join(', ')}" unless not_found.empty?
+ fail unless f + e == 0
+end
+
+task :all_spec do # Necessary because of argument passing bug in 1.8.7
+ Rake::Task[:spec].invoke('nil/*')
+end
+
+task :spec_tag, :path do |t, args|
+ Rake::Task[:spec].invoke(args[:path], 'tag -G fails')
+end
+
+task :default => [:test, :all_spec]
+
+DEPENDENCIES = Hash.new([]).merge!(
+ '1.8.7/argf/chars' => 'backports/1.8.7/string/each_char',
+ '1.8.7/argf/each_char' => 'backports/1.8.7/string/each_char',
+ '1.8.7/array/cycle' => 'backports/1.8.7/stop_iteration',
+ '1.8.7/enumerable/entries' => ['backports/1.8.7/enumerable/each_with_index', 'backports/1.8.7/enumerable/to_a'],
+ '1.8.7/enumerator/rewind' => 'backports/1.8.7/enumerator/next',
+ '1.8.7/hash/reject' => 'backports/1.8.7/integer/even',
+ '1.9.1/hash/rassoc' => 'backports/1.8.7/hash/key',
+ '1.9.1/proc/lambda' => 'backports/1.9.1/proc/curry',
+ '1.9.2/complex/to_r' => 'complex',
+ '1.9.2/array/select' => 'backports/1.8.7/array/select',
+ '1.9.2/hash/select' => 'backports/1.8.7/hash/select',
+ '1.9.2/enumerable/each_entry' => 'backports/1.8.7/enumerable/each_with_index',
+ '2.0.0/hash/to_h' => 'backports/1.9.1/hash/default_proc'
+)
+{
+ :each_with_index => %w[enumerable/detect enumerable/find enumerable/find_all enumerable/select enumerable/to_a],
+ :first => %w[enumerable/cycle io/bytes io/chars io/each_byte io/each_char io/lines io/each_line]
+}.each do |req, libs|
+ libs.each{|l| DEPENDENCIES["1.8.7/#{l}"] = "backports/1.8.7/enumerable/#{req}" }
+end
+
+# These cause actual errors while loading in 1.8:
+IGNORE_IN_18 = %w[
+ 1.9.1/symbol/length
+ 1.9.1/symbol/size
+ 1.9.3/string/byteslice
+ 1.8.7/proc/yield
+ 1.9.1/proc/case_compare
+]
+def mspec_cmds(pattern, action='ci')
+ pattern = "lib/backports/*.*.*/#{pattern}.rb"
+ Dir.glob(pattern) do |lib_path|
+ _match, version, path = lib_path.match(/backports\/(\d\.\d\.\d)\/(.*)\.rb/).to_a
+ next if path =~ /stdlib/
+ next if version <= RUBY_VERSION
+ version_path = "#{version}/#{path}"
+ next if IGNORE_IN_18.include? version_path if RUBY_VERSION < '1.9'
+ deps = [*DEPENDENCIES[version_path]].map{|p| "-r #{p}"}.join(' ')
+ klass, method = path.split('/')
+ path = [klass.gsub('_', ''), method].join('/') # don't ask me why RubySpec uses matchdata instead of match_data
+ yield %W[mspec #{action}
+ -I lib
+ -r ./set_version/#{version}
+ #{deps}
+ -r backports/#{version_path}
+ rubyspec/core/#{path}_spec.rb
+ ].join(' '), path
+ end
+end
View
9 default.mspec
@@ -0,0 +1,9 @@
+if (Backports::TARGET_VERSION rescue false) # Conf loaded at different times, not sure why
+ class MSpecScript
+ # The set of substitutions to transform a spec filename
+ # into a tag filename.
+ set :tags_patterns, [ [%r(rubyspec/), "tags/#{RUBY_VERSION}/"] ]
+ end
+
+ SpecGuard.ruby_version_override = Backports::TARGET_VERSION if Backports::TARGET_VERSION > RUBY_VERSION
+end
1  rubyspec
@@ -0,0 +1 @@
+Subproject commit 5164363092c30689b9e7dcef2e391b95fde9fbb8
View
1  set_version/1.8.7.rb
@@ -0,0 +1 @@
+require File.expand_path(File.dirname(__FILE__) + "/setter")
View
1  set_version/1.9.1.rb
@@ -0,0 +1 @@
+require File.expand_path(File.dirname(__FILE__) + "/setter")
View
1  set_version/1.9.2.rb
@@ -0,0 +1 @@
+require File.expand_path(File.dirname(__FILE__) + "/setter")
View
1  set_version/1.9.3.rb
@@ -0,0 +1 @@
+require File.expand_path(File.dirname(__FILE__) + "/setter")
View
1  set_version/2.0.0.rb
@@ -0,0 +1 @@
+require File.expand_path(File.dirname(__FILE__) + "/setter")
View
14 set_version/setter.rb
@@ -0,0 +1,14 @@
+module Backports
+ TARGET_VERSION = caller.each{|c| break $1 if c =~ /set_version\/(\d\.\d\.\d)\.rb/}
+end
+
+unless Object.const_defined?(:Enumerator) || Backports::TARGET_VERSION < '1.9'
+ require 'enumerator'
+ # Needed for mspec:
+ Enumerator = Enumerable::Enumerator
+end
+
+if RUBY_VERSION < Backports::TARGET_VERSION && Backports::TARGET_VERSION >= '1.9'
+ require 'backports/1.9.2/float/infinity.rb' # Used in many specs...
+ require 'backports/1.9.2/float/nan.rb' # Used in many specs...
+end
View
2  test/README
@@ -10,4 +10,4 @@ For example:
This will run the specs for Range#cover for Ruby 1.8.7 after loading backports.
-You need to check which tests fail to decide if it's OK that they do or not. For example it is to be expected that specs checking for encoding behavior will fail, as backports does not support the Ruby 1.9 encoding functionality.
+You need to check which tests fail to decide if it's OK that they do or not. For example it is to be expected that specs checking for encoding behavior will fail, as backports does not support the Ruby 1.9 encoding functionality.
View
15 test/_backport_guards_test.rb
@@ -22,7 +22,6 @@ def require_with_bogus_extension(lib)
class AAA_TestBackportGuards < Test::Unit::TestCase
def setup
- # Don't call super, to override test/helper's definition, do not require backports yet
$VERBOSE = true
@prev, $stderr = $stderr, StringIO.new
end
@@ -76,18 +75,20 @@ def digest_delta(before, after)
# Order super important!
def test__1_abbrev_can_be_required_before_backports
- assert require 'abbrev'
+ assert require('abbrev')
assert !$LOADED_FEATURES.include?('backports')
end
# Order super important!
def test__2_backports_wont_override_unnecessarily
before = digest
- require "./lib/backports/#{RUBY_VERSION}"
- after = digest
- assert_nil digest_delta(before, after)
+ unless RUBY_VERSION <= '1.8.6'
+ require "backports/#{RUBY_VERSION}"
+ after = digest
+ assert_nil digest_delta(before, after)
+ end
unless RUBY_VERSION == "2.0.0"
- require "./lib/backports"
+ require "backports"
after = digest
assert !digest_delta(before, after).nil?
end
@@ -125,6 +126,8 @@ def test_load_correctly_new_libraries_test
def test_no_warnings
require 'ostruct'
require 'set'
+ require 'backports/1.8.7/array/each'
+ require 'backports/1.8.7/enumerator/next'
assert_equal 1, [1,2,3].each.next # [Bug #70]
end
end
View
26 test/lazy_test.rb
@@ -2,6 +2,12 @@
require './test/test_helper'
class TestLazyEnumerator < Test::Unit::TestCase
+ def setup
+ require "backports/2.0.0/enumerable/lazy"
+ require "backports/1.8.7/enumerable"
+ require "backports/1.8.7/io/each"
+ end
+
class Step
include Enumerable
attr_reader :current, :args
@@ -101,7 +107,7 @@ def test_flat_map
assert_equal(3, a.current)
assert_equal(2, a.lazy.flat_map {|x| [x * 2]}.first)
assert_equal(1, a.current)
- end
+ end if [].respond_to?(:flat_map)
def test_flat_map_nested
a = Step.new(1..3)
@@ -111,7 +117,7 @@ def test_flat_map_nested
assert_equal([1, "a"],
a.lazy.flat_map {|x| ("a".."c").lazy.map {|y| [x, y]}}.first)
assert_equal(1, a.current)
- end
+ end if [].respond_to?(:flat_map)
def test_flat_map_to_ary
to_ary = Class.new {
@@ -127,17 +133,17 @@ def to_ary
[1, 2, 3].flat_map {|x| to_ary.new(x)})
assert_equal([:to_ary, 1, :to_ary, 2, :to_ary, 3],
[1, 2, 3].lazy.flat_map {|x| to_ary.new(x)}.force)
- end
+ end if [].respond_to?(:flat_map)
def test_flat_map_non_array
assert_equal(["1", "2", "3"], [1, 2, 3].flat_map {|x| x.to_s})
assert_equal(["1", "2", "3"], [1, 2, 3].lazy.flat_map {|x| x.to_s}.force)
- end
+ end if [].respond_to?(:flat_map)
def test_flat_map_hash
assert_equal([{?a=>97}, {?b=>98}, {?c=>99}], [?a, ?b, ?c].flat_map {|x| {x=>x.ord}})
assert_equal([{?a=>97}, {?b=>98}, {?c=>99}], [?a, ?b, ?c].lazy.flat_map {|x| {x=>x.ord}}.force)
- end
+ end if [].respond_to?(:flat_map)
def test_reject
a = Step.new(1..6)
@@ -332,14 +338,14 @@ def test_drop_while
end
def test_drop_and_take
- assert_equal([4, 5], (1..Float::INFINITY).lazy.drop(3).take(2).to_a)
+ assert_equal([4, 5], (1..(1.0/0)).lazy.drop(3).take(2).to_a) # Backports: don't rely on INFINITY
end
def test_cycle
a = Step.new(1..3)
- assert_equal("1", a.cycle(2).map(&:to_s).first)
+ assert_equal("1", a.cycle(2).map{|x| x.to_s}.first)
assert_equal(3, a.current)
- assert_equal("1", a.lazy.cycle(2).map(&:to_s).first)
+ assert_equal("1", a.lazy.cycle(2).map{|x| x.to_s}.first)
assert_equal(1, a.current)
end
@@ -387,7 +393,7 @@ def test_inspect
assert_equal(<<EOS.chomp, l.inspect)
#<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 1..10>:map>:map>:flat_map>:flat_map>:select>:select>:reject>:grep(1)>:zip("a".."c")>:take(10)>:take_while>:drop(3)>:drop_while>:cycle(3)>
EOS
- end
+ end if [].respond_to?(:flat_map)
def test_lazy_to_enum
lazy = [1, 2, 3].lazy
@@ -464,7 +470,7 @@ def test_laziness_conservation
:each_entry => [],
:each_cons => 42,
}.each do |method, arg|
- assert_equal Enumerator::Lazy, [].lazy.send(method, *arg).class, bug7507
+ assert_equal Enumerator::Lazy, [].lazy.send(method, *arg).class, method if [].respond_to?(method)
end
assert_equal Enumerator::Lazy, [].lazy.chunk{}.class, bug7507
end
View
1  test/socket_interaction_test.rb
@@ -2,6 +2,7 @@
class TestSocketInteraction < Test::Unit::TestCase
def test_interaction # Issue #67
+ require 'backports'
require 'socket'
assert_equal nil, UDPSocket.open{}
end
View
6 test/test_helper.rb
@@ -1,7 +1 @@
require 'test/unit'
-
-class Test::Unit::TestCase
- def setup
- require "./lib/backports"
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.