Skip to content

Commit b0bb1ec

Browse files
authored
Merge pull request #60 from eregon/run-and-fix-specs
Run pathname specs from ruby/spec in CI and fix them
2 parents 90ad687 + ef196cc commit b0bb1ec

File tree

4 files changed

+49
-40
lines changed

4 files changed

+49
-40
lines changed

.github/workflows/test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,20 @@ jobs:
4040
run: bundle install
4141
- name: Run test
4242
run: rake compile test
43+
44+
spec:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- uses: actions/checkout@v5
48+
- uses: ruby/setup-ruby@v1
49+
with:
50+
ruby-version: ruby
51+
- uses: actions/checkout@v5
52+
with:
53+
repository: ruby/spec
54+
path: rubyspec
55+
- name: Clone MSpec
56+
run: git clone https://github.com/ruby/mspec.git ../mspec
57+
- run: bundle install
58+
- run: rake compile
59+
- run: ../mspec/bin/mspec -Ilib rubyspec/library/pathname

ext/pathname/pathname.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
static VALUE rb_cPathname;
44
static ID id_at_path;
55
static ID id_sub;
6-
static ID id_realdirpath;
76

87
static VALUE
98
get_strpath(VALUE obj)
@@ -84,22 +83,6 @@ path_sub(int argc, VALUE *argv, VALUE self)
8483
return rb_class_new_instance(1, &str, rb_obj_class(self));
8584
}
8685

87-
/*
88-
* Returns the real (absolute) pathname of +self+ in the actual filesystem.
89-
*
90-
* Does not contain symlinks or useless dots, +..+ and +.+.
91-
*
92-
* The last component of the real pathname can be nonexistent.
93-
*/
94-
static VALUE
95-
path_realdirpath(int argc, VALUE *argv, VALUE self)
96-
{
97-
VALUE basedir, str;
98-
rb_scan_args(argc, argv, "01", &basedir);
99-
str = rb_funcall(rb_cFile, id_realdirpath, 2, get_strpath(self), basedir);
100-
return rb_class_new_instance(1, &str, rb_obj_class(self));
101-
}
102-
10386
static void init_ids(void);
10487

10588
void
@@ -119,7 +102,6 @@ InitVM_pathname(void)
119102
rb_cPathname = rb_define_class("Pathname", rb_cObject);
120103
rb_define_method(rb_cPathname, "<=>", path_cmp, 1);
121104
rb_define_method(rb_cPathname, "sub", path_sub, -1);
122-
rb_define_method(rb_cPathname, "realdirpath", path_realdirpath, -1);
123105
}
124106

125107
void
@@ -128,5 +110,4 @@ init_ids(void)
128110
#undef rb_intern
129111
id_at_path = rb_intern("@path");
130112
id_sub = rb_intern("sub");
131-
id_realdirpath = rb_intern("realdirpath");
132113
}

lib/pathname.rb

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ module ::Kernel
150150
# - #read(*args)
151151
# - #binread(*args)
152152
# - #readlines(*args)
153+
# - #sysopen(*args)
153154
# - #write(*args)
154155
# - #binwrite(*args)
155156
# - #atime
@@ -190,11 +191,6 @@ module ::Kernel
190191
# - #mkdir(*args)
191192
# - #opendir(*args)
192193
#
193-
# === IO
194-
#
195-
# This method is a facade for IO:
196-
# - #sysopen(*args)
197-
#
198194
# === Utilities
199195
#
200196
# These methods are a mixture of Find, FileUtils, and others:
@@ -239,9 +235,10 @@ class Pathname
239235
# If +path+ contains a NUL character (<tt>\0</tt>), an ArgumentError is raised.
240236
#
241237
def initialize(path)
242-
path = path.to_path if path.respond_to? :to_path
243-
244-
raise TypeError unless path.is_a?(String) # Compatibility for C version
238+
unless String === path
239+
path = path.to_path if path.respond_to? :to_path
240+
raise TypeError unless String === path
241+
end
245242

246243
if path.include?("\0")
247244
raise ArgumentError, "pathname contains \\0: #{path.inspect}"
@@ -884,11 +881,6 @@ def relative_path_from(base_directory)
884881
end
885882
end
886883

887-
class Pathname # * IO *
888-
# See <tt>IO.sysopen</tt>.
889-
def sysopen(...) IO.sysopen(@path, ...) end
890-
end
891-
892884
class Pathname # * File *
893885
#
894886
# #each_line iterates over the line in the file. It yields a String object
@@ -911,6 +903,9 @@ def binread(...) File.binread(@path, ...) end
911903
# See <tt>File.readlines</tt>. Returns all the lines from the file.
912904
def readlines(...) File.readlines(@path, ...) end
913905

906+
# See <tt>File.sysopen</tt>.
907+
def sysopen(...) File.sysopen(@path, ...) end
908+
914909
# Writes +contents+ to the file. See <tt>File.write</tt>.
915910
def write(...) File.write(@path, ...) end
916911

@@ -986,6 +981,13 @@ def truncate(length) File.truncate(@path, length) end
986981
# See <tt>File.utime</tt>. Update the access and modification times.
987982
def utime(atime, mtime) File.utime(atime, mtime, @path) end
988983

984+
# Update the access and modification times of the file.
985+
#
986+
# Same as Pathname#utime, but does not follow symbolic links.
987+
#
988+
# See File.lutime.
989+
def lutime(atime, mtime) File.lutime(atime, mtime, @path) end
990+
989991
# See <tt>File.basename</tt>. Returns the last component of the path.
990992
def basename(...) self.class.new(File.basename(@path, ...)) end
991993

@@ -1012,6 +1014,13 @@ def split()
10121014
#
10131015
# All components of the pathname must exist when this method is called.
10141016
def realpath(...) self.class.new(File.realpath(@path, ...)) end
1017+
1018+
# Returns the real (absolute) pathname of +self+ in the actual filesystem.
1019+
#
1020+
# Does not contain symlinks or useless dots, +..+ and +.+.
1021+
#
1022+
# The last component of the real pathname can be nonexistent.
1023+
def realdirpath(...) self.class.new(File.realdirpath(@path, ...)) end
10151024
end
10161025

10171026

@@ -1236,12 +1245,8 @@ module Kernel
12361245
#
12371246
# This method is available since 1.8.5.
12381247
def Pathname(path) # :doc:
1239-
Kernel.Pathname(path)
1240-
end
1241-
private :Pathname
1242-
1243-
def self.Pathname(path) # Compatibility for C version
12441248
return path if Pathname === path
12451249
Pathname.new(path)
12461250
end
1251+
module_function :Pathname
12471252
end

test/pathname/test_pathname.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def has_symlink?
348348
rescue NotImplementedError
349349
return false
350350
rescue Errno::ENOENT
351-
return false
351+
return true
352352
rescue Errno::EACCES
353353
return false
354354
end
@@ -370,10 +370,11 @@ def has_hardlink?
370370
end
371371

372372
def realpath(path, basedir=nil)
373-
Pathname.new(path).realpath(basedir).to_s
373+
Pathname.new(path).realpath(*basedir).to_s
374374
end
375375

376376
def test_realpath
377+
omit "not working yet" if RUBY_ENGINE == "jruby"
377378
return if !has_symlink?
378379
with_tmpchdir('rubytest-pathname') {|dir|
379380
assert_raise(Errno::ENOENT) { realpath("#{dir}/not-exist") }
@@ -434,6 +435,7 @@ def realdirpath(path)
434435
end
435436

436437
def test_realdirpath
438+
omit "not working yet" if RUBY_ENGINE == "jruby"
437439
return if !has_symlink?
438440
Dir.mktmpdir('rubytest-pathname') {|dir|
439441
rdir = realpath(dir)
@@ -1054,7 +1056,11 @@ def test_lutime
10541056
latime = Time.utc(2000)
10551057
lmtime = Time.utc(1999)
10561058
File.symlink("a", "l")
1057-
Pathname("l").utime(latime, lmtime)
1059+
begin
1060+
Pathname("l").lutime(latime, lmtime)
1061+
rescue NotImplementedError
1062+
next
1063+
end
10581064
s = File.lstat("a")
10591065
ls = File.lstat("l")
10601066
assert_equal(atime, s.atime)

0 commit comments

Comments
 (0)