Skip to content

Commit 2750737

Browse files
authored
Merge pull request #2144 from drodriguez/android-fix-tilde-test
[android] Fix tilde/home directory tests.
2 parents 9678f2d + 6841f4b commit 2750737

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

TestFoundation/TestNSString.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,25 +1002,30 @@ class TestNSString: LoopbackServerTest {
10021002
}
10031003

10041004
func test_expandingTildeInPath() {
1005+
// Android home directory is the root directory, so the result of ~ may
1006+
// actually have a trailing path separator, but only if it is the root
1007+
// directory itself.
1008+
let rootDirectory = "/"
1009+
10051010
do {
10061011
let path: NSString = "~"
10071012
let result = path.expandingTildeInPath
10081013
XCTAssert(result == NSHomeDirectory(), "Could resolve home directory for current user")
1009-
XCTAssertFalse(result.hasSuffix("/"), "Result have no trailing path separator")
1014+
XCTAssertFalse(result.hasSuffix("/") && result != rootDirectory, "Result should not have a trailing path separator")
10101015
}
10111016

10121017
do {
10131018
let path: NSString = "~/"
10141019
let result = path.expandingTildeInPath
10151020
XCTAssert(result == NSHomeDirectory(), "Could resolve home directory for current user")
1016-
XCTAssertFalse(result.hasSuffix("/"), "Result have no trailing path separator")
1021+
XCTAssertFalse(result.hasSuffix("/") && result != rootDirectory, "Result should not have a trailing path separator")
10171022
}
10181023

10191024
do {
10201025
let path = NSString(string: "~\(NSUserName())")
10211026
let result = path.expandingTildeInPath
10221027
XCTAssert(result == NSHomeDirectory(), "Could resolve home directory for specific user")
1023-
XCTAssertFalse(result.hasSuffix("/"), "Result have no trailing path separator")
1028+
XCTAssertFalse(result.hasSuffix("/") && result != rootDirectory, "Result should not have a trailing path separator")
10241029
}
10251030

10261031
do {
@@ -1052,7 +1057,7 @@ class TestNSString: LoopbackServerTest {
10521057
do {
10531058
let path: NSString = "~/foo/bar/"
10541059
let result = path.standardizingPath
1055-
let expected = NSHomeDirectory() + "/foo/bar"
1060+
let expected = NSHomeDirectory().appendingPathComponent("foo/bar")
10561061
XCTAssertEqual(result, expected, "standardizingPath expanding initial tilde.")
10571062
}
10581063

0 commit comments

Comments
 (0)