Permalink
Browse files

fixing tests to run with newer versions of ruby

  • Loading branch information...
1 parent a18e6e3 commit 962d56cba3a132d590be1dd062f2a3a2efa48545 @mmaiza mmaiza committed Feb 8, 2013
Showing with 43 additions and 37 deletions.
  1. +2 −2 test/Draw.rb
  2. +5 −4 test/Image1.rb
  3. +5 −5 test/Image2.rb
  4. +6 −5 test/Image3.rb
  5. +3 −3 test/ImageList1.rb
  6. +2 −2 test/ImageList2.rb
  7. +6 −5 test/Image_attributes.rb
  8. +2 −2 test/Import_Export.rb
  9. +1 −1 test/Info.rb
  10. +2 −2 test/Magick.rb
  11. +1 −1 test/Pixel.rb
  12. +3 −3 test/Preview.rb
  13. +5 −2 test/all_basic.rb
View
@@ -3,7 +3,7 @@
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
class Magick::Draw
def self._dummy_img_
@@ -116,6 +116,6 @@ def test_patterns
end
if __FILE__ == $0
-Test::Unit::UI::Console::TestRunner.run(Draw_UT) if RUBY_VERSION != '1.9.1'
+Test::Unit::UI::Console::TestRunner.run(Draw_UT) if !RUBY_VERSION[/^1\.9|^2/]
end
View
@@ -2,11 +2,11 @@
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
class Image1_UT < Test::Unit::TestCase
- FreezeError = RUBY_VERSION == '1.9.1' ? RuntimeError : TypeError
+ FreezeError = RUBY_VERSION[/^1\.9|^2/] ? RuntimeError : TypeError
def setup
@img = Magick::Image.new(20, 20)
@@ -746,7 +746,8 @@ def test_composite
assert_raise(TypeError) { img1.composite(img2, 0, 0, 2, Magick::OverCompositeOp) }
# negative offsets raise an exception
- assert_raise(Magick::ImageMagickError) { img1.composite(img2, -10, -10, Magick::OverCompositeOp) }
+ # No longer true, negative offset are accepted as virtual pixels
+ #assert_raise(Magick::ImageMagickError) { img1.composite(img2, -10, -10, Magick::OverCompositeOp) }
img2.destroy!
assert_raise(Magick::DestroyedImageError) { img1.composite(img2, Magick::CenterGravity, Magick::OverCompositeOp) }
@@ -758,5 +759,5 @@ def test_composite
if __FILE__ == $0
IMAGES_DIR = '../doc/ex/images'
FILES = Dir[IMAGES_DIR+'/Button_*.gif']
-Test::Unit::UI::Console::TestRunner.run(Image1_UT) if RUBY_VERSION != '1.9.1'
+Test::Unit::UI::Console::TestRunner.run(Image1_UT) if !RUBY_VERSION[/^1\.9|^2/]
end
View
@@ -2,13 +2,13 @@
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
# TODO: improve exif tests - need a benchmark image with EXIF data
class Image2_UT < Test::Unit::TestCase
- FreezeError = RUBY_VERSION == '1.9.1' ? RuntimeError : TypeError
+ FreezeError = RUBY_VERSION[/^1\.9|^2/] ? RuntimeError : TypeError
def setup
@img = Magick::Image.new(20, 20)
@@ -254,7 +254,7 @@ def test_despeckle
# ensure methods detect destroyed images
def test_destroy
methods = Magick::Image.instance_methods(false).sort
- if RUBY_VERSION == '1.9.1'
+ if RUBY_VERSION[/^1\.9|^2/]
methods -= [:__display__, :destroy!, :destroyed?, :inspect, :cur_image, :marshal_load]
else
methods -= %w{ __display__ destroy! destroyed? inspect cur_image marshal_load}
@@ -582,7 +582,7 @@ def test_export_pixels_to_str
end
assert_nothing_raised do
res = @img.export_pixels_to_str(0, 0, 10, 10, "I", Magick::LongPixel)
- assert_equal(10*10*4, res.length)
+ assert_equal(10*10*8, res.length)
end
assert_nothing_raised do
res = @img.export_pixels_to_str(0, 0, 10, 10, "I", Magick::FloatPixel)
@@ -1304,5 +1304,5 @@ def test_posterize
if __FILE__ == $0
IMAGES_DIR = '../doc/ex/images'
FILES = Dir[IMAGES_DIR+'/Button_*.gif']
-Test::Unit::UI::Console::TestRunner.run(Image2_UT) if RUBY_VERSION != '1.9.1'
+Test::Unit::UI::Console::TestRunner.run(Image2_UT) if !RUBY_VERSION[/^1\.9|^2/]
end
View
@@ -2,7 +2,7 @@
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
require 'fileutils'
ColorspaceTypes = [
@@ -33,18 +33,19 @@
class Image3_UT < Test::Unit::TestCase
- FreezeError = RUBY_VERSION == '1.9.1' ? RuntimeError : TypeError
+ FreezeError = RUBY_VERSION[/^1\.9|^2/] ? RuntimeError : TypeError
def setup
@img = Magick::Image.new(20, 20)
+ @p = Magick::Image.read(IMAGE_WITH_PROFILE).first.color_profile
end
def test_profile!
assert_nothing_raised do
res = @img.profile!('*', nil)
assert_same(@img, res)
end
- assert_nothing_raised { @img.profile!('icc', 'xxx') }
+ assert_nothing_raised { @img.profile!('icc', @p) }
assert_nothing_raised { @img.profile!('iptc', 'xxx') }
assert_nothing_raised { @img.profile!('icc', nil) }
assert_nothing_raised { @img.profile!('iptc', nil) }
@@ -997,5 +998,5 @@ def test_write
if __FILE__ == $0
IMAGES_DIR = '../doc/ex/images'
FILES = Dir[IMAGES_DIR+'/Button_*.gif']
-Test::Unit::UI::Console::TestRunner.run(Image3_UT) if RUBY_VERSION != '1.9.1'
-end
+Test::Unit::UI::Console::TestRunner.run(Image3_UT) if !RUBY_VERSION[/^1\.9|^2/]
+end
View
@@ -2,7 +2,7 @@
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
class ImageList1_UT < Test::Unit::TestCase
@@ -500,7 +500,7 @@ def test_map!
assert_raise(ArgumentError) { @list.map! { 2 } }
end
- if RUBY_VERSION != '1.9.1'
+ if !RUBY_VERSION[/^1\.9|^2/]
def test_nitems
n = nil
assert_nothing_raised { n = @list.nitems }
@@ -804,5 +804,5 @@ def test_spaceship
if __FILE__ == $0
IMAGES_DIR = '../doc/ex/images'
FILES = Dir[IMAGES_DIR+'/Button_*.gif'].sort
-Test::Unit::UI::Console::TestRunner.run(ImageList1_UT) if RUBY_VERSION != '1.9.1'
+Test::Unit::UI::Console::TestRunner.run(ImageList1_UT) if !RUBY_VERSION[/^1\.9|^2/]
end
View
@@ -4,7 +4,7 @@
require 'fileutils'
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
class ImageList2_UT < Test::Unit::TestCase
@@ -385,5 +385,5 @@ def test_write
if __FILE__ == $0
IMAGES_DIR = '../doc/ex/images'
FLOWER_HAT = IMAGES_DIR+'/Flower_Hat.jpg'
-Test::Unit::UI::Console::TestRunner.run(ImageList2_UT) if RUBY_VERSION != '1.9.1'
+Test::Unit::UI::Console::TestRunner.run(ImageList2_UT) if !RUBY_VERSION[/^1\.9|^2/]
end
View
@@ -3,7 +3,7 @@
require 'fileutils'
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
# TODO
# test frozen attributes!
@@ -12,7 +12,7 @@
class Image_Attributes_UT < Test::Unit::TestCase
- FreezeError = RUBY_VERSION == '1.9.1' ? RuntimeError : TypeError
+ FreezeError = RUBY_VERSION[/^1\.9|^2/] ? RuntimeError : TypeError
def setup
@img = Magick::Image.new(100, 100)
@@ -23,6 +23,7 @@ def setup
gc.draw(@img)
@hat = Magick::Image.read(FLOWER_HAT).first
+ @p = Magick::Image.read(IMAGE_WITH_PROFILE).first.color_profile
end
# Test old alpha attribute. New alpha() behavior is tested in Image1.rb
@@ -145,8 +146,8 @@ def test_class_type
def test_color_profile
assert_nothing_raised { @img.color_profile }
assert_nil(@img.color_profile)
- assert_nothing_raised { @img.color_profile = 'xxx' }
- assert_equal('xxx', @img.color_profile)
+ assert_nothing_raised { @img.color_profile = @p }
+ assert_equal(@p, @img.color_profile)
assert_raise(TypeError) { @img.color_profile = 2 }
end
@@ -678,5 +679,5 @@ def test_frozen
if __FILE__ == $0
FLOWER_HAT = '../doc/ex/images/Flower_Hat.jpg'
-Test::Unit::UI::Console::TestRunner.run(Image_Attributes_UT) if RUBY_VERSION != '1.9.1'
+Test::Unit::UI::Console::TestRunner.run(Image_Attributes_UT) if !RUBY_VERSION[/^1\.9|^2/]
end
View
@@ -1,6 +1,6 @@
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
class Import_Export_UT < Test::Unit::TestCase
@@ -111,6 +111,6 @@ def test_import_export
if __FILE__ == $0
IMAGES_DIR = '../doc/ex/images'
-Test::Unit::UI::Console::TestRunner.run(Import_Export_UT) if RUBY_VERSION != '1.9.1'
+Test::Unit::UI::Console::TestRunner.run(Import_Export_UT) if !RUBY_VERSION[/^1\.9|^2/]
end
View
@@ -3,7 +3,7 @@
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
class Info_UT < Test::Unit::TestCase
View
@@ -3,7 +3,7 @@
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
module Magick
@@ -359,6 +359,6 @@ def test_trace_proc
end
if __FILE__ == $0
-Test::Unit::UI::Console::TestRunner.run(Magick_UT) if RUBY_VERSION != '1.9.1'
+Test::Unit::UI::Console::TestRunner.run(Magick_UT) if !RUBY_VERSION[/^1\.9|^2/]
end
View
@@ -2,7 +2,7 @@
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
class Pixel_UT < Test::Unit::TestCase
View
@@ -2,7 +2,7 @@
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
class Preview_UT < Test::Unit::TestCase
@@ -47,7 +47,7 @@ def test_preview
puts "\n"
preview_types.each do |type|
puts "testing #{type.to_s}..."
- assert_nothing_raised { prev = hat.preview(type) }
+ assert_nothing_raised { hat.preview(type) }
end
assert_raise(TypeError) { hat.preview(2) }
end
@@ -57,6 +57,6 @@ def test_preview
if __FILE__ == $0
IMAGES_DIR = '../doc/ex/images'
-Test::Unit::UI::Console::TestRunner.run(Preview_UT) if RUBY_VERSION != '1.9.1'
+Test::Unit::UI::Console::TestRunner.run(Preview_UT) if !RUBY_VERSION[/^1\.9|^2/]
end
View
@@ -1,15 +1,17 @@
#! /usr/local/bin/ruby -w
require 'RMagick'
require 'test/unit'
-require 'test/unit/ui/console/testrunner' if RUBY_VERSION != '1.9.1'
+require 'test/unit/ui/console/testrunner' if !RUBY_VERSION[/^1\.9|^2/]
+puts RUBY_VERSION
+puts RUBY_VERSION.class
module Test
module Unit
class TestCase
alias :_old_run_ :run
def run(result, &blk)
- method_name = RUBY_VERSION == '1.9.1' ? self.name : @method_name
+ method_name = RUBY_VERSION[/^1\.9|^2/] ? self.__name__ : @method_name
puts "Running #{method_name}"
_old_run_(result, &blk)
end
@@ -23,6 +25,7 @@ def run(result, &blk)
IMAGES_DIR = '../doc/ex/images'
FILES = Dir[IMAGES_DIR+'/Button_*.gif'].sort
FLOWER_HAT = IMAGES_DIR+'/Flower_Hat.jpg'
+IMAGE_WITH_PROFILE = IMAGES_DIR+'/image_with_profile.jpg'
require 'Image1.rb'
require 'Image2.rb'

0 comments on commit 962d56c

Please sign in to comment.