Skip to content

[file_selector] Switch to Swift Testing#12235

Open
stuartmorgan-g wants to merge 2 commits into
flutter:mainfrom
stuartmorgan-g:file-selector-swift-testing
Open

[file_selector] Switch to Swift Testing#12235
stuartmorgan-g wants to merge 2 commits into
flutter:mainfrom
stuartmorgan-g:file-selector-swift-testing

Conversation

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

Updates the iOS and macOS Swift unit tests to use Swift Testing rather than XCTest.

Part of flutter/flutter#180787

Pre-Review Checklist

Footnotes

  1. 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

Updates the iOS and macOS Swift unit tests to use Swift Testing rather
than XCTest.

Part of flutter/flutter#180787

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@okorohelijah okorohelijah Jul 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#expect(paths.count == 0)
#expect(paths.isEmpty)

@okorohelijah okorohelijah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants