[file_selector] Switch to Swift Testing#12235
Conversation
Updates the iOS and macOS Swift unit tests to use Swift Testing rather than XCTest. Part of flutter/flutter#180787
There was a problem hiding this comment.
Code Review
This pull request migrates the iOS and macOS example runner tests for the file selector plugins from XCTest to the Swift Testing framework, replacing test classes, assertions, and expectations with @Suite, @Test, #expect, and confirmation. The review feedback recommends utilizing try #require(...) to safely unwrap optionals instead of force-unwrapping or using conditional binding, and simplifying array assertions to avoid potential out-of-bounds errors.
| let panel = try #require(panelController.openPanel) | ||
| if #available(macOS 11.0, *) { | ||
| #expect(panel.allowedContentTypes.count == 1) | ||
| #expect(panel.allowedContentTypes[0].preferredFilenameExtension == unknownExtension) |
There was a problem hiding this comment.
If allowedContentTypes is empty, the first #expect will fail and log an issue, but the test will keep running. The very next line will attempt to access index [0], causing an out-of-bounds fatal error that crashes the entire test process.
can we try #require to safely unwrap the first element.
| plugin.displayOpenPanel(options: options) { result in | ||
| switch result { | ||
| case .success(let paths): | ||
| #expect(paths.count == 0) |
There was a problem hiding this comment.
| #expect(paths.count == 0) | |
| #expect(paths.isEmpty) |
Updates the iOS and macOS Swift unit tests to use Swift Testing rather than XCTest.
Part of flutter/flutter#180787
Pre-Review Checklist
[shared_preferences]///).Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2