Skip to content

Commit ce0d5cc

Browse files
committed
Refine dirname test on Windows
- Compare with the root of the target file - Fix root path of UNC path
1 parent 5cf7d94 commit ce0d5cc

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

test/ruby/test_file_exhaustive.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
require '-test-/file'
77

88
class TestFileExhaustive < Test::Unit::TestCase
9-
DRIVE = Dir.pwd[%r'\A(?:[a-z]:|//[^/]+/[^/]+)'i]
9+
ROOT_REGEXP = %r'\A(?:[a-z]:(?=(/))|//[^/]+/[^/]+)'i
10+
DRIVE = Dir.pwd[ROOT_REGEXP]
1011
POSIX = /cygwin|mswin|bccwin|mingw|emx/ !~ RUBY_PLATFORM
1112
NTFS = !(/mingw|mswin|bccwin/ !~ RUBY_PLATFORM)
1213

@@ -1279,8 +1280,9 @@ def test_dirname
12791280
assert_equal(@dir, File.dirname(regular_file, 1))
12801281
assert_equal(File.dirname(@dir), File.dirname(regular_file, 2))
12811282
assert_raise(ArgumentError) {File.dirname(regular_file, -1)}
1282-
# mswin allows rootdir and tmpdir are in different drives
1283-
assert_equal(rootdir, File.dirname(regular_file, regular_file.count('/'))) unless /mswin/ =~ RUBY_PLATFORM
1283+
root = "#{@dir[ROOT_REGEXP]||?/}#{$1}"
1284+
assert_equal(root, File.dirname(regular_file, regular_file.count('/')))
1285+
assert_equal(root, File.dirname(regular_file, regular_file.count('/') + 100))
12841286
end
12851287

12861288
def test_dirname_encoding

0 commit comments

Comments
 (0)