Skip to content

[android] Enable tests for FileManager in Android. #2176

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
May 1, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Foundation/FileManager+POSIX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension FileManager {
internal func _mountedVolumeURLs(includingResourceValuesForKeys propertyKeys: [URLResourceKey]?, options: VolumeEnumerationOptions = []) -> [URL]? {
var urls: [URL] = []

#if os(Linux)
#if os(Linux) || os(Android)
guard let procMounts = try? String(contentsOfFile: "/proc/mounts", encoding: .utf8) else {
return nil
}
Expand Down
7 changes: 0 additions & 7 deletions Foundation/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -399,16 +399,9 @@ open class FileManager : NSObject {

This method replaces fileSystemAttributesAtPath:.
*/
#if os(Android)
@available(*, unavailable, message: "Unsuppported on this platform")
open func attributesOfFileSystem(forPath path: String) throws -> [FileAttributeKey : Any] {
NSUnsupported()
}
#else
open func attributesOfFileSystem(forPath path: String) throws -> [FileAttributeKey : Any] {
return try _attributesOfFileSystem(forPath: path)
}
#endif

/* createSymbolicLinkAtPath:withDestination:error: returns YES if the symbolic link that point at 'destPath' was able to be created at the location specified by 'path'. If this method returns NO, the link was unable to be created and an NSError will be returned by reference in the 'error' parameter. This method does not traverse a terminal symlink.

Expand Down
20 changes: 6 additions & 14 deletions TestFoundation/TestFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ class TestFileManager : XCTestCase {
}

func test_fileSystemAttributes() {
#if !os(Android)
let fm = FileManager.default
let path = NSTemporaryDirectory()

Expand Down Expand Up @@ -379,7 +378,6 @@ class TestFileManager : XCTestCase {
} catch {
XCTFail("\(error)")
}
#endif
}

func test_setFileAttributes() {
Expand Down Expand Up @@ -1084,7 +1082,7 @@ class TestFileManager : XCTestCase {
try testCopy()
}

#if !DEPLOYMENT_RUNTIME_OBJC // XDG tests require swift-corelibs-foundation
#if !DEPLOYMENT_RUNTIME_OBJC && !os(Android) // XDG tests require swift-corelibs-foundation

#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT // These are white box tests for the internals of XDG parsing:
func test_xdgStopgapsCoverAllConstants() {
Expand Down Expand Up @@ -1201,16 +1199,9 @@ VIDEOS=StopgapVideos
#endif // NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT

// This test below is a black box test, and does not require @testable import.

enum TestError: Error {
case notImplementedOnThisPlatform
}


#if !os(Android)
func printPathByRunningHelper(withConfiguration config: String, method: String, identifier: String) throws -> String {
#if os(Android)
throw TestError.notImplementedOnThisPlatform
#endif

let uuid = UUID().uuidString
let path = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("org.swift.Foundation.XDGTestHelper").appendingPathComponent(uuid)
try FileManager.default.createDirectory(at: path, withIntermediateDirectories: true)
Expand Down Expand Up @@ -1268,6 +1259,7 @@ VIDEOS=StopgapVideos
assertFetchingPath(withConfiguration: configuration, identifier: "pictures", yields: "\(prefix)/Pictures")
assertFetchingPath(withConfiguration: configuration, identifier: "videos", yields: "\(prefix)/Videos")
}
#endif // !os(Android)
#endif // !DEPLOYMENT_RUNTIME_OBJC

func test_emptyFilename() {
Expand Down Expand Up @@ -1565,15 +1557,15 @@ VIDEOS=StopgapVideos
("test_displayNames", test_displayNames),
]

#if !DEPLOYMENT_RUNTIME_OBJC && NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
#if !DEPLOYMENT_RUNTIME_OBJC && NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT && !os(Android)
tests.append(contentsOf: [
("test_xdgStopgapsCoverAllConstants", test_xdgStopgapsCoverAllConstants),
("test_parseXDGConfiguration", test_parseXDGConfiguration),
("test_xdgURLSelection", test_xdgURLSelection),
])
#endif

#if !DEPLOYMENT_RUNTIME_OBJC
#if !DEPLOYMENT_RUNTIME_OBJC && !os(Android)
tests.append(contentsOf: [
("test_fetchXDGPathsFromHelper", test_fetchXDGPathsFromHelper),
])
Expand Down