[macruby-changes] [3255] MacRuby/trunk/spec/macruby

source_changes at macosforge.org source_changes at macosforge.org
Tue Jan 12 16:47:25 PST 2010


Revision: 3255
          http://trac.macosforge.org/projects/ruby/changeset/3255
Author:   ernest.prabhakar at gmail.com
Date:     2010-01-12 16:47:23 -0800 (Tue, 12 Jan 2010)
Log Message:
-----------
Passing Dispatch::Source specs for type :READ

Modified Paths:
--------------
    MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb
    MacRuby/trunk/spec/macruby/core/gcd/source_spec_disabled.rb
    MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/source_tags.txt

Modified: MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb	2010-01-13 00:47:20 UTC (rev 3254)
+++ MacRuby/trunk/spec/macruby/core/gcd/source_spec.rb	2010-01-13 00:47:23 UTC (rev 3255)
@@ -141,6 +141,7 @@
           src.resume!
           @q.sync { }
           @i.should == 42 #0b101_010
+          src.cancel!
         end        
       end
 
@@ -155,6 +156,7 @@
           src = Dispatch::Source.new(@type, $$, @mask, @q) { }
           src.should be_kind_of(Dispatch::Source)
           src.suspended?.should == false
+          src.cancel!
         end
 
         it "fires on process event with event mask data" do
@@ -178,6 +180,7 @@
         it "returns an instance of Dispatch::Source" do
           src = Dispatch::Source.new(@type, @signal, 0, @q) { }
           src.should be_kind_of(Dispatch::Source)
+          #src.cancel! - why does this make the subsequent test fail?
         end
 
         it "fires on signal with signal count data" do
@@ -201,33 +204,43 @@
         describe :READ do
           before :each do
             @type = Dispatch::Source::READ
+            File.delete(@filename) if File.exist?(@filename)
+            File.open(@filename, "w") {|f| f.print @msg}
+            @file = File.open(@filename, "r")
           end
+          
+          after :each do
+            @file.close if not @file.closed?
+          end
 
           it "returns an instance of Dispatch::Source" do
-            src = Dispatch::Source.new(@type, $stdin.to_i, 0, @q) { }
+            src = Dispatch::Source.new(@type, @file.to_i, 0, @q) { }
             src.should be_kind_of(Dispatch::Source)
+            src.cancel!            
           end
           
-          it "fires with data on estimate of readable bytes" do
+          it "fires with data on estimated # of readable bytes" do
             @result = ""
-            File.delete(@filename) if File.exist?(@filename)
-            File.open(@filename, "w") {|f| f.puts @msg}
-            file = File.open(@filename, "r")
-            src = Dispatch::Source.new(@type, file.to_i, 0, @q) do |s|
+            src = Dispatch::Source.new(@type, @file.to_i, 0, @q) do |s|
               begin
-                puts "Reading #{s.data} bytes"
-                @result << file.read_nonblock(s.data-1)
-                puts "#{@result}: #{s.data}"
+                @result << @file.read(s.data) # ideally should read_nonblock
               rescue Exception => error
-                puts "OOPS!: #{error}"
-                src.cancel!            
+                puts error
               end
             end
-            src.on_cancel { file.close } #is this a race condition?
             while (@result.size < @msg.size) do; end
+            src.cancel!            
             @q.sync { }
             @result.should == @msg
           end
+          
+          it "does not close file when cancelled" do
+            src = Dispatch::Source.new(@type, @file.to_i, 0, @q) { }
+            src.cancel!
+            @q.sync { }
+            @file.closed?.should == false
+          end
+          
         end    
 
         describe :WRITE do
@@ -258,6 +271,7 @@
       
   end
   
+  
   describe "Dispatch::Timer" do
     before :each do
       @q = Dispatch::Queue.new('org.macruby.gcd_spec.sources')

Modified: MacRuby/trunk/spec/macruby/core/gcd/source_spec_disabled.rb
===================================================================
--- MacRuby/trunk/spec/macruby/core/gcd/source_spec_disabled.rb	2010-01-13 00:47:20 UTC (rev 3254)
+++ MacRuby/trunk/spec/macruby/core/gcd/source_spec_disabled.rb	2010-01-13 00:47:23 UTC (rev 3255)
@@ -373,3 +373,19 @@
   end
 end
     
+describe "via Dispatch::FileSource" do
+  it "returns an instance of Dispatch::Source" do
+    src = Dispatch::FileSource.new(@type, @file.to_i, 0, @q) { }
+    src.should be_kind_of(Dispatch::Source)
+    src.should be_kind_of(Dispatch::FileSource)
+    src.cancel!
+  end
+
+  it "does close file when cancelled" do
+    src = Dispatch::Source.new(@type, @file.to_i, 0, @q) { }
+    src.cancel!
+    @q.sync { }
+    file.closed?.should == true
+  end
+end
+

Modified: MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/source_tags.txt
===================================================================
--- MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/source_tags.txt	2010-01-13 00:47:20 UTC (rev 3254)
+++ MacRuby/trunk/spec/macruby/tags/macruby/core/gcd/source_tags.txt	2010-01-13 00:47:23 UTC (rev 3255)
@@ -1 +0,0 @@
-fails:Dispatch::Source of type file: READ fires with data on estimate of readable bytes
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100112/335d9437/attachment-0001.html>


More information about the macruby-changes mailing list