Skip to content

[android] Fix tilde/home directory tests. #2144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions TestFoundation/TestNSString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1014,25 +1014,30 @@ class TestNSString: LoopbackServerTest {
}

func test_expandingTildeInPath() {
// Android home directory is the root directory, so the result of ~ may
// actually have a trailing path separator, but only if it is the root
// directory itself.
let rootDirectory = "/"

do {
let path: NSString = "~"
let result = path.expandingTildeInPath
XCTAssert(result == NSHomeDirectory(), "Could resolve home directory for current user")
XCTAssertFalse(result.hasSuffix("/"), "Result have no trailing path separator")
XCTAssertFalse(result.hasSuffix("/") && result != rootDirectory, "Result should not have a trailing path separator")
}

do {
let path: NSString = "~/"
let result = path.expandingTildeInPath
XCTAssert(result == NSHomeDirectory(), "Could resolve home directory for current user")
XCTAssertFalse(result.hasSuffix("/"), "Result have no trailing path separator")
XCTAssertFalse(result.hasSuffix("/") && result != rootDirectory, "Result should not have a trailing path separator")
}

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

do {
Expand Down Expand Up @@ -1064,7 +1069,7 @@ class TestNSString: LoopbackServerTest {
do {
let path: NSString = "~/foo/bar/"
let result = path.standardizingPath
let expected = NSHomeDirectory() + "/foo/bar"
let expected = NSHomeDirectory().appendingPathComponent("foo/bar")
XCTAssertEqual(result, expected, "standardizingPath expanding initial tilde.")
}

Expand Down