Skip to content

Commit c0d98e3

Browse files
committed
[android] Enable tests for FileManager in Android.
Many tests were disable in Android, but they actually work without almost changes. - Android uses /proc/mounts as Linux. Enabling that code path gives good results in Android. - `attributesOfFileSystem` works on Android once glibc.modulemap includes the right headers (see swiftlang/swift#24286). - However, since Process is still not available in Android, the test that relies on xdgTestHelper tool will not work, and have been disabled (but instead of causing the test to fail, they are simply not run in Android, which probably will never conform to XDG).
1 parent f10462b commit c0d98e3

File tree

3 files changed

+7
-22
lines changed

3 files changed

+7
-22
lines changed

Foundation/FileManager+POSIX.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension FileManager {
1919
internal func _mountedVolumeURLs(includingResourceValuesForKeys propertyKeys: [URLResourceKey]?, options: VolumeEnumerationOptions = []) -> [URL]? {
2020
var urls: [URL] = []
2121

22-
#if os(Linux)
22+
#if os(Linux) || os(Android)
2323
guard let procMounts = try? String(contentsOfFile: "/proc/mounts", encoding: .utf8) else {
2424
return nil
2525
}

Foundation/FileManager.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,16 +399,9 @@ open class FileManager : NSObject {
399399

400400
This method replaces fileSystemAttributesAtPath:.
401401
*/
402-
#if os(Android)
403-
@available(*, unavailable, message: "Unsuppported on this platform")
404-
open func attributesOfFileSystem(forPath path: String) throws -> [FileAttributeKey : Any] {
405-
NSUnsupported()
406-
}
407-
#else
408402
open func attributesOfFileSystem(forPath path: String) throws -> [FileAttributeKey : Any] {
409403
return try _attributesOfFileSystem(forPath: path)
410404
}
411-
#endif
412405

413406
/* 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.
414407

TestFoundation/TestFileManager.swift

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ class TestFileManager : XCTestCase {
348348
}
349349

350350
func test_fileSystemAttributes() {
351-
#if !os(Android)
352351
let fm = FileManager.default
353352
let path = NSTemporaryDirectory()
354353

@@ -379,7 +378,6 @@ class TestFileManager : XCTestCase {
379378
} catch {
380379
XCTFail("\(error)")
381380
}
382-
#endif
383381
}
384382

385383
func test_setFileAttributes() {
@@ -1084,7 +1082,7 @@ class TestFileManager : XCTestCase {
10841082
try testCopy()
10851083
}
10861084

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

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

12031201
// This test below is a black box test, and does not require @testable import.
1204-
1205-
enum TestError: Error {
1206-
case notImplementedOnThisPlatform
1207-
}
1208-
1202+
1203+
#if !os(Android)
12091204
func printPathByRunningHelper(withConfiguration config: String, method: String, identifier: String) throws -> String {
1210-
#if os(Android)
1211-
throw TestError.notImplementedOnThisPlatform
1212-
#endif
1213-
12141205
let uuid = UUID().uuidString
12151206
let path = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("org.swift.Foundation.XDGTestHelper").appendingPathComponent(uuid)
12161207
try FileManager.default.createDirectory(at: path, withIntermediateDirectories: true)
@@ -1268,6 +1259,7 @@ VIDEOS=StopgapVideos
12681259
assertFetchingPath(withConfiguration: configuration, identifier: "pictures", yields: "\(prefix)/Pictures")
12691260
assertFetchingPath(withConfiguration: configuration, identifier: "videos", yields: "\(prefix)/Videos")
12701261
}
1262+
#endif // !os(Android)
12711263
#endif // !DEPLOYMENT_RUNTIME_OBJC
12721264

12731265
func test_emptyFilename() {
@@ -1565,15 +1557,15 @@ VIDEOS=StopgapVideos
15651557
("test_displayNames", test_displayNames),
15661558
]
15671559

1568-
#if !DEPLOYMENT_RUNTIME_OBJC && NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
1560+
#if !DEPLOYMENT_RUNTIME_OBJC && NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT && !os(Android)
15691561
tests.append(contentsOf: [
15701562
("test_xdgStopgapsCoverAllConstants", test_xdgStopgapsCoverAllConstants),
15711563
("test_parseXDGConfiguration", test_parseXDGConfiguration),
15721564
("test_xdgURLSelection", test_xdgURLSelection),
15731565
])
15741566
#endif
15751567

1576-
#if !DEPLOYMENT_RUNTIME_OBJC
1568+
#if !DEPLOYMENT_RUNTIME_OBJC && !os(Android)
15771569
tests.append(contentsOf: [
15781570
("test_fetchXDGPathsFromHelper", test_fetchXDGPathsFromHelper),
15791571
])

0 commit comments

Comments
 (0)