diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index ed8b613..92b03e9 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -40,3 +40,20 @@ jobs:
run: bundle install
- name: Run test
run: rake compile test
+
+ spec:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v5
+ - uses: ruby/setup-ruby@v1
+ with:
+ ruby-version: ruby
+ - uses: actions/checkout@v5
+ with:
+ repository: ruby/spec
+ path: rubyspec
+ - name: Clone MSpec
+ run: git clone https://github.com/ruby/mspec.git ../mspec
+ - run: bundle install
+ - run: rake compile
+ - run: ../mspec/bin/mspec -Ilib rubyspec/library/pathname
diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c
index 73be963..10d055f 100644
--- a/ext/pathname/pathname.c
+++ b/ext/pathname/pathname.c
@@ -3,7 +3,6 @@
static VALUE rb_cPathname;
static ID id_at_path;
static ID id_sub;
-static ID id_realdirpath;
static VALUE
get_strpath(VALUE obj)
@@ -84,22 +83,6 @@ path_sub(int argc, VALUE *argv, VALUE self)
return rb_class_new_instance(1, &str, rb_obj_class(self));
}
-/*
- * Returns the real (absolute) pathname of +self+ in the actual filesystem.
- *
- * Does not contain symlinks or useless dots, +..+ and +.+.
- *
- * The last component of the real pathname can be nonexistent.
- */
-static VALUE
-path_realdirpath(int argc, VALUE *argv, VALUE self)
-{
- VALUE basedir, str;
- rb_scan_args(argc, argv, "01", &basedir);
- str = rb_funcall(rb_cFile, id_realdirpath, 2, get_strpath(self), basedir);
- return rb_class_new_instance(1, &str, rb_obj_class(self));
-}
-
static void init_ids(void);
void
@@ -119,7 +102,6 @@ InitVM_pathname(void)
rb_cPathname = rb_define_class("Pathname", rb_cObject);
rb_define_method(rb_cPathname, "<=>", path_cmp, 1);
rb_define_method(rb_cPathname, "sub", path_sub, -1);
- rb_define_method(rb_cPathname, "realdirpath", path_realdirpath, -1);
}
void
@@ -128,5 +110,4 @@ init_ids(void)
#undef rb_intern
id_at_path = rb_intern("@path");
id_sub = rb_intern("sub");
- id_realdirpath = rb_intern("realdirpath");
}
diff --git a/lib/pathname.rb b/lib/pathname.rb
index 404be1a..a0db812 100644
--- a/lib/pathname.rb
+++ b/lib/pathname.rb
@@ -150,6 +150,7 @@ module ::Kernel
# - #read(*args)
# - #binread(*args)
# - #readlines(*args)
+# - #sysopen(*args)
# - #write(*args)
# - #binwrite(*args)
# - #atime
@@ -190,11 +191,6 @@ module ::Kernel
# - #mkdir(*args)
# - #opendir(*args)
#
-# === IO
-#
-# This method is a facade for IO:
-# - #sysopen(*args)
-#
# === Utilities
#
# These methods are a mixture of Find, FileUtils, and others:
@@ -239,9 +235,10 @@ class Pathname
# If +path+ contains a NUL character (\0), an ArgumentError is raised.
#
def initialize(path)
- path = path.to_path if path.respond_to? :to_path
-
- raise TypeError unless path.is_a?(String) # Compatibility for C version
+ unless String === path
+ path = path.to_path if path.respond_to? :to_path
+ raise TypeError unless String === path
+ end
if path.include?("\0")
raise ArgumentError, "pathname contains \\0: #{path.inspect}"
@@ -884,11 +881,6 @@ def relative_path_from(base_directory)
end
end
-class Pathname # * IO *
- # See IO.sysopen.
- def sysopen(...) IO.sysopen(@path, ...) end
-end
-
class Pathname # * File *
#
# #each_line iterates over the line in the file. It yields a String object
@@ -911,6 +903,9 @@ def binread(...) File.binread(@path, ...) end
# See File.readlines. Returns all the lines from the file.
def readlines(...) File.readlines(@path, ...) end
+ # See File.sysopen.
+ def sysopen(...) File.sysopen(@path, ...) end
+
# Writes +contents+ to the file. See File.write.
def write(...) File.write(@path, ...) end
@@ -986,6 +981,13 @@ def truncate(length) File.truncate(@path, length) end
# See File.utime. Update the access and modification times.
def utime(atime, mtime) File.utime(atime, mtime, @path) end
+ # Update the access and modification times of the file.
+ #
+ # Same as Pathname#utime, but does not follow symbolic links.
+ #
+ # See File.lutime.
+ def lutime(atime, mtime) File.lutime(atime, mtime, @path) end
+
# See File.basename. Returns the last component of the path.
def basename(...) self.class.new(File.basename(@path, ...)) end
@@ -1012,6 +1014,13 @@ def split()
#
# All components of the pathname must exist when this method is called.
def realpath(...) self.class.new(File.realpath(@path, ...)) end
+
+ # Returns the real (absolute) pathname of +self+ in the actual filesystem.
+ #
+ # Does not contain symlinks or useless dots, +..+ and +.+.
+ #
+ # The last component of the real pathname can be nonexistent.
+ def realdirpath(...) self.class.new(File.realdirpath(@path, ...)) end
end
@@ -1236,12 +1245,8 @@ module Kernel
#
# This method is available since 1.8.5.
def Pathname(path) # :doc:
- Kernel.Pathname(path)
- end
- private :Pathname
-
- def self.Pathname(path) # Compatibility for C version
return path if Pathname === path
Pathname.new(path)
end
+ module_function :Pathname
end
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index 7e0011c..e80473e 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -348,7 +348,7 @@ def has_symlink?
rescue NotImplementedError
return false
rescue Errno::ENOENT
- return false
+ return true
rescue Errno::EACCES
return false
end
@@ -370,10 +370,11 @@ def has_hardlink?
end
def realpath(path, basedir=nil)
- Pathname.new(path).realpath(basedir).to_s
+ Pathname.new(path).realpath(*basedir).to_s
end
def test_realpath
+ omit "not working yet" if RUBY_ENGINE == "jruby"
return if !has_symlink?
with_tmpchdir('rubytest-pathname') {|dir|
assert_raise(Errno::ENOENT) { realpath("#{dir}/not-exist") }
@@ -434,6 +435,7 @@ def realdirpath(path)
end
def test_realdirpath
+ omit "not working yet" if RUBY_ENGINE == "jruby"
return if !has_symlink?
Dir.mktmpdir('rubytest-pathname') {|dir|
rdir = realpath(dir)
@@ -1054,7 +1056,11 @@ def test_lutime
latime = Time.utc(2000)
lmtime = Time.utc(1999)
File.symlink("a", "l")
- Pathname("l").utime(latime, lmtime)
+ begin
+ Pathname("l").lutime(latime, lmtime)
+ rescue NotImplementedError
+ next
+ end
s = File.lstat("a")
ls = File.lstat("l")
assert_equal(atime, s.atime)