[macruby-changes] [1849] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Fri Jun 12 17:54:30 PDT 2009


Revision: 1849
          http://trac.macosforge.org/projects/ruby/changeset/1849
Author:   eloy.de.enige at gmail.com
Date:     2009-06-12 17:54:30 -0700 (Fri, 12 Jun 2009)
Log Message:
-----------
Fixed File.expand_path, removed all tags.

We do not comply with MRI in these cases:
* "//" is expanded to "/"
* "/private/tmp" (and others which exist in "/") is expanded to "/tmp"

Tagged failing Kernel#require example.

Made specs green, also had to change MSpec for returning the right tmp path.

Modified Paths:
--------------
    MacRuby/branches/experimental/mspec/lib/mspec/helpers/tmp.rb
    MacRuby/branches/experimental/objc.m
    MacRuby/branches/experimental/spec/frozen/core/dir/chdir_spec.rb
    MacRuby/branches/experimental/spec/frozen/core/dir/fixtures/common.rb
    MacRuby/branches/experimental/spec/frozen/core/file/expand_path_spec.rb
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/kernel/require_tags.txt

Added Paths:
-----------
    MacRuby/branches/experimental/spec/macruby/core/file_spec.rb

Removed Paths:
-------------
    MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/expand_path_tags.txt

Modified: MacRuby/branches/experimental/mspec/lib/mspec/helpers/tmp.rb
===================================================================
--- MacRuby/branches/experimental/mspec/lib/mspec/helpers/tmp.rb	2009-06-12 23:12:46 UTC (rev 1848)
+++ MacRuby/branches/experimental/mspec/lib/mspec/helpers/tmp.rb	2009-06-13 00:54:30 UTC (rev 1849)
@@ -16,13 +16,18 @@
 class Object
   def tmp(name)
     unless @spec_temp_directory
-      [ "/private/tmp", "/tmp", "/var/tmp", ENV["TMPDIR"], ENV["TMP"],
-        ENV["TEMP"], ENV["USERPROFILE"] ].each do |dir|
-        if dir and File.directory?(dir) and File.writable?(dir)
-          temp = File.expand_path dir
-          temp = File.readlink temp if File.symlink? temp
-          @spec_temp_directory = temp
-          break
+      # MacRuby TODO: Discuss with Brian
+      if RUBY_NAME =~ /^macruby/
+        @spec_temp_directory = "/private/tmp"
+      else
+        [ "/private/tmp", "/tmp", "/var/tmp", ENV["TMPDIR"], ENV["TMP"],
+          ENV["TEMP"], ENV["USERPROFILE"] ].each do |dir|
+          if dir and File.directory?(dir) and File.writable?(dir)
+            temp = File.expand_path dir
+            temp = File.readlink temp if File.symlink? temp
+            @spec_temp_directory = temp
+            break
+          end
         end
       end
     end

Modified: MacRuby/branches/experimental/objc.m
===================================================================
--- MacRuby/branches/experimental/objc.m	2009-06-12 23:12:46 UTC (rev 1848)
+++ MacRuby/branches/experimental/objc.m	2009-06-13 00:54:30 UTC (rev 1849)
@@ -192,13 +192,34 @@
 VALUE
 rb_file_expand_path(VALUE fname, VALUE dname)
 {
-    NSString *res = [(NSString *)fname stringByExpandingTildeInPath];
-    if (![res isAbsolutePath]) {
-	NSString *dir = dname != Qnil
-	    	? (NSString *)dname
-		: [[NSFileManager defaultManager] currentDirectoryPath];
-	res = [dir stringByAppendingPathComponent:res];
+    NSString *res = (NSString *)FilePathValue(fname);
+
+    if ([res isAbsolutePath]) {
+      NSString *tmp = [res stringByResolvingSymlinksInPath];
+      // Make sure we don't have an invalid user path.
+      if ([res hasPrefix:@"~"] && [tmp isEqualTo:res]) {
+        NSString *user = [[[res pathComponents] objectAtIndex:0] substringFromIndex:1];
+        rb_raise(rb_eArgError, "user %s doesn't exist", [user UTF8String]);
+      }
+      res = tmp;
     }
+    else {
+      NSString *dir = dname != Qnil ?
+        (NSString *)FilePathValue(dname) : [[NSFileManager defaultManager] currentDirectoryPath];
+
+      if (![dir isAbsolutePath]) {
+        dir = (NSString *)rb_file_expand_path((VALUE)dir, Qnil);
+      }
+
+      // stringByStandardizingPath does not expand "/." to "/".
+      if ([res isEqualTo:@"."] && [dir isEqualTo:@"/"]) {
+        res = @"/";
+      }
+      else {
+        res = [[dir stringByAppendingPathComponent:res] stringByStandardizingPath];
+      }
+    }
+
     return (VALUE)[res mutableCopy];
 }
 

Modified: MacRuby/branches/experimental/spec/frozen/core/dir/chdir_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/dir/chdir_spec.rb	2009-06-12 23:12:46 UTC (rev 1848)
+++ MacRuby/branches/experimental/spec/frozen/core/dir/chdir_spec.rb	2009-06-13 00:54:30 UTC (rev 1849)
@@ -13,16 +13,16 @@
   it "defaults to $HOME with no arguments" do
     if ENV['HOME']
     Dir.chdir(ENV['HOME'])
-    home = Dir.pwd
+    home = DirSpecs.pwd
 
     Dir.chdir
-    Dir.pwd.should == home
+    DirSpecs.pwd.should == home
     end
   end
   
   it "changes to the specified directory" do
     Dir.chdir DirSpecs.mock_dir
-    Dir.pwd.should == DirSpecs.mock_dir
+    DirSpecs.pwd.should == DirSpecs.mock_dir
   end
   
   it "returns 0 when successfully changing directory" do
@@ -34,10 +34,10 @@
   end
   
   it "changes to the specified directory for the duration of the block" do
-    ar = Dir.chdir(DirSpecs.mock_dir) { |dir| [dir, Dir.pwd] }
+    ar = Dir.chdir(DirSpecs.mock_dir) { |dir| [dir, DirSpecs.pwd] }
     ar.should == [DirSpecs.mock_dir, DirSpecs.mock_dir]
 
-    Dir.pwd.should == @original
+    DirSpecs.pwd.should == @original
   end
   
   it "raises a SystemCallError if the directory does not exist" do
@@ -72,6 +72,6 @@
     rescue StandardError
     end
 
-    Dir.pwd.should == @original
+    DirSpecs.pwd.should == @original
   end
 end

Modified: MacRuby/branches/experimental/spec/frozen/core/dir/fixtures/common.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/dir/fixtures/common.rb	2009-06-12 23:12:46 UTC (rev 1848)
+++ MacRuby/branches/experimental/spec/frozen/core/dir/fixtures/common.rb	2009-06-13 00:54:30 UTC (rev 1849)
@@ -1,17 +1,21 @@
 require 'fileutils'
 
 module DirSpecs
-  def DirSpecs.mock_dir(dirs = ['mock'])
+  def self.pwd
+    File.expand_path(Dir.pwd)
+  end
+
+  def self.mock_dir(dirs = ['mock'])
     File.expand_path(tmp(File.join(dirs)))
   end
 
-  def DirSpecs.nonexistent
+  def self.nonexistent
     name = mock_dir + "/nonexistent00"
     name = name.next while File.exist? name
     name
   end
 
-  def DirSpecs.clear_dirs
+  def self.clear_dirs
     old_kcode, $KCODE = $KCODE, 'u'
     ['nonexisting', 'default_perms','reduced', 'always_returns_0', '???', [0xe9].pack('U')].each do |dir|
       begin
@@ -21,7 +25,7 @@
     end
   end
 
-  def DirSpecs.create_mock_dirs
+  def self.create_mock_dirs
     mock_dir = self.mock_dir
     files = %w[
       .dotfile

Modified: MacRuby/branches/experimental/spec/frozen/core/file/expand_path_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/frozen/core/file/expand_path_spec.rb	2009-06-12 23:12:46 UTC (rev 1848)
+++ MacRuby/branches/experimental/spec/frozen/core/file/expand_path_spec.rb	2009-06-13 00:54:30 UTC (rev 1849)
@@ -67,12 +67,18 @@
       File.expand_path('~/').should == ENV['HOME']
       File.expand_path('~/..badfilename').should == "#{ENV['HOME']}/..badfilename"
       File.expand_path('..').should == Dir.pwd.split('/')[0...-1].join("/")
-      File.expand_path('//').should == '//'
       File.expand_path('~/a','~/b').should == "#{ENV['HOME']}/a"
     end
 
+    not_compliant_on :macruby do
+      it "leaves multiple prefixed slashes untouched" do
+        File.expand_path('//').should == '//'
+        File.expand_path('////').should == '////'
+      end
+    end
+
     it "raises an ArgumentError if the path is not valid" do
-      lambda { File.expand_path("~a_fake_file") }.should raise_error(ArgumentError)
+      lambda { File.expand_path("~a_not_existing_user") }.should raise_error(ArgumentError)
     end
 
     it "expands ~ENV['USER'] to the user's home directory" do
@@ -85,7 +91,7 @@
     end
   end
 
-  it "raises an ArgumentError is not passed one or two arguments" do
+  it "raises an ArgumentError if not passed one or two arguments" do
     lambda { File.expand_path }.should raise_error(ArgumentError)
     lambda { File.expand_path '../', 'tmp', 'foo' }.should raise_error(ArgumentError)
   end

Deleted: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/expand_path_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/expand_path_tags.txt	2009-06-12 23:12:46 UTC (rev 1848)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/file/expand_path_tags.txt	2009-06-13 00:54:30 UTC (rev 1849)
@@ -1,7 +0,0 @@
-critical:File.expand_path raises an ArgumentError is not passed one or two arguments
-critical:File.expand_path raises a TypeError if not passed a String type
-fails:File.expand_path converts a pathname to an absolute pathname, using a complete path
-fails:File.expand_path expand path with 
-fails:File.expand_path expand_path for commoms unix path  give a full path
-fails:File.expand_path raises an ArgumentError if the path is not valid
-fails:File.expand_path expands /./dir to /dir

Modified: MacRuby/branches/experimental/spec/frozen/tags/macruby/core/kernel/require_tags.txt
===================================================================
--- MacRuby/branches/experimental/spec/frozen/tags/macruby/core/kernel/require_tags.txt	2009-06-12 23:12:46 UTC (rev 1848)
+++ MacRuby/branches/experimental/spec/frozen/tags/macruby/core/kernel/require_tags.txt	2009-06-13 00:54:30 UTC (rev 1849)
@@ -10,4 +10,5 @@
 fails:Kernel#require bases the filename in $LOADED_FEATURES on the path given, not just basename
 fails:Kernel#require will not load the same file twice, returns false instead
 fails:Kernel#require checks $LOADED_FEATURES to see whether file is already loaded
-fails:Kernel#require does not infinite loop on an rb file that requires itself
\ No newline at end of file
+fails:Kernel#require does not infinite loop on an rb file that requires itself
+fails:Kernel#require appends a file with no extension with .rb/.<ext> in that order to locate file
\ No newline at end of file

Added: MacRuby/branches/experimental/spec/macruby/core/file_spec.rb
===================================================================
--- MacRuby/branches/experimental/spec/macruby/core/file_spec.rb	                        (rev 0)
+++ MacRuby/branches/experimental/spec/macruby/core/file_spec.rb	2009-06-13 00:54:30 UTC (rev 1849)
@@ -0,0 +1,14 @@
+# TODO
+# require File.expand_path('../spec_helper', __FILE__)
+# require File.expand_path('../spec_helper.rb', __FILE__)
+
+require File.dirname(__FILE__) + "/../spec_helper"
+
+describe "File#expand_path" do
+  it "removes prefixed slashes, which isn't done by MRI" do
+    File.expand_path('//').should == '/'
+    File.expand_path('////').should == '/'
+    File.expand_path('////foo').should == '/foo'
+    File.expand_path('////foo//bar').should == '/foo/bar'
+  end
+end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090612/4d19a3bb/attachment-0001.html>


More information about the macruby-changes mailing list