[macruby-changes] [792] MacRuby/trunk/test-macruby

source_changes at macosforge.org source_changes at macosforge.org
Thu Jan 15 07:28:58 PST 2009


Revision: 792
          http://trac.macosforge.org/projects/ruby/changeset/792
Author:   eloy.de.enige at gmail.com
Date:     2009-01-15 07:28:56 -0800 (Thu, 15 Jan 2009)
Log Message:
-----------
Started refactoring test cases and turning them into ?\226?\128?\152specs?\226?\128?\153.

Modified Paths:
--------------
    MacRuby/trunk/test-macruby/runner.rb

Added Paths:
-----------
    MacRuby/trunk/test-macruby/cases/
    MacRuby/trunk/test-macruby/cases/boxed_test.rb
    MacRuby/trunk/test-macruby/cases/framework_test.rb
    MacRuby/trunk/test-macruby/cases/hash_test.rb
    MacRuby/trunk/test-macruby/cases/objc_ext_test.rb
    MacRuby/trunk/test-macruby/cases/objc_test.rb
    MacRuby/trunk/test-macruby/cases/rubycocoa_test_disabled.rb
    MacRuby/trunk/test-macruby/cases/string_test.rb
    MacRuby/trunk/test-macruby/fixtures/
    MacRuby/trunk/test-macruby/fixtures/PureObjCSubclass.m
    MacRuby/trunk/test-macruby/known_bugs/
    MacRuby/trunk/test-macruby/known_bugs/extconf.rb
    MacRuby/trunk/test-macruby/known_bugs/known_bugs.rb
    MacRuby/trunk/test-macruby/known_bugs/known_bugs_in_c.c
    MacRuby/trunk/test-macruby/test_helper/
    MacRuby/trunk/test-macruby/test_helper/objective-c_helper.rb
    MacRuby/trunk/test-macruby/test_helper/temp_dir_helper.rb
    MacRuby/trunk/test-macruby/test_helper/test_unit_helper.rb
    MacRuby/trunk/test-macruby/test_helper.rb

Removed Paths:
-------------
    MacRuby/trunk/test-macruby/extconf.rb
    MacRuby/trunk/test-macruby/known_bugs.rb
    MacRuby/trunk/test-macruby/known_bugs_in_c.c
    MacRuby/trunk/test-macruby/rubycocoa_test.rb
    MacRuby/trunk/test-macruby/test_boxed.rb
    MacRuby/trunk/test-macruby/test_framework.rb
    MacRuby/trunk/test-macruby/test_hash.rb
    MacRuby/trunk/test-macruby/test_objc.rb
    MacRuby/trunk/test-macruby/test_objc_ext.rb
    MacRuby/trunk/test-macruby/test_string.rb

Property Changed:
----------------
    MacRuby/trunk/test-macruby/


Property changes on: MacRuby/trunk/test-macruby
___________________________________________________________________
Added: svn:ignore
   + tmp


Copied: MacRuby/trunk/test-macruby/cases/boxed_test.rb (from rev 789, MacRuby/trunk/test-macruby/test_boxed.rb)
===================================================================
--- MacRuby/trunk/test-macruby/cases/boxed_test.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/cases/boxed_test.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,182 @@
+#!/usr/bin/env macruby
+
+require File.expand_path('../../test_helper', __FILE__)
+
+class TestBS < Test::Unit::TestCase
+
+  def setup
+    framework 'Foundation'
+    bundle = '/tmp/_test_bs.bundle'
+    if !File.exist?(bundle) or File.mtime(bundle) < File.mtime(__FILE__)
+      s = <<EOS
+#import <Foundation/Foundation.h>
+ at interface NSObject (MacRubyNSPointAdditions)
+- (float)x;
+- (float)y;
+ at end
+ at interface TestBoxed : NSObject
+ at end
+ at implementation TestBoxed
+- (void)testPoint:(NSPoint)point x:(float)x y:(float)y
+{
+    if (point.x != x)
+        [NSException raise:@"NSException"
+            format:@"point.x (%f) != x (%f)", point.x, x];
+  
+    if (point.y != y) 
+        [NSException raise:@"NSException"
+            format:@"point.y (%f) != y (%f)", point.y, y];
+}
+- (void)testPointAsObject:(id)point x:(float)x y:(float)y
+{
+    Class boxed;
+    boxed = NSClassFromString(@"Boxed");
+
+    if (![point isKindOfClass:boxed]) 
+        [NSException raise:@"NSException"
+            format:@"point (%@) isn't a boxed type", point];
+
+    if (![point isKindOfClass:[NSValue class]]) 
+        [NSException raise:@"NSException"
+            format:@"point (%@) isn't a value type", point];
+
+#if 0 // FIXME this cannot be tested yet 
+    if ([point x] != x)       
+        [NSException raise:@"NSException"
+            format:@"[point x] (%f) != x (%f)", [point x], x];
+
+    if ([point y] != y)       
+        [NSException raise:@"NSException"
+            format:@"[point y] (%f) != y (%f)", [point y], y];
+#endif
+
+    if (strcmp([point objCType], @encode(NSPoint)) != 0)
+        [NSException raise:@"NSException"
+            format:@"[point objCType] (%s) != @encode(NSPoint) (%s)", 
+	    [point objCType], @encode(NSPoint)];
+
+    NSPoint p;
+    [point getValue:&p];
+    [self testPoint:p x:x y:y];   
+}
+- (NSPoint)testReturnPointWithX:(float)x y:(float)y
+{
+    NSPoint p;
+    p.x = x;
+    p.y = y;
+    return p;
+}
+ at end
+EOS
+      File.open('/tmp/_test.m', 'w') { |io| io.write(s) }
+      system("gcc /tmp/_test.m -bundle -o #{bundle} -framework Foundation -fobjc-gc-only") or exit 1
+    end
+    require 'dl'; DL.dlopen(bundle)
+  end
+  
+  def test_boxed_classes
+    assert_kind_of(Class, Boxed)
+    assert_equal(NSValue, Boxed.superclass)
+
+    # struct
+    assert(NSRect.ancestors.include?(Boxed))
+    assert('{_NSRect={_NSPoint=ff}{_NSSize=ff}}', NSRect.objc_type)
+    assert_equal([:origin, :size] , NSRect.fields)
+    assert(!NSRect.opaque?)
+
+    # opaque
+    assert(NSZone.ancestors.include?(Boxed))
+    assert_equal('^{_NSZone=}', NSZone.objc_type)
+    assert_equal([] , NSZone.fields)
+    assert(NSZone.opaque?)
+  end
+
+  def test_opaque
+    assert_raise(TypeError) { NSZone.new }
+    z = 'foo'.zone
+    assert_kind_of(NSZone, z)
+    assert_equal(z, 'bar'.zone)
+  end
+
+  def test_struct1
+    p = NSPoint.new
+    assert_kind_of(NSPoint, p)
+    assert_equal(0.0, p.x)
+    assert_equal(0.0, p.y)
+    assert_equal([0.0, 0.0], p.to_a)
+    assert_equal(p, NSPoint.new)
+    assert_equal(p, p.dup)
+    assert_equal(p, p.clone)
+    assert_equal(p, NSZeroPoint)
+
+    p.x += 1
+    assert_equal(1.0, p.x)
+    assert_equal([1.0, 0.0], p.to_a)
+    
+    p2 = NSPoint.new(1.0, 2.0)
+    assert_equal(p.x, p2.x)
+    assert_not_equal(p.y, p2.y)
+    p.y += 2
+    assert_equal(p.y, p2.y)
+
+    assert_raise(ArgumentError) { NSPoint.new(42) }
+    assert_raise(ArgumentError) { NSPoint.new(42, 42, 42) }
+    assert_raise(TypeError) { NSPoint.new(nil, nil) }
+    assert_raise(ArgumentError) { NSPoint.new('foo', 'bar') }
+    assert_raise(TypeError) { p.x = nil }
+    assert_raise(ArgumentError) { p.x = 'foo' }
+
+    r = NSRect.new
+    assert_kind_of(NSRect, r)
+    assert_equal(NSZeroPoint, r.origin)
+    assert_equal(NSZeroSize, r.size) 
+    assert_equal([NSZeroPoint, NSZeroSize], r.to_a)
+    
+    assert_raise(ArgumentError) { r.origin = nil }
+    assert_raise(ArgumentError) { r.origin = 'foo' }
+
+    r2 = NSRect.new(p, NSSize.new(42.0, 42.0))
+    assert_not_equal(r, r2)
+    r.size = NSSize.new(42.0, 42.0)
+    assert_equal(r.size, r2.size)
+    r.origin = p
+    assert_equal(r.origin, r2.origin)
+    assert_equal(r, r2)
+    r.origin.x -= 1
+    r2.origin.x -= 1
+    r.size.width /= 2.0
+    r2.size.width /= 2.0
+    assert_equal(r, r2)
+    assert_equal(r.to_a, r2.to_a)
+  end
+
+  def test_struct_nsstring_marshalling
+    r = NSRange.new(1, 4)
+    assert_kind_of(NSString, NSStringFromRange(r))
+    assert_equal('{1, 4}', NSStringFromRange(r))
+    assert_equal(r, NSRangeFromString(NSStringFromRange(r)))
+    rect = NSRect.new(NSPoint.new(42.0, 1042.0), NSSize.new(123, 456))
+    assert_equal(NSPoint.new(42.0, 1042.0),
+      NSPointFromString(NSStringFromPoint(rect.origin)))
+  end
+
+  def test_nspoint_in_objc
+    p = NSPoint.new(42.0, 99.0)
+    o = TestBoxed.new
+    o.testPoint(p, x:42.0, y:99.0)
+    o.testPointAsObject(p, x:42.0, y:99.0)
+    assert_equal(p, o.testReturnPointWithX(42.0, y:99.0))
+  end
+
+  class MethodReturningBoxed
+    def foo
+      NSPoint.new(1, 2)
+    end
+  end
+  def test_objc_call_pure_method_returning_boxed
+    o = MethodReturningBoxed.new
+    assert_equal(NSPoint.new(1, 2), o.send(:foo))
+    assert_equal(NSPoint.new(1, 2), o.performSelector(:foo))
+  end
+
+end


Property changes on: MacRuby/trunk/test-macruby/cases/boxed_test.rb
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: MacRuby/trunk/test-macruby/cases/framework_test.rb (from rev 789, MacRuby/trunk/test-macruby/test_framework.rb)
===================================================================
--- MacRuby/trunk/test-macruby/cases/framework_test.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/cases/framework_test.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,29 @@
+#!/usr/bin/env macruby
+
+require File.expand_path('../../test_helper', __FILE__)
+
+class TestFramework < Test::Unit::TestCase
+
+  def test_setup
+    framework('Foundation')
+  end
+
+  def test_framework_by_name
+    assert_nothing_raised { framework('Foundation') }
+    assert_raise(RuntimeError) { framework('DoesNotExist') }
+  end
+
+  def test_framework_by_path
+    assert_nothing_raised do 
+      framework('/System/Library/Frameworks/Foundation.framework')
+    end
+    assert_raise(RuntimeError) { framework('/does/not/exist') }
+  end
+
+  def test_framework_load_twice
+    assert_equal(false, framework('Foundation'))
+    assert_equal(false,
+      framework('/System/Library/Frameworks/Foundation.framework'))
+  end
+
+end


Property changes on: MacRuby/trunk/test-macruby/cases/framework_test.rb
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: MacRuby/trunk/test-macruby/cases/hash_test.rb (from rev 789, MacRuby/trunk/test-macruby/test_hash.rb)
===================================================================
--- MacRuby/trunk/test-macruby/cases/hash_test.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/cases/hash_test.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,91 @@
+#!/usr/bin/env macruby
+
+require File.expand_path('../../test_helper', __FILE__)
+
+class TestHash < Test::Unit::TestCase
+
+  def test_hash_class
+    assert(Hash.is_a?(Class))
+    assert(Hash.ancestors.include?(NSDictionary))
+    assert(Hash.ancestors.include?(NSMutableDictionary))
+  end
+
+  def test_hash_create
+    h = {}
+    assert_kind_of(Hash, h)
+    h = {'a' => 100}
+    assert_kind_of(Hash, h)
+    h = Hash.new
+    assert_kind_of(Hash, h)
+    h = Hash.alloc.init
+    assert_kind_of(Hash, h)
+    h = Hash['a', 100, 'b', 200]
+    assert_kind_of(Hash, h)
+    h = Hash['a' => 100, 'b' => 200]
+    assert_kind_of(Hash, h)
+  end
+
+  class MyHash < Hash; end
+  def test_hash_create_subclass
+    assert(MyHash.ancestors.include?(Hash))
+    h = MyHash.new
+    assert_kind_of(MyHash, h)
+    h = MyHash.alloc.init
+    assert_kind_of(MyHash, h)
+    h = MyHash['a', 100, 'b', 200]
+    assert_kind_of(MyHash, h)
+    h = MyHash['a' => 100, 'b' => 200]
+    assert_kind_of(MyHash, h)
+  end
+
+  def test_hash_cannot_modify_immutable
+    h = NSDictionary.new
+    assert_raise(RuntimeError) { h[1] = 1 }
+    assert_raise(RuntimeError) { h.clear }
+    h = NSDictionary.alloc.init
+    assert_raise(RuntimeError) { h[1] = 1 }
+    assert_raise(RuntimeError) { h.clear }
+  end
+
+  def test_hash_get_set
+    h = {}
+    h[1] = 2
+    assert_equal(2, h[1])
+    h['foo'] = 3
+    assert_equal(3, h['foo'])
+    assert_equal(3, h[String.new('foo')])
+    h[[1,2]] = 4
+    assert_equal(4, h[[1,2]])
+    assert_equal(4, h[Array.new([1,2])])
+    h[:sym] = 5
+    assert_equal(5, h[:sym])
+    assert_equal(5, h['sym'.intern])
+  end
+
+  def test_hash_count
+    h = {}
+    assert_equal(0, h.size)
+    assert_equal(0, h.count)
+    assert(h.empty?)
+    h[1] = 2
+    assert_equal(1, h.size)
+    assert_equal(1, h.count)
+    assert(!h.empty?)
+    h[1] = nil
+    assert_equal(1, h.size)
+    assert_equal(1, h.count)
+    assert(!h.empty?)
+    h.delete(1)
+    assert_equal(0, h.size)
+    assert_equal(0, h.count)
+    assert(h.empty?)
+  end
+
+  def test_hash_clear
+    h = {1=>2}
+    h.clear
+    assert(h.empty?)
+    assert_equal(nil, h[1])
+  end
+
+end


Property changes on: MacRuby/trunk/test-macruby/cases/hash_test.rb
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: MacRuby/trunk/test-macruby/cases/objc_ext_test.rb (from rev 789, MacRuby/trunk/test-macruby/test_objc_ext.rb)
===================================================================
--- MacRuby/trunk/test-macruby/cases/objc_ext_test.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/cases/objc_ext_test.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,89 @@
+#!/usr/bin/env macruby
+
+require File.expand_path('../../test_helper', __FILE__)
+
+framework 'Cocoa'
+
+# These tests should probably move to the macruby part of rubyspec once we get to that point.
+
+require 'objc_ext/ns_user_defaults'
+
+class TestNSUserDefaultsExtensions < Test::Unit::TestCase
+  it "should returns a value for a given key through the #[] reader method" do
+    defaults.setValue('foo', forKey: 'key')
+    assert_equal 'foo', defaults['key']
+  end
+  
+  it "should assign a value for a given key through the #[]= writer method" do
+    defaults['key'] = 'foo'
+    assert_equal 'foo', defaults.valueForKey('key')
+  end
+  
+  it "should remove an object for a given key with the #delete method" do
+    defaults.setValue('foo', forKey: 'key')
+    defaults.delete('key')
+    assert_nil defaults.valueForKey('key')
+  end
+  
+  private
+  
+  def defaults
+    NSUserDefaults.standardUserDefaults
+  end
+end
+
+require 'objc_ext/ns_rect'
+
+class TestNSRectExtensions < Test::Unit::TestCase
+  def setup
+    @rect = NSRect.new([100, 100], [200, 200])
+  end
+  
+  it "should return its size instance's height with #height" do
+    assert_equal 200, @rect.height
+  end
+  
+  it "should assign the height to its size instance with #height=" do
+    @rect.height = 300
+    assert_equal 300, @rect.height
+    
+    @rect.height = NSNumber.numberWithInt(400)
+    assert_equal 400, @rect.height
+  end
+  
+  it "should return its size instance's width with #width" do
+    assert_equal 200, @rect.width
+  end
+  
+  it "should assign the width to its size instance with #width=" do
+    @rect.width = 300
+    assert_equal 300, @rect.width
+    
+    @rect.width = NSNumber.numberWithInt(400)
+    assert_equal 400, @rect.width
+  end
+  
+  it "should return its origin instance's x coord with #x" do
+    assert_equal 100, @rect.x
+  end
+  
+  it "should assign the x coord to its origin instance with #x=" do
+    @rect.x = 200
+    assert_equal 200, @rect.x
+    
+    @rect.x = NSNumber.numberWithInt(300)
+    assert_equal 300, @rect.x
+  end
+  
+  it "should return its origin instance's y coord with #y" do
+    assert_equal 100, @rect.y
+  end
+  
+  it "should assign the y coord to its origin instance with #y=" do
+    @rect.y = 200
+    assert_equal 200, @rect.y
+    
+    @rect.y = NSNumber.numberWithInt(300)
+    assert_equal 300, @rect.y
+  end
+end
\ No newline at end of file


Property changes on: MacRuby/trunk/test-macruby/cases/objc_ext_test.rb
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: MacRuby/trunk/test-macruby/cases/objc_test.rb (from rev 791, MacRuby/trunk/test-macruby/test_objc.rb)
===================================================================
--- MacRuby/trunk/test-macruby/cases/objc_test.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/cases/objc_test.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,175 @@
+#!/usr/bin/env macruby
+
+require File.expand_path('../../test_helper', __FILE__)
+
+class MacRuby::TestClassConstantLookup < Test::Unit::TestCase
+  module Namespace
+    class PureRubyClass; end
+    module PureRubyModule; end
+    SINGLETON = (class << self; self; end)
+  end
+  
+  it "should not find pure Ruby classes in different namespaces" do
+    assert_raise(NameError) { PureRubyClass }
+  end
+  
+  it "should find pure Ruby classes in different namespaces if given the correct path" do
+    assert_nothing_raised(NameError) { Namespace::PureRubyClass }
+  end
+  
+  it "should not find pure Ruby modules in different namespaces" do
+    assert_raise(NameError) { PureRubyModule }
+  end
+  
+  it "should find pure Ruby modules in different namespaces if given the correct path" do
+    assert_nothing_raised(NameError) { Namespace::PureRubyModule }
+  end
+  
+  it "should not find pure Ruby class singletons in different namespaces" do
+    assert_raise(NameError) { SINGLETON }
+  end
+  
+  it "should find pure Ruby class singletons in different namespaces if given the correct path" do
+    assert_nothing_raised(NameError) { Namespace::SINGLETON }
+  end
+end
+
+class MacRuby::TestKeyedArguments < Test::Unit::TestCase
+  before do
+    @key, @value = "key", NSObject.new
+  end
+  
+  it "should allow the user to specify each argument by name" do
+    dictionary = {}
+    dictionary.setValue(@value, forKey: @key)
+    
+    assert_equal @value, dictionary.valueForKey(@key)
+  end
+  
+  it "should still find a method without keyed arguments, even if the last argument is a hash" do
+    obj = NSObject.new
+    def obj.method(first, *others)
+      [first, others] # stub this method to return all args
+    end
+    
+    assert_equal [:first, []], obj.method(:first)
+    assert_equal [:first, [:foo => 'foo']], obj.method(:first, foo: 'foo')
+    assert_equal [:first, [:foo => 'foo', :bar => 'bar']], obj.method(:first, foo: 'foo', bar: 'bar')
+  end
+  
+  it "should forward method calls with #performSelector when selector is given as String" do
+    dictionary = NSMutableDictionary.performSelector('new')
+    dictionary.performSelector('setObject:forKey:', withObject: @value, withObject: @key)
+    
+    assert_equal @value, dictionary.performSelector('objectForKey:', withObject: @key)
+  end
+  
+  it "should forward method calls with #performSelector when selector is given as Symbol" do
+    dictionary = NSMutableDictionary.performSelector(:'new')
+    dictionary.performSelector(:'setObject:forKey:', withObject: @value, withObject: @key)
+    
+    assert_equal @value, dictionary.performSelector(:'objectForKey:', withObject: @key)
+  end
+  
+  it "should forward method calls with #send when selector is given as String" do
+    dictionary = NSMutableDictionary.send('new')
+    dictionary.send('setObject:forKey:', @value, @key)
+    
+    assert_equal @value, dictionary.send('objectForKey:', @key)
+  end
+  
+  it "should forward method calls with #send when selector is given as Symbol" do
+    dictionary = NSMutableDictionary.send(:new)
+    dictionary.send(:'setObject:forKey:', @value, @key)
+    
+    assert_equal @value, dictionary.send(:'objectForKey:', @key)
+  end
+end
+
+class MacRuby::TestGeneralSyntax < Test::Unit::TestCase
+  it "should find a Objective-C method with varying number of arguments" do
+    [
+      ['"foo" == "bar"'],
+      ['"foo" == %@', 'bar'],
+      ['%@ == %@', 'foo', 'bar']
+      
+    ].each do |arguments|
+      assert_equal '"foo" == "bar"', NSPredicate.predicateWithFormat(*arguments).predicateFormat
+    end
+  end
+end
+
+class MacRuby::TestInstanceVariableAccess < Test::Unit::TestCase
+  it "should assign an instance variable on an instance of a pure Objective-C class and _not_ garbage collect it" do
+    obj = NSObject.alloc.init
+    obj.instance_variable_set(:@foo, 'foo')
+    GC.start
+    
+    assert_equal 'foo', obj.instance_variable_get(:@foo)
+  end
+  
+  it "should assign an instance variable on an instance of a CoreFoundation class and _not_ garbage collect it" do
+    obj = NSString.alloc.init
+    obj.instance_variable_set(:@foo, 'foo')
+    GC.start
+    
+    assert_equal 'foo', obj.instance_variable_get(:@foo)
+  end
+end
+
+class MacRuby::TestMethodDispatch < Test::Unit::TestCase
+  it "should find a method on a pure Objective-C class in the dispatch chain, before a method on a module that is included" do
+    objc = ObjectiveC.new(fixture('PureObjCSubclass.m'))
+    objc.compile!
+    objc.require!
+    
+    assert_equal "FOO", PureObjCSubclass.alloc.init.require("foo")
+  end
+  
+  it "should find a method on a class in the dispatch chain, before a method on a module that is included" do
+    klass = Class.new do
+      def require(name)
+        name.upcase
+      end
+    end
+    
+    assert_equal "FOO", klass.new.require("foo")
+  end
+  
+  it "should find a method on a singleton in the dispatch chain, before a method on a module that is included" do
+    obj = NSObject.new
+    def obj.require(name)
+      name.upcase
+    end
+    
+    assert_equal "FOO", obj.require("foo")
+  end
+end
+
+class MacRuby::TestPrimitiveTypes < Test::Unit::TestCase
+  before do
+    objc = ObjectiveC.new(fixture('PureObjCSubclass.m'))
+    objc.compile!
+    objc.require!
+    
+    @pure_objc_instance = PureObjCSubclass.alloc.init
+  end
+  
+  it "should be possible to use a Ruby String as dictionary key and pass the dictionary of into Objective-C land" do
+    key = String.new("foo")
+    value = Object.new
+    dictionary = { key => value }
+    
+    assert_equal value, @pure_objc_instance.test_getObject(dictionary, forKey: key)
+  end
+end
+
+class MacRuby::TestInstantiation < Test::Unit::TestCase
+  it "should instantiate with klass::new" do
+    assert_kind_of NSObject, NSObject.new
+  end
+  
+  it "should instantiate with klass::alloc.init" do
+    assert_kind_of NSObject, NSObject.alloc.init
+  end
+end


Property changes on: MacRuby/trunk/test-macruby/cases/objc_test.rb
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: MacRuby/trunk/test-macruby/cases/rubycocoa_test_disabled.rb (from rev 789, MacRuby/trunk/test-macruby/rubycocoa_test.rb)
===================================================================
--- MacRuby/trunk/test-macruby/cases/rubycocoa_test_disabled.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/cases/rubycocoa_test_disabled.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,253 @@
+#!/usr/local/bin/macruby
+
+require "test/spec"
+require 'mocha'
+
+#require File.expand_path('../../lib/osx/cocoa', __FILE__)
+require 'osx/cocoa'
+
+class TestRubyCocoaStyleMethod < OSX::NSObject
+  def initialize
+    @set_from_initialize = 'represent!'
+  end
+  
+  def perform_selector_with_object(sel, obj)
+    callMethod_withArgs(sel, obj)
+  end
+  
+  def callMethod(method, withArgs:args)
+    send(method, *args)
+  end
+  
+  def method_rubyCocoaStyle_withExtraArg(mname, rc_style, arg)
+    "#{mname}(#{rc_style}, #{arg})"
+  end
+  
+  def method_notRubyCocoaStyle(first_arg, second_arg, third_arg)
+  end
+  
+  def self.classMethod(mname, macRubyStyle:mr_style, withExtraArg:arg)
+    "#{mname}(#{mr_style}, #{arg})"
+  end
+end
+
+class TestRubyCocoaStyleSuperMethod < OSX::NSObject
+  def init
+    self if super_init
+  end
+end
+
+class NSObjectSubclassWithInitialize < OSX::NSObject
+  def initialize
+    @set_from_initialize = 'represent!'
+  end
+end
+
+class NSObjectSubclassWithoutInitialize < OSX::NSObject; end
+
+CONSTANT_IN_THE_TOPLEVEL_OBJECT_INSTEAD_OF_OSX = true
+
+describe "RubyCocoa layer, in general" do
+  xit "should load AppKit when the osx/cocoa file is loaded" do
+    Kernel.expects(:framework).with('AppKit')
+    load 'osx/cocoa.rb'
+  end
+  
+  it "should set a global variable which indicates that a framework is being loaded" do
+    Kernel.expects(:__framework_before_rubycocoa_layer).with do |f|
+      $LOADING_FRAMEWORK.should.be true
+      f == 'Foo'
+    end
+    Kernel.framework 'Foo'
+    $LOADING_FRAMEWORK.should.be false
+  end
+end
+
+describe "NSObject additions" do
+  before do
+    @obj = TestRubyCocoaStyleMethod.alloc.init
+  end
+  
+  it "should alias ib_outlet to ib_outlets" do
+    TestRubyCocoaStyleMethod.private_methods.should.include :ib_outlets
+  end
+  
+  it "should call initialize from init if it exists" do
+    NSObjectSubclassWithInitialize.alloc.init.instance_variable_get(:@set_from_initialize).should == 'represent!'
+    NSObjectSubclassWithoutInitialize.alloc.init.instance_variable_get(:@set_from_initialize).should.be nil
+  end
+  
+  it "should catch RubyCocoa style instance method, call the correct MacRuby style method and define a shortcut method" do
+    @obj.perform_selector_with_object('description', nil).should.match /^<TestRubyCocoaStyleMethod/
+    @obj.respond_to?(:callMethod_withArgs).should.be true
+    @obj.perform_selector_with_object('description', nil).should.match /^<TestRubyCocoaStyleMethod/
+  end
+  
+  it "should catch RubyCocoa style instance methods that end with a underscore" do
+    @obj.callMethod_withArgs_('description', nil).should.match /^<TestRubyCocoaStyleMethod/
+    @obj.respond_to?(:callMethod_withArgs_).should.be true
+  end
+  
+  it "should catch RubyCocoa style instance methods defined in Objective-C" do
+    color = NSColor.colorWithCalibratedRed(1.0, green:1.0, blue:1.0, alpha:1.0)
+    lambda { color.blendedColorWithFraction_ofColor(0.5, NSColor.greenColor) }.should.not.raise NoMethodError
+  end
+  
+  it "should catch RubyCocoa style class methods defined in ruby" do
+    lambda { TestRubyCocoaStyleMethod.classMethod_macRubyStyle_withExtraArg(1, 2, 3) }.should.not.raise NoMethodError
+    TestRubyCocoaStyleMethod.respond_to?(:classMethod_macRubyStyle_withExtraArg).should.be true
+  end
+  
+  it "should catch RubyCocoa style class methods defined in Objective-C" do
+    lambda { NSColor.colorWithCalibratedRed_green_blue_alpha(1.0, 1.0, 1.0, 1.0) }.should.not.raise NoMethodError
+    NSColor.respond_to?(:colorWithCalibratedRed_green_blue_alpha).should.be true
+  end
+  
+  it "should still raise NoMethodError if a class method doesn't exist" do
+    lambda { NSColor.colorWithCalibratedRed_pink(1.0, 1.0) }.should.raise NoMethodError
+  end
+  
+  it "should also work on other regular NSObject subclasses" do
+    nsstring = 'foo'
+    nsstring.insertString_atIndex('bar', 3)
+    nsstring.should == 'foobar'
+  end
+  
+  it "should still raise a NoMethodError if the selector doesn't exist when a method is missing" do
+    lambda { @obj.does_not_exist }.should.raise NoMethodError
+    lambda { @obj.doesnotexist_ }.should.raise NoMethodError
+    lambda { @obj.doesnotexist }.should.raise NoMethodError
+  end
+  
+  it "should be possible to call super_foo type methods" do
+    lambda { TestRubyCocoaStyleSuperMethod.alloc.init }.should.not.raise.exception
+  end
+  
+  it "should handle objc_send style methods" do
+    nsstring = 'foo'
+    nsstring.objc_send(:insertString, 'bar', :atIndex, 3)
+    nsstring.should == 'foobar'
+    nsstring.objc_send(:description).should == 'foobar'
+    lambda { nsstring.objc_send(:does_not_exist) }.should.raise NoMethodError
+  end
+  
+  it "should create MacRuby style method aliases for any method containing underscores" do
+    @obj.respond_to?(:"method:rubyCocoaStyle:withExtraArg:").should.be true
+    @obj.method('foo', rubyCocoaStyle:true, withExtraArg:false).should == 'foo(true, false)'
+  end
+  
+  it "should not create MacRuby style method aliases for methods containing underscores if the arity doesn't match" do
+    @obj.respond_to?(:"method:notRubyCocoaStyle:").should.be false
+  end
+  
+  it "should respond to to_ruby" do
+    @obj.respond_to?(:to_ruby).should.be true
+  end
+end
+
+describe 'OSX module' do
+  it "should exist" do
+    defined?(OSX).should.not.be nil # this is weird.. I haven't defined OSX yet?!
+  end
+  
+  it "should load a framework into the runtime" do
+    OSX.require_framework 'WebKit'
+    defined?(WebView).should.not.be nil
+    
+    OSX.require_framework '/System/Library/Frameworks/QTKit.framework'
+    defined?(QTMovie).should.not.be nil
+  end
+  
+  it "should forward messages to Kernel if it responds to it" do
+    Kernel.expects(:NSRectFill).with(1, 2).times(2)
+    OSX::NSRectFill(1, 2)
+    OSX.respond_to?(:NSRectFill).should.be true
+    OSX::NSRectFill(1, 2)
+    
+    lambda { OSX::NSRectFillllllll(1, 2) }.should.raise NoMethodError
+  end
+  
+  it "should try to get missing constants from the toplevel object" do
+    OSX::CONSTANT_IN_THE_TOPLEVEL_OBJECT_INSTEAD_OF_OSX.should.be true
+  end
+  
+  it "should still raise a NameError from OSX, not from the toplevel object, when a constant is missing" do
+    lambda { OSX::DOES_NOT_EXIST_IN_TOPLEVEL_OBJECT }.should.raise NameError
+    
+    begin
+      OSX::DOES_NOT_EXIST_IN_TOPLEVEL_OBJECT
+    rescue NameError => e
+      e.message.should.include 'OSX::DOES_NOT_EXIST_IN_TOPLEVEL_OBJECT'
+    end
+  end
+end
+
+describe 'NSData additions' do
+  before do
+    path = '/System/Library/DTDs/BridgeSupport.dtd'
+    @obj = NSData.dataWithContentsOfFile(path)
+    @ruby_data = File.read(path)
+  end
+
+  it "should respond to rubyString" do
+    @obj.respond_to?(:rubyString).should.be true
+    @obj.rubyString.should.equal @ruby_data
+  end
+end
+
+describe 'NSUserDefaults additions' do
+  before do
+    @obj = NSUserDefaults.alloc.init
+  end
+  
+  it "should respond to [] and []=" do
+    @obj.respond_to?(:[]).should.be true
+    @obj.respond_to?(:[]=).should.be true
+    @obj['key'] = 'value'
+    @obj['key'].should.equal 'value'
+  end
+end
+
+describe 'NSIndexSet additions' do
+  before do
+    @obj = NSIndexSet.alloc.init
+  end
+  
+  it "should respond to to_a" do
+    @obj.respond_to?(:to_a).should.be true
+  end
+end
+
+describe 'NSNumber additions' do
+  before do
+    @i = NSNumber.numberWithInt(42)
+    @f = NSNumber.numberWithDouble(42.42)
+  end
+  
+  it "should respond to to_i and to_f" do
+    @i.respond_to?(:to_i).should.be true
+    @i.respond_to?(:to_f).should.be true
+    @i.to_i.should.equal 42
+    @f.to_f.should.equal 42.42
+  end
+end
+
+describe 'NSDate additions' do
+  before do
+    @obj = NSDate.alloc.init
+  end
+  
+  it "should respond to to_time" do
+    @obj.respond_to?(:to_time).should.be true
+  end
+end
+
+describe 'NSImage additions' do
+  before do
+    @obj = NSImage.alloc.init
+  end
+  
+  it "should respond to focus" do
+    @obj.respond_to?(:focus).should.be true
+  end
+end


Property changes on: MacRuby/trunk/test-macruby/cases/rubycocoa_test_disabled.rb
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: MacRuby/trunk/test-macruby/cases/string_test.rb (from rev 789, MacRuby/trunk/test-macruby/test_string.rb)
===================================================================
--- MacRuby/trunk/test-macruby/cases/string_test.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/cases/string_test.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,66 @@
+#!/usr/bin/env macruby
+
+require File.expand_path('../../test_helper', __FILE__)
+
+class TestString < Test::Unit::TestCase
+
+  def setup
+    framework 'Foundation'
+    bundle = '/tmp/_test_string.bundle'
+    if !File.exist?(bundle) or File.mtime(bundle) < File.mtime(__FILE__)
+      s = <<EOS
+#import <Foundation/Foundation.h>
+ at interface MyTestClass : NSObject
+ at end
+ at implementation MyTestClass
+- (NSString*)testSubstring:(NSString*)str range:(NSRange)range
+{
+    unichar buf[1024];
+    [str getCharacters:buf range:range];
+    return [[NSString alloc] initWithCharacters:buf length:range.length];
+}
+ at end
+EOS
+      File.open('/tmp/_test_string.m', 'w') { |io| io.write(s) }
+      system("gcc /tmp/_test_string.m -bundle -o #{bundle} -framework Foundation -fobjc-gc-only") or exit 1
+    end
+    require 'dl'; DL.dlopen(bundle)
+  end
+  
+  def test_characterAtIndex
+    s = 'abcあいうxyz'
+    [0,3,6,8].each do |d|
+      assert_equal(s[d].ord, s.characterAtIndex(d))
+      assert_equal(s[d].ord, s.characterAtIndex(d))
+    end
+  end
+  
+  def test_getCharactersRange
+    s = 'abcあいうxzy'
+    obj = MyTestClass.alloc.init
+    [[0,1], [1,7], [4,3], [7,2]].each do |d|
+      assert_equal(s[*d], obj.testSubstring(s, range:NSRange.new(*d)))
+    end
+  end
+  
+  #
+  # Tests for UTF-16 surrogate pairs
+  # These tests should be fixed in the future.
+  #
+  # Memo:
+  #   If an NSString consists of a character which is UTF-16 surrogate pair,
+  #   the length of the string will be 2 in Cocoa, while 1 in ruby 1.9.
+  #
+  
+  def test_characterAtIndex_surrogate_pairs
+    s = "abc\xf0\xa3\xb4\x8exzy"
+    assert_equal(s[3].ord, s.characterAtIndex(3))
+  end
+  
+  def test_getCharactersRange_surrogate_pairs
+    s = "abc\xf0\xa3\xb4\x8exzy"
+    obj = MyTestClass.alloc.init
+    assert_equal(s[2,3], obj.testSubstring(s, range:NSRange.new(2,3)))
+  end
+  
+end


Property changes on: MacRuby/trunk/test-macruby/cases/string_test.rb
___________________________________________________________________
Added: svn:mergeinfo
   + 

Deleted: MacRuby/trunk/test-macruby/extconf.rb
===================================================================
--- MacRuby/trunk/test-macruby/extconf.rb	2009-01-15 12:52:28 UTC (rev 791)
+++ MacRuby/trunk/test-macruby/extconf.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -1,2 +0,0 @@
-require "mkmf"
-create_makefile("known_bugs_in_c")
\ No newline at end of file

Added: MacRuby/trunk/test-macruby/fixtures/PureObjCSubclass.m
===================================================================
--- MacRuby/trunk/test-macruby/fixtures/PureObjCSubclass.m	                        (rev 0)
+++ MacRuby/trunk/test-macruby/fixtures/PureObjCSubclass.m	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,16 @@
+#import <Foundation/Foundation.h>
+
+ at interface PureObjCSubclass : NSObject
+ at end
+
+ at implementation PureObjCSubclass
+- (id)require:(NSString *)name
+{
+    return [name uppercaseString];
+}
+
+- (id)test_getObject:(id)dictionary forKey:(id)key
+{
+    return [dictionary objectForKey:key];
+}
+ at end
\ No newline at end of file

Copied: MacRuby/trunk/test-macruby/known_bugs/extconf.rb (from rev 789, MacRuby/trunk/test-macruby/extconf.rb)
===================================================================
--- MacRuby/trunk/test-macruby/known_bugs/extconf.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/known_bugs/extconf.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,2 @@
+require "mkmf"
+create_makefile("known_bugs_in_c")
\ No newline at end of file


Property changes on: MacRuby/trunk/test-macruby/known_bugs/extconf.rb
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: MacRuby/trunk/test-macruby/known_bugs/known_bugs.rb (from rev 789, MacRuby/trunk/test-macruby/known_bugs.rb)
===================================================================
--- MacRuby/trunk/test-macruby/known_bugs/known_bugs.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/known_bugs/known_bugs.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,133 @@
+#!/usr/local/bin/macruby
+
+require "test/unit"
+#framework 'Cocoa'
+
+module KnownBugs
+  class TestBugsInC < Test::Unit::TestCase 
+    def setup
+      dir = File.expand_path('../', __FILE__)
+      exit(1) unless system("cd #{dir} && macruby extconf.rb && make")
+      require File.join(dir, 'known_bugs_in_c')
+    end
+
+    def test_accessing_an_array_created_via_rb_str_split2
+      KnownBugsInC.test_rb_str_split2("foo:bar", ":")
+    end
+  end
+
+  class TestKernel < Test::Unit::TestCase
+    module ::Kernel
+      private
+      def is_callable?; true end
+    end
+
+    module ::Kernel
+      def should_be_callable?; true end
+      private :should_be_callable?
+    end
+
+    def test_kernel_methods_made_private_with_keyword
+      assert is_callable? # works
+    end
+
+    def test_kernel_methods_made_private_with_class_method
+      assert should_be_callable? # causes endless loop
+    end
+  end
+
+  class TestDuplicatingInstances < Test::Unit::TestCase
+    # Works
+
+    class Foo; end
+
+    def test_dup_on_an_instance_of_a_pure_ruby_class
+      obj = Foo.new
+      assert_not_equal obj, obj.dup.object_id
+    end
+
+    # Fails
+
+    def test_dup_on_an_instance_of_Object
+      obj = Object.new
+      assert_nothing_raised(NSException) do
+        # Raises: [NSObject copyWithZone:]: unrecognized selector sent to instance
+        assert_not_equal obj.object_id, obj.dup.object_id
+      end
+    end
+
+    def test_dup_on_a_class_instance
+      assert_not_equal Foo.object_id, Foo.dup.object_id
+    end
+  end
+
+  class TestStringFormatting < Test::Unit::TestCase
+    def test_formatting_with_a_Bignum
+      assert_nothing_raised(RangeError) { "%d" % 68727360256 }
+    end
+  end
+
+  class TestIncludingModuleInClass < Test::Unit::TestCase
+    module ClassInstanceMethod
+      def a_class_instance_method; end
+    end
+
+    class ::Class
+      include ClassInstanceMethod
+    end
+
+    def test_class_should_respond_to_methods_included_in_Class
+      assert Class.new.respond_to?(:a_class_instance_method)
+    end
+  end
+
+  class TestIncludingModuleInModule < Test::Unit::TestCase
+    module ModuleInstanceMethod
+      def a_module_instance_method; end
+    end
+
+    class ::Module
+      include ModuleInstanceMethod
+    end
+
+    def test_module_should_respond_to_methods_included_in_Module
+      assert Module.new.respond_to?(:a_module_instance_method)
+    end
+  end
+
+  class TestConstantLookup < Test::Unit::TestCase
+    module Namespace
+      NamespacedConstant = nil
+      class NamespacedClass; end
+    end
+
+    def test_should_not_find_namespaced_constants # works
+      assert_raise(NameError) { NamespacedConstant }
+    end
+
+    def test_should_not_find_namespaced_classes # fails
+      assert_raise(NameError) { NamespacedClass }
+    end
+  end
+
+  class TestRespondTo < Test::Unit::TestCase
+    class RespondTo
+      def respond_to?(method, hidden = false)
+        super
+      end
+    end
+
+    def test_super_implementation
+      assert_nothing_raised(SystemStackError) do
+        RespondTo.new.respond_to?(:object_id)
+      end
+    end
+  end
+
+  class TestBooleanComparison < Test::Unit::TestCase
+    def test_NSCFBoolean_comparison_to_Ruby_bool
+      assert_equal true,  NSNumber.numberWithBool(true)
+      assert_equal false, NSNumber.numberWithBool(false)
+    end
+  end
+end
\ No newline at end of file


Property changes on: MacRuby/trunk/test-macruby/known_bugs/known_bugs.rb
___________________________________________________________________
Added: svn:mergeinfo
   + 

Copied: MacRuby/trunk/test-macruby/known_bugs/known_bugs_in_c.c (from rev 789, MacRuby/trunk/test-macruby/known_bugs_in_c.c)
===================================================================
--- MacRuby/trunk/test-macruby/known_bugs/known_bugs_in_c.c	                        (rev 0)
+++ MacRuby/trunk/test-macruby/known_bugs/known_bugs_in_c.c	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,17 @@
+#include "ruby/ruby.h"
+
+static VALUE
+known_bug_rb_str_split2(VALUE recv, VALUE str, VALUE sep)
+{
+  VALUE parts = rb_str_split2(str, sep);
+  // Accessing the array goes wrong, has it been collected?
+  // Because at the end of rb_str_split_m the `result' _is_ the array as expected…
+  return rb_ary_entry(parts, 0);
+}
+
+void Init_known_bugs_in_c() {
+  VALUE cKnownBugsInC;
+  
+  cKnownBugsInC = rb_define_module("KnownBugsInC");
+  rb_define_module_function(cKnownBugsInC, "test_rb_str_split2", known_bug_rb_str_split2, 2);
+}
\ No newline at end of file


Property changes on: MacRuby/trunk/test-macruby/known_bugs/known_bugs_in_c.c
___________________________________________________________________
Added: svn:mergeinfo
   + 

Deleted: MacRuby/trunk/test-macruby/known_bugs.rb
===================================================================
--- MacRuby/trunk/test-macruby/known_bugs.rb	2009-01-15 12:52:28 UTC (rev 791)
+++ MacRuby/trunk/test-macruby/known_bugs.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -1,133 +0,0 @@
-#!/usr/local/bin/macruby
-
-require "test/unit"
-#framework 'Cocoa'
-
-module KnownBugs
-  class TestBugsInC < Test::Unit::TestCase 
-    def setup
-      dir = File.expand_path('../', __FILE__)
-      exit(1) unless system("cd #{dir} && macruby extconf.rb && make")
-      require File.join(dir, 'known_bugs_in_c')
-    end
-
-    def test_accessing_an_array_created_via_rb_str_split2
-      KnownBugsInC.test_rb_str_split2("foo:bar", ":")
-    end
-  end
-
-  class TestKernel < Test::Unit::TestCase
-    module ::Kernel
-      private
-      def is_callable?; true end
-    end
-
-    module ::Kernel
-      def should_be_callable?; true end
-      private :should_be_callable?
-    end
-
-    def test_kernel_methods_made_private_with_keyword
-      assert is_callable? # works
-    end
-
-    def test_kernel_methods_made_private_with_class_method
-      assert should_be_callable? # causes endless loop
-    end
-  end
-
-  class TestDuplicatingInstances < Test::Unit::TestCase
-    # Works
-
-    class Foo; end
-
-    def test_dup_on_an_instance_of_a_pure_ruby_class
-      obj = Foo.new
-      assert_not_equal obj, obj.dup.object_id
-    end
-
-    # Fails
-
-    def test_dup_on_an_instance_of_Object
-      obj = Object.new
-      assert_nothing_raised(NSException) do
-        # Raises: [NSObject copyWithZone:]: unrecognized selector sent to instance
-        assert_not_equal obj.object_id, obj.dup.object_id
-      end
-    end
-
-    def test_dup_on_a_class_instance
-      assert_not_equal Foo.object_id, Foo.dup.object_id
-    end
-  end
-
-  class TestStringFormatting < Test::Unit::TestCase
-    def test_formatting_with_a_Bignum
-      assert_nothing_raised(RangeError) { "%d" % 68727360256 }
-    end
-  end
-
-  class TestIncludingModuleInClass < Test::Unit::TestCase
-    module ClassInstanceMethod
-      def a_class_instance_method; end
-    end
-
-    class ::Class
-      include ClassInstanceMethod
-    end
-
-    def test_class_should_respond_to_methods_included_in_Class
-      assert Class.new.respond_to?(:a_class_instance_method)
-    end
-  end
-
-  class TestIncludingModuleInModule < Test::Unit::TestCase
-    module ModuleInstanceMethod
-      def a_module_instance_method; end
-    end
-
-    class ::Module
-      include ModuleInstanceMethod
-    end
-
-    def test_module_should_respond_to_methods_included_in_Module
-      assert Module.new.respond_to?(:a_module_instance_method)
-    end
-  end
-
-  class TestConstantLookup < Test::Unit::TestCase
-    module Namespace
-      NamespacedConstant = nil
-      class NamespacedClass; end
-    end
-
-    def test_should_not_find_namespaced_constants # works
-      assert_raise(NameError) { NamespacedConstant }
-    end
-
-    def test_should_not_find_namespaced_classes # fails
-      assert_raise(NameError) { NamespacedClass }
-    end
-  end
-
-  class TestRespondTo < Test::Unit::TestCase
-    class RespondTo
-      def respond_to?(method, hidden = false)
-        super
-      end
-    end
-
-    def test_super_implementation
-      assert_nothing_raised(SystemStackError) do
-        RespondTo.new.respond_to?(:object_id)
-      end
-    end
-  end
-
-  class TestBooleanComparison < Test::Unit::TestCase
-    def test_NSCFBoolean_comparison_to_Ruby_bool
-      assert_equal true,  NSNumber.numberWithBool(true)
-      assert_equal false, NSNumber.numberWithBool(false)
-    end
-  end
-end
\ No newline at end of file

Deleted: MacRuby/trunk/test-macruby/known_bugs_in_c.c
===================================================================
--- MacRuby/trunk/test-macruby/known_bugs_in_c.c	2009-01-15 12:52:28 UTC (rev 791)
+++ MacRuby/trunk/test-macruby/known_bugs_in_c.c	2009-01-15 15:28:56 UTC (rev 792)
@@ -1,17 +0,0 @@
-#include "ruby/ruby.h"
-
-static VALUE
-known_bug_rb_str_split2(VALUE recv, VALUE str, VALUE sep)
-{
-  VALUE parts = rb_str_split2(str, sep);
-  // Accessing the array goes wrong, has it been collected?
-  // Because at the end of rb_str_split_m the `result' _is_ the array as expected…
-  return rb_ary_entry(parts, 0);
-}
-
-void Init_known_bugs_in_c() {
-  VALUE cKnownBugsInC;
-  
-  cKnownBugsInC = rb_define_module("KnownBugsInC");
-  rb_define_module_function(cKnownBugsInC, "test_rb_str_split2", known_bug_rb_str_split2, 2);
-}
\ No newline at end of file

Deleted: MacRuby/trunk/test-macruby/rubycocoa_test.rb
===================================================================
--- MacRuby/trunk/test-macruby/rubycocoa_test.rb	2009-01-15 12:52:28 UTC (rev 791)
+++ MacRuby/trunk/test-macruby/rubycocoa_test.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -1,253 +0,0 @@
-#!/usr/local/bin/macruby
-
-require "test/spec"
-require 'mocha'
-
-#require File.expand_path('../../lib/osx/cocoa', __FILE__)
-require 'osx/cocoa'
-
-class TestRubyCocoaStyleMethod < OSX::NSObject
-  def initialize
-    @set_from_initialize = 'represent!'
-  end
-  
-  def perform_selector_with_object(sel, obj)
-    callMethod_withArgs(sel, obj)
-  end
-  
-  def callMethod(method, withArgs:args)
-    send(method, *args)
-  end
-  
-  def method_rubyCocoaStyle_withExtraArg(mname, rc_style, arg)
-    "#{mname}(#{rc_style}, #{arg})"
-  end
-  
-  def method_notRubyCocoaStyle(first_arg, second_arg, third_arg)
-  end
-  
-  def self.classMethod(mname, macRubyStyle:mr_style, withExtraArg:arg)
-    "#{mname}(#{mr_style}, #{arg})"
-  end
-end
-
-class TestRubyCocoaStyleSuperMethod < OSX::NSObject
-  def init
-    self if super_init
-  end
-end
-
-class NSObjectSubclassWithInitialize < OSX::NSObject
-  def initialize
-    @set_from_initialize = 'represent!'
-  end
-end
-
-class NSObjectSubclassWithoutInitialize < OSX::NSObject; end
-
-CONSTANT_IN_THE_TOPLEVEL_OBJECT_INSTEAD_OF_OSX = true
-
-describe "RubyCocoa layer, in general" do
-  xit "should load AppKit when the osx/cocoa file is loaded" do
-    Kernel.expects(:framework).with('AppKit')
-    load 'osx/cocoa.rb'
-  end
-  
-  it "should set a global variable which indicates that a framework is being loaded" do
-    Kernel.expects(:__framework_before_rubycocoa_layer).with do |f|
-      $LOADING_FRAMEWORK.should.be true
-      f == 'Foo'
-    end
-    Kernel.framework 'Foo'
-    $LOADING_FRAMEWORK.should.be false
-  end
-end
-
-describe "NSObject additions" do
-  before do
-    @obj = TestRubyCocoaStyleMethod.alloc.init
-  end
-  
-  it "should alias ib_outlet to ib_outlets" do
-    TestRubyCocoaStyleMethod.private_methods.should.include :ib_outlets
-  end
-  
-  it "should call initialize from init if it exists" do
-    NSObjectSubclassWithInitialize.alloc.init.instance_variable_get(:@set_from_initialize).should == 'represent!'
-    NSObjectSubclassWithoutInitialize.alloc.init.instance_variable_get(:@set_from_initialize).should.be nil
-  end
-  
-  it "should catch RubyCocoa style instance method, call the correct MacRuby style method and define a shortcut method" do
-    @obj.perform_selector_with_object('description', nil).should.match /^<TestRubyCocoaStyleMethod/
-    @obj.respond_to?(:callMethod_withArgs).should.be true
-    @obj.perform_selector_with_object('description', nil).should.match /^<TestRubyCocoaStyleMethod/
-  end
-  
-  it "should catch RubyCocoa style instance methods that end with a underscore" do
-    @obj.callMethod_withArgs_('description', nil).should.match /^<TestRubyCocoaStyleMethod/
-    @obj.respond_to?(:callMethod_withArgs_).should.be true
-  end
-  
-  it "should catch RubyCocoa style instance methods defined in Objective-C" do
-    color = NSColor.colorWithCalibratedRed(1.0, green:1.0, blue:1.0, alpha:1.0)
-    lambda { color.blendedColorWithFraction_ofColor(0.5, NSColor.greenColor) }.should.not.raise NoMethodError
-  end
-  
-  it "should catch RubyCocoa style class methods defined in ruby" do
-    lambda { TestRubyCocoaStyleMethod.classMethod_macRubyStyle_withExtraArg(1, 2, 3) }.should.not.raise NoMethodError
-    TestRubyCocoaStyleMethod.respond_to?(:classMethod_macRubyStyle_withExtraArg).should.be true
-  end
-  
-  it "should catch RubyCocoa style class methods defined in Objective-C" do
-    lambda { NSColor.colorWithCalibratedRed_green_blue_alpha(1.0, 1.0, 1.0, 1.0) }.should.not.raise NoMethodError
-    NSColor.respond_to?(:colorWithCalibratedRed_green_blue_alpha).should.be true
-  end
-  
-  it "should still raise NoMethodError if a class method doesn't exist" do
-    lambda { NSColor.colorWithCalibratedRed_pink(1.0, 1.0) }.should.raise NoMethodError
-  end
-  
-  it "should also work on other regular NSObject subclasses" do
-    nsstring = 'foo'
-    nsstring.insertString_atIndex('bar', 3)
-    nsstring.should == 'foobar'
-  end
-  
-  it "should still raise a NoMethodError if the selector doesn't exist when a method is missing" do
-    lambda { @obj.does_not_exist }.should.raise NoMethodError
-    lambda { @obj.doesnotexist_ }.should.raise NoMethodError
-    lambda { @obj.doesnotexist }.should.raise NoMethodError
-  end
-  
-  it "should be possible to call super_foo type methods" do
-    lambda { TestRubyCocoaStyleSuperMethod.alloc.init }.should.not.raise.exception
-  end
-  
-  it "should handle objc_send style methods" do
-    nsstring = 'foo'
-    nsstring.objc_send(:insertString, 'bar', :atIndex, 3)
-    nsstring.should == 'foobar'
-    nsstring.objc_send(:description).should == 'foobar'
-    lambda { nsstring.objc_send(:does_not_exist) }.should.raise NoMethodError
-  end
-  
-  it "should create MacRuby style method aliases for any method containing underscores" do
-    @obj.respond_to?(:"method:rubyCocoaStyle:withExtraArg:").should.be true
-    @obj.method('foo', rubyCocoaStyle:true, withExtraArg:false).should == 'foo(true, false)'
-  end
-  
-  it "should not create MacRuby style method aliases for methods containing underscores if the arity doesn't match" do
-    @obj.respond_to?(:"method:notRubyCocoaStyle:").should.be false
-  end
-  
-  it "should respond to to_ruby" do
-    @obj.respond_to?(:to_ruby).should.be true
-  end
-end
-
-describe 'OSX module' do
-  it "should exist" do
-    defined?(OSX).should.not.be nil # this is weird.. I haven't defined OSX yet?!
-  end
-  
-  it "should load a framework into the runtime" do
-    OSX.require_framework 'WebKit'
-    defined?(WebView).should.not.be nil
-    
-    OSX.require_framework '/System/Library/Frameworks/QTKit.framework'
-    defined?(QTMovie).should.not.be nil
-  end
-  
-  it "should forward messages to Kernel if it responds to it" do
-    Kernel.expects(:NSRectFill).with(1, 2).times(2)
-    OSX::NSRectFill(1, 2)
-    OSX.respond_to?(:NSRectFill).should.be true
-    OSX::NSRectFill(1, 2)
-    
-    lambda { OSX::NSRectFillllllll(1, 2) }.should.raise NoMethodError
-  end
-  
-  it "should try to get missing constants from the toplevel object" do
-    OSX::CONSTANT_IN_THE_TOPLEVEL_OBJECT_INSTEAD_OF_OSX.should.be true
-  end
-  
-  it "should still raise a NameError from OSX, not from the toplevel object, when a constant is missing" do
-    lambda { OSX::DOES_NOT_EXIST_IN_TOPLEVEL_OBJECT }.should.raise NameError
-    
-    begin
-      OSX::DOES_NOT_EXIST_IN_TOPLEVEL_OBJECT
-    rescue NameError => e
-      e.message.should.include 'OSX::DOES_NOT_EXIST_IN_TOPLEVEL_OBJECT'
-    end
-  end
-end
-
-describe 'NSData additions' do
-  before do
-    path = '/System/Library/DTDs/BridgeSupport.dtd'
-    @obj = NSData.dataWithContentsOfFile(path)
-    @ruby_data = File.read(path)
-  end
-
-  it "should respond to rubyString" do
-    @obj.respond_to?(:rubyString).should.be true
-    @obj.rubyString.should.equal @ruby_data
-  end
-end
-
-describe 'NSUserDefaults additions' do
-  before do
-    @obj = NSUserDefaults.alloc.init
-  end
-  
-  it "should respond to [] and []=" do
-    @obj.respond_to?(:[]).should.be true
-    @obj.respond_to?(:[]=).should.be true
-    @obj['key'] = 'value'
-    @obj['key'].should.equal 'value'
-  end
-end
-
-describe 'NSIndexSet additions' do
-  before do
-    @obj = NSIndexSet.alloc.init
-  end
-  
-  it "should respond to to_a" do
-    @obj.respond_to?(:to_a).should.be true
-  end
-end
-
-describe 'NSNumber additions' do
-  before do
-    @i = NSNumber.numberWithInt(42)
-    @f = NSNumber.numberWithDouble(42.42)
-  end
-  
-  it "should respond to to_i and to_f" do
-    @i.respond_to?(:to_i).should.be true
-    @i.respond_to?(:to_f).should.be true
-    @i.to_i.should.equal 42
-    @f.to_f.should.equal 42.42
-  end
-end
-
-describe 'NSDate additions' do
-  before do
-    @obj = NSDate.alloc.init
-  end
-  
-  it "should respond to to_time" do
-    @obj.respond_to?(:to_time).should.be true
-  end
-end
-
-describe 'NSImage additions' do
-  before do
-    @obj = NSImage.alloc.init
-  end
-  
-  it "should respond to focus" do
-    @obj.respond_to?(:focus).should.be true
-  end
-end

Modified: MacRuby/trunk/test-macruby/runner.rb
===================================================================
--- MacRuby/trunk/test-macruby/runner.rb	2009-01-15 12:52:28 UTC (rev 791)
+++ MacRuby/trunk/test-macruby/runner.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -1,2 +1,3 @@
-path = File.dirname(__FILE__)
-Dir.glob(File.join(path, 'test_*.rb')).each { |p| require(p) }
+Dir.glob(File.expand_path('../cases/*_test.rb', __FILE__)).each do |test|
+  require test
+end
\ No newline at end of file

Deleted: MacRuby/trunk/test-macruby/test_boxed.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_boxed.rb	2009-01-15 12:52:28 UTC (rev 791)
+++ MacRuby/trunk/test-macruby/test_boxed.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -1,180 +0,0 @@
-require 'test/unit'
-
-class TestBS < Test::Unit::TestCase
-
-  def setup
-    framework 'Foundation'
-    bundle = '/tmp/_test_bs.bundle'
-    if !File.exist?(bundle) or File.mtime(bundle) < File.mtime(__FILE__)
-      s = <<EOS
-#import <Foundation/Foundation.h>
- at interface NSObject (MacRubyNSPointAdditions)
-- (float)x;
-- (float)y;
- at end
- at interface TestBoxed : NSObject
- at end
- at implementation TestBoxed
-- (void)testPoint:(NSPoint)point x:(float)x y:(float)y
-{
-    if (point.x != x)
-        [NSException raise:@"NSException"
-            format:@"point.x (%f) != x (%f)", point.x, x];
-  
-    if (point.y != y) 
-        [NSException raise:@"NSException"
-            format:@"point.y (%f) != y (%f)", point.y, y];
-}
-- (void)testPointAsObject:(id)point x:(float)x y:(float)y
-{
-    Class boxed;
-    boxed = NSClassFromString(@"Boxed");
-
-    if (![point isKindOfClass:boxed]) 
-        [NSException raise:@"NSException"
-            format:@"point (%@) isn't a boxed type", point];
-
-    if (![point isKindOfClass:[NSValue class]]) 
-        [NSException raise:@"NSException"
-            format:@"point (%@) isn't a value type", point];
-
-#if 0 // FIXME this cannot be tested yet 
-    if ([point x] != x)       
-        [NSException raise:@"NSException"
-            format:@"[point x] (%f) != x (%f)", [point x], x];
-
-    if ([point y] != y)       
-        [NSException raise:@"NSException"
-            format:@"[point y] (%f) != y (%f)", [point y], y];
-#endif
-
-    if (strcmp([point objCType], @encode(NSPoint)) != 0)
-        [NSException raise:@"NSException"
-            format:@"[point objCType] (%s) != @encode(NSPoint) (%s)", 
-	    [point objCType], @encode(NSPoint)];
-
-    NSPoint p;
-    [point getValue:&p];
-    [self testPoint:p x:x y:y];   
-}
-- (NSPoint)testReturnPointWithX:(float)x y:(float)y
-{
-    NSPoint p;
-    p.x = x;
-    p.y = y;
-    return p;
-}
- at end
-EOS
-      File.open('/tmp/_test.m', 'w') { |io| io.write(s) }
-      system("gcc /tmp/_test.m -bundle -o #{bundle} -framework Foundation -fobjc-gc-only") or exit 1
-    end
-    require 'dl'; DL.dlopen(bundle)
-  end
-  
-  def test_boxed_classes
-    assert_kind_of(Class, Boxed)
-    assert_equal(NSValue, Boxed.superclass)
-
-    # struct
-    assert(NSRect.ancestors.include?(Boxed))
-    assert('{_NSRect={_NSPoint=ff}{_NSSize=ff}}', NSRect.objc_type)
-    assert_equal([:origin, :size] , NSRect.fields)
-    assert(!NSRect.opaque?)
-
-    # opaque
-    assert(NSZone.ancestors.include?(Boxed))
-    assert_equal('^{_NSZone=}', NSZone.objc_type)
-    assert_equal([] , NSZone.fields)
-    assert(NSZone.opaque?)
-  end
-
-  def test_opaque
-    assert_raise(TypeError) { NSZone.new }
-    z = 'foo'.zone
-    assert_kind_of(NSZone, z)
-    assert_equal(z, 'bar'.zone)
-  end
-
-  def test_struct1
-    p = NSPoint.new
-    assert_kind_of(NSPoint, p)
-    assert_equal(0.0, p.x)
-    assert_equal(0.0, p.y)
-    assert_equal([0.0, 0.0], p.to_a)
-    assert_equal(p, NSPoint.new)
-    assert_equal(p, p.dup)
-    assert_equal(p, p.clone)
-    assert_equal(p, NSZeroPoint)
-
-    p.x += 1
-    assert_equal(1.0, p.x)
-    assert_equal([1.0, 0.0], p.to_a)
-    
-    p2 = NSPoint.new(1.0, 2.0)
-    assert_equal(p.x, p2.x)
-    assert_not_equal(p.y, p2.y)
-    p.y += 2
-    assert_equal(p.y, p2.y)
-
-    assert_raise(ArgumentError) { NSPoint.new(42) }
-    assert_raise(ArgumentError) { NSPoint.new(42, 42, 42) }
-    assert_raise(TypeError) { NSPoint.new(nil, nil) }
-    assert_raise(ArgumentError) { NSPoint.new('foo', 'bar') }
-    assert_raise(TypeError) { p.x = nil }
-    assert_raise(ArgumentError) { p.x = 'foo' }
-
-    r = NSRect.new
-    assert_kind_of(NSRect, r)
-    assert_equal(NSZeroPoint, r.origin)
-    assert_equal(NSZeroSize, r.size) 
-    assert_equal([NSZeroPoint, NSZeroSize], r.to_a)
-    
-    assert_raise(ArgumentError) { r.origin = nil }
-    assert_raise(ArgumentError) { r.origin = 'foo' }
-
-    r2 = NSRect.new(p, NSSize.new(42.0, 42.0))
-    assert_not_equal(r, r2)
-    r.size = NSSize.new(42.0, 42.0)
-    assert_equal(r.size, r2.size)
-    r.origin = p
-    assert_equal(r.origin, r2.origin)
-    assert_equal(r, r2)
-    r.origin.x -= 1
-    r2.origin.x -= 1
-    r.size.width /= 2.0
-    r2.size.width /= 2.0
-    assert_equal(r, r2)
-    assert_equal(r.to_a, r2.to_a)
-  end
-
-  def test_struct_nsstring_marshalling
-    r = NSRange.new(1, 4)
-    assert_kind_of(NSString, NSStringFromRange(r))
-    assert_equal('{1, 4}', NSStringFromRange(r))
-    assert_equal(r, NSRangeFromString(NSStringFromRange(r)))
-    rect = NSRect.new(NSPoint.new(42.0, 1042.0), NSSize.new(123, 456))
-    assert_equal(NSPoint.new(42.0, 1042.0),
-      NSPointFromString(NSStringFromPoint(rect.origin)))
-  end
-
-  def test_nspoint_in_objc
-    p = NSPoint.new(42.0, 99.0)
-    o = TestBoxed.new
-    o.testPoint(p, x:42.0, y:99.0)
-    o.testPointAsObject(p, x:42.0, y:99.0)
-    assert_equal(p, o.testReturnPointWithX(42.0, y:99.0))
-  end
-
-  class MethodReturningBoxed
-    def foo
-      NSPoint.new(1, 2)
-    end
-  end
-  def test_objc_call_pure_method_returning_boxed
-    o = MethodReturningBoxed.new
-    assert_equal(NSPoint.new(1, 2), o.send(:foo))
-    assert_equal(NSPoint.new(1, 2), o.performSelector(:foo))
-  end
-
-end

Deleted: MacRuby/trunk/test-macruby/test_framework.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_framework.rb	2009-01-15 12:52:28 UTC (rev 791)
+++ MacRuby/trunk/test-macruby/test_framework.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -1,27 +0,0 @@
-require 'test/unit'
-
-class TestFramework < Test::Unit::TestCase
-
-  def test_setup
-    framework('Foundation')
-  end
-
-  def test_framework_by_name
-    assert_nothing_raised { framework('Foundation') }
-    assert_raise(RuntimeError) { framework('DoesNotExist') }
-  end
-
-  def test_framework_by_path
-    assert_nothing_raised do 
-      framework('/System/Library/Frameworks/Foundation.framework')
-    end
-    assert_raise(RuntimeError) { framework('/does/not/exist') }
-  end
-
-  def test_framework_load_twice
-    assert_equal(false, framework('Foundation'))
-    assert_equal(false,
-      framework('/System/Library/Frameworks/Foundation.framework'))
-  end
-
-end

Deleted: MacRuby/trunk/test-macruby/test_hash.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_hash.rb	2009-01-15 12:52:28 UTC (rev 791)
+++ MacRuby/trunk/test-macruby/test_hash.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -1,89 +0,0 @@
-require 'test/unit'
-
-class TestHash < Test::Unit::TestCase
-
-  def test_hash_class
-    assert(Hash.is_a?(Class))
-    assert(Hash.ancestors.include?(NSDictionary))
-    assert(Hash.ancestors.include?(NSMutableDictionary))
-  end
-
-  def test_hash_create
-    h = {}
-    assert_kind_of(Hash, h)
-    h = {'a' => 100}
-    assert_kind_of(Hash, h)
-    h = Hash.new
-    assert_kind_of(Hash, h)
-    h = Hash.alloc.init
-    assert_kind_of(Hash, h)
-    h = Hash['a', 100, 'b', 200]
-    assert_kind_of(Hash, h)
-    h = Hash['a' => 100, 'b' => 200]
-    assert_kind_of(Hash, h)
-  end
-
-  class MyHash < Hash; end
-  def test_hash_create_subclass
-    assert(MyHash.ancestors.include?(Hash))
-    h = MyHash.new
-    assert_kind_of(MyHash, h)
-    h = MyHash.alloc.init
-    assert_kind_of(MyHash, h)
-    h = MyHash['a', 100, 'b', 200]
-    assert_kind_of(MyHash, h)
-    h = MyHash['a' => 100, 'b' => 200]
-    assert_kind_of(MyHash, h)
-  end
-
-  def test_hash_cannot_modify_immutable
-    h = NSDictionary.new
-    assert_raise(RuntimeError) { h[1] = 1 }
-    assert_raise(RuntimeError) { h.clear }
-    h = NSDictionary.alloc.init
-    assert_raise(RuntimeError) { h[1] = 1 }
-    assert_raise(RuntimeError) { h.clear }
-  end
-
-  def test_hash_get_set
-    h = {}
-    h[1] = 2
-    assert_equal(2, h[1])
-    h['foo'] = 3
-    assert_equal(3, h['foo'])
-    assert_equal(3, h[String.new('foo')])
-    h[[1,2]] = 4
-    assert_equal(4, h[[1,2]])
-    assert_equal(4, h[Array.new([1,2])])
-    h[:sym] = 5
-    assert_equal(5, h[:sym])
-    assert_equal(5, h['sym'.intern])
-  end
-
-  def test_hash_count
-    h = {}
-    assert_equal(0, h.size)
-    assert_equal(0, h.count)
-    assert(h.empty?)
-    h[1] = 2
-    assert_equal(1, h.size)
-    assert_equal(1, h.count)
-    assert(!h.empty?)
-    h[1] = nil
-    assert_equal(1, h.size)
-    assert_equal(1, h.count)
-    assert(!h.empty?)
-    h.delete(1)
-    assert_equal(0, h.size)
-    assert_equal(0, h.count)
-    assert(h.empty?)
-  end
-
-  def test_hash_clear
-    h = {1=>2}
-    h.clear
-    assert(h.empty?)
-    assert_equal(nil, h[1])
-  end
-
-end

Added: MacRuby/trunk/test-macruby/test_helper/objective-c_helper.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_helper/objective-c_helper.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/test_helper/objective-c_helper.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,54 @@
+require File.expand_path('../temp_dir_helper', __FILE__)
+require 'dl'
+
+# Eloy: From Kari, will probably move to Rucola, so need to update.
+class ObjectiveC
+  class CompileError < ::StandardError; end
+  
+  include TempDirHelper
+  
+  # Returns a new ObjectiveC compile instance with the +source_file+ and the
+  # +frameworks+ needed to compile this +source_file+. Foundation is added to
+  # the +frameworks+ by default.
+  #
+  #   objc = ObjectiveC.new('/path/to/source_file.m', 'WebKit')
+  #   objc.compile!
+  #   objc.require!
+  def initialize(source_file, *frameworks)
+    @path, @frameworks = source_file, frameworks
+    @frameworks.unshift 'Foundation'
+  end
+  
+  # Compiles the +source_file+. See new.
+  # Raises a ObjectiveC::CompileError if compilation failed.
+  #
+  # TODO: Check the arch build flags etc.
+  def compile!
+    ensure_dir!(output_dir)
+    
+    frameworks = @frameworks.map { |f| "-framework #{f}" }.join(' ')
+    command = "gcc -o #{ bundle_path } -arch x86_64 -fobjc-gc -flat_namespace -undefined suppress -bundle #{ frameworks } #{ includes } #{ @path }"
+    unless system(command)
+      raise CompileError, "Unable to compile file `#{ File.basename(@path) }'."
+    end
+  end
+  
+  # Loads the compiled bundle with <tt>DL.dlopen</tt>.
+  def require!
+    DL.dlopen(bundle_path)
+  end
+  
+  private
+  
+  def includes
+    "-I#{ File.dirname(@path) }"
+  end
+  
+  def output_dir
+    temp_dir 'bundles'
+  end
+  
+  def bundle_path
+    File.join output_dir, "#{ File.basename(@path, '.m') }.bundle"
+  end
+end
\ No newline at end of file

Added: MacRuby/trunk/test-macruby/test_helper/temp_dir_helper.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_helper/temp_dir_helper.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/test_helper/temp_dir_helper.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,19 @@
+require "fileutils"
+
+module TempDirHelper
+  def ensure_dir!(path)
+    FileUtils.mkdir_p(path) unless File.exist?(path)
+  end
+  
+  def setup_temp_dir!
+    ensure_dir!(temp_dir)
+  end
+  
+  def teardown_temp_dir!
+    FileUtils.rm_rf(temp_dir) if File.exist?(temp_dir)
+  end
+  
+  def temp_dir(path = nil)
+    path.nil? ? TMP_PATH : File.join(TMP_PATH, path)
+  end
+end
\ No newline at end of file

Added: MacRuby/trunk/test-macruby/test_helper/test_unit_helper.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_helper/test_unit_helper.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/test_helper/test_unit_helper.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,27 @@
+# The following is just a simple hack to be able to write tests with a spec description.
+# This should ease the process of moving tests to run with mspec for instance.
+class Test::Unit::TestCase
+  class << self
+    # Runs before each test case.
+    def before(&block)
+      define_method("setup", &block)
+    end
+    
+    # Runs after each test case.
+    def after(&block)
+      define_method("teardown", &block)
+    end
+    
+    # Defines a test case.
+    def it(name, &block)
+      define_method("test_#{name}", &block)
+    end
+  end
+  
+  private
+  
+  # Returns the path to a file in +FIXTURE_PATH+.
+  def fixture(name)
+    File.join(FIXTURE_PATH, name)
+  end
+end
\ No newline at end of file

Added: MacRuby/trunk/test-macruby/test_helper.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_helper.rb	                        (rev 0)
+++ MacRuby/trunk/test-macruby/test_helper.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -0,0 +1,13 @@
+require 'test/unit'
+framework 'Foundation'
+
+# Add ruby lib to the load path
+$:.unshift(File.expand_path('../../lib', __FILE__))
+
+FIXTURE_PATH = File.expand_path('../fixtures', __FILE__)
+TMP_PATH = File.expand_path('../tmp', __FILE__)
+
+# Load all test helpers
+Dir.glob(File.expand_path('../test_helper/*_helper.rb', __FILE__)).each do |helper|
+  require helper
+end

Deleted: MacRuby/trunk/test-macruby/test_objc.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_objc.rb	2009-01-15 12:52:28 UTC (rev 791)
+++ MacRuby/trunk/test-macruby/test_objc.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -1,155 +0,0 @@
-#!/usr/bin/env macruby
-
-require 'test/unit'
-
-require 'test/unit'
-class Test::Unit::TestCase
-  class << self
-    def it(name, &block)
-      define_method("test_#{name}", &block)
-    end
-  end
-end
-
-class TestClassConstantLookup < Test::Unit::TestCase
-  module Namespace
-    class PureRubyClass; end
-    module PureRubyModule; end
-    SINGLETON = (class << self; self; end)
-  end
-  
-  it "should not find pure Ruby classes in different namespaces" do
-    assert_raise(NameError) { PureRubyClass }
-  end
-  
-  it "should find pure Ruby classes in different namespaces if given the correct path" do
-    assert_nothing_raised(NameError) { Namespace::PureRubyClass }
-  end
-  
-  it "should not find pure Ruby modules in different namespaces" do
-    assert_raise(NameError) { PureRubyModule }
-  end
-  
-  it "should find pure Ruby modules in different namespaces if given the correct path" do
-    assert_nothing_raised(NameError) { Namespace::PureRubyModule }
-  end
-  
-  it "should not find pure Ruby class singletons in different namespaces" do
-    assert_raise(NameError) { SINGLETON }
-  end
-  
-  it "should find pure Ruby class singletons in different namespaces if given the correct path" do
-    assert_nothing_raised(NameError) { Namespace::SINGLETON }
-  end
-end
-
-class TestSubclass < Test::Unit::TestCase
-
-  def setup
-    framework 'Foundation'
-    bundle = '/tmp/_test.bundle'
-    if !File.exist?(bundle) or File.mtime(bundle) < File.mtime(__FILE__)
-      s = <<EOS
-#import <Foundation/Foundation.h>
- at interface MyClass : NSObject
- at end
- at implementation MyClass
-- (int)test
-{
-    return 42;
-}
-- (id)test_getObject:(id)dictionary forKey:(id)key
-{
-  return [dictionary objectForKey:key];
-}
- at end
-EOS
-      File.open('/tmp/_test.m', 'w') { |io| io.write(s) }
-      system("gcc /tmp/_test.m -bundle -o #{bundle} -framework Foundation -fobjc-gc-only") or exit 1
-    end
-    require 'dl'; DL.dlopen(bundle)
-  end
-
-  def test_new
-    o = NSObject.new
-    assert_kind_of(NSObject, o)
-    o = NSObject.alloc.init
-    assert_kind_of(NSObject, o)
-  end
-
-  class MyDictionary < NSMutableDictionary
-    def foo(tc, *args)
-      tc.assert_kind_of(Array, args)
-      unless args.empty?
-        tc.assert_equal(1, args.length)
-        tc.assert_kind_of(Hash, args[0])
-      end
-    end
-    def foo2(tc, args)
-      tc.assert_kind_of(Hash, args)
-    end
-  end
-
-  def test_keyed_syntax
-    d = NSMutableDictionary.new
-    o = NSObject.new
-    k = NSString.new
-    d.setObject o, forKey:k
-    assert_equal(o, d.objectForKey(k))
-
-    d2 = MyDictionary.new
-    d2.foo(self)
-    d2.foo(self, foo:k)
-    d2.foo(self, foo:k, bar:k)
-    d2.foo2(self, foo:k, bar:k)
-
-    d2 = NSMutableDictionary.performSelector('new')
-    d2.performSelector(:'setObject:forKey:', withObject:o, withObject:k)
-    assert_equal(o, d2.performSelector(:'objectForKey:', withObject:k))
-    assert(d.isEqual(d2))
-  end
-
-  def test_pure_objc_ivar
-    o = NSObject.alloc.init
-    assert_kind_of(NSObject, o)
-    o.instance_variable_set(:@foo, 'foo')
-    GC.start
-    assert_equal('foo', o.instance_variable_get(:@foo))
-  end
-
-  def test_cftype_ivar
-    o = NSString.alloc.init
-    assert_kind_of(NSString, o)
-    o.instance_variable_set(:@foo, 'foo')
-    GC.start
-    assert_equal('foo', o.instance_variable_get(:@foo))
-  end
-
-  def test_method_dispatch_priority
-    o = MyClass.new
-    assert_kind_of(MyClass, o)
-    assert_equal(42, o.test)
-  end
-
-  def test_method_variadic
-    p = NSPredicate.predicateWithFormat('foo == 1')
-    assert_kind_of(NSPredicate, p)
-    p = NSPredicate.predicateWithFormat('foo == %@', 'bar')
-    assert_kind_of(NSPredicate, p)
-    p = NSPredicate.predicateWithFormat('%@ == %@', 'foo', 'bar')
-    assert_kind_of(NSPredicate, p)
-  end
-
-  def test_primitive_as_dictionary_key
-    o = MyClass.new
-    assert_kind_of(MyClass, o)
-    s = String.new("foo")
-    v = Object.new
-    dict = {s => v}
-    assert_equal(v, o.test_getObject(dict, forKey:s))
-    dict = {}
-    dict.setObject v, forKey:s
-    assert_equal(v, o.test_getObject(dict, forKey:s))
-  end
-
-end

Deleted: MacRuby/trunk/test-macruby/test_objc_ext.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_objc_ext.rb	2009-01-15 12:52:28 UTC (rev 791)
+++ MacRuby/trunk/test-macruby/test_objc_ext.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -1,97 +0,0 @@
-#!/usr/bin/env macruby
-
-$:.unshift(File.expand_path('../../lib', __FILE__))
-framework 'Cocoa'
-
-require 'test/unit'
-class Test::Unit::TestCase
-  class << self
-    def it(name, &block)
-      define_method("test_#{name}", &block)
-    end
-  end
-end
-
-# These tests should probably move to the macruby part of rubyspec once we get to that point.
-
-require 'objc_ext/ns_user_defaults'
-
-class TestNSUserDefaultsExtensions < Test::Unit::TestCase
-  it "should returns a value for a given key through the #[] reader method" do
-    defaults.setValue('foo', forKey: 'key')
-    assert_equal 'foo', defaults['key']
-  end
-  
-  it "should assign a value for a given key through the #[]= writer method" do
-    defaults['key'] = 'foo'
-    assert_equal 'foo', defaults.valueForKey('key')
-  end
-  
-  it "should remove an object for a given key with the #delete method" do
-    defaults.setValue('foo', forKey: 'key')
-    defaults.delete('key')
-    assert_nil defaults.valueForKey('key')
-  end
-  
-  private
-  
-  def defaults
-    NSUserDefaults.standardUserDefaults
-  end
-end
-
-require 'objc_ext/ns_rect'
-
-class TestNSRectExtensions < Test::Unit::TestCase
-  def setup
-    @rect = NSRect.new([100, 100], [200, 200])
-  end
-  
-  it "should return its size instance's height with #height" do
-    assert_equal 200, @rect.height
-  end
-  
-  it "should assign the height to its size instance with #height=" do
-    @rect.height = 300
-    assert_equal 300, @rect.height
-    
-    @rect.height = NSNumber.numberWithInt(400)
-    assert_equal 400, @rect.height
-  end
-  
-  it "should return its size instance's width with #width" do
-    assert_equal 200, @rect.width
-  end
-  
-  it "should assign the width to its size instance with #width=" do
-    @rect.width = 300
-    assert_equal 300, @rect.width
-    
-    @rect.width = NSNumber.numberWithInt(400)
-    assert_equal 400, @rect.width
-  end
-  
-  it "should return its origin instance's x coord with #x" do
-    assert_equal 100, @rect.x
-  end
-  
-  it "should assign the x coord to its origin instance with #x=" do
-    @rect.x = 200
-    assert_equal 200, @rect.x
-    
-    @rect.x = NSNumber.numberWithInt(300)
-    assert_equal 300, @rect.x
-  end
-  
-  it "should return its origin instance's y coord with #y" do
-    assert_equal 100, @rect.y
-  end
-  
-  it "should assign the y coord to its origin instance with #y=" do
-    @rect.y = 200
-    assert_equal 200, @rect.y
-    
-    @rect.y = NSNumber.numberWithInt(300)
-    assert_equal 300, @rect.y
-  end
-end
\ No newline at end of file

Deleted: MacRuby/trunk/test-macruby/test_string.rb
===================================================================
--- MacRuby/trunk/test-macruby/test_string.rb	2009-01-15 12:52:28 UTC (rev 791)
+++ MacRuby/trunk/test-macruby/test_string.rb	2009-01-15 15:28:56 UTC (rev 792)
@@ -1,66 +0,0 @@
-# -*- coding: utf-8 -*-
-
-require 'test/unit'
-
-class TestString < Test::Unit::TestCase
-
-  def setup
-    framework 'Foundation'
-    bundle = '/tmp/_test_string.bundle'
-    if !File.exist?(bundle) or File.mtime(bundle) < File.mtime(__FILE__)
-      s = <<EOS
-#import <Foundation/Foundation.h>
- at interface MyTestClass : NSObject
- at end
- at implementation MyTestClass
-- (NSString*)testSubstring:(NSString*)str range:(NSRange)range
-{
-    unichar buf[1024];
-    [str getCharacters:buf range:range];
-    return [[NSString alloc] initWithCharacters:buf length:range.length];
-}
- at end
-EOS
-      File.open('/tmp/_test_string.m', 'w') { |io| io.write(s) }
-      system("gcc /tmp/_test_string.m -bundle -o #{bundle} -framework Foundation -fobjc-gc-only") or exit 1
-    end
-    require 'dl'; DL.dlopen(bundle)
-  end
-  
-  def test_characterAtIndex
-    s = 'abcあいうxyz'
-    [0,3,6,8].each do |d|
-      assert_equal(s[d].ord, s.characterAtIndex(d))
-      assert_equal(s[d].ord, s.characterAtIndex(d))
-    end
-  end
-  
-  def test_getCharactersRange
-    s = 'abcあいうxzy'
-    obj = MyTestClass.alloc.init
-    [[0,1], [1,7], [4,3], [7,2]].each do |d|
-      assert_equal(s[*d], obj.testSubstring(s, range:NSRange.new(*d)))
-    end
-  end
-  
-  #
-  # Tests for UTF-16 surrogate pairs
-  # These tests should be fixed in the future.
-  #
-  # Memo:
-  #   If an NSString consists of a character which is UTF-16 surrogate pair,
-  #   the length of the string will be 2 in Cocoa, while 1 in ruby 1.9.
-  #
-  
-  def test_characterAtIndex_surrogate_pairs
-    s = "abc\xf0\xa3\xb4\x8exzy"
-    assert_equal(s[3].ord, s.characterAtIndex(3))
-  end
-  
-  def test_getCharactersRange_surrogate_pairs
-    s = "abc\xf0\xa3\xb4\x8exzy"
-    obj = MyTestClass.alloc.init
-    assert_equal(s[2,3], obj.testSubstring(s, range:NSRange.new(2,3)))
-  end
-  
-end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090115/d739d40b/attachment-0001.html>


More information about the macruby-changes mailing list