-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[local_auth] Convert native unit tests to Swift #6779
[local_auth] Convert native unit tests to Swift #6779
Conversation
Converts native unit tests from Objective-C to Swift, as a first step toward an eventual plugin conversion. Since OCMock usage was removed in a previous PR, the tests are converted essentially directly (the rewrites were largely mechanical syntax replacement), without any changes needed to production code. Part of flutter/flutter#119104
That |
@testable import local_auth_darwin | ||
|
||
// Set a long timeout to avoid flake due to slow CI. | ||
let timeout: TimeInterval = 30.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can be fileprivate
(unless you want to make this timeout
available in the whole test module)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
XCTAssert(self.contexts.count > 0, "Insufficient test contexts provided") | ||
let context = self.contexts.first! | ||
contexts.remove(at: 0) | ||
return context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
return self.contexts.removeFirst()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I didn't realize Swift arrays had fixed some of the annoying API limitations of NSArray
(like not having a remove-and-return method).
var evaluateError: NSError? | ||
|
||
// Overridden as read-write to allow stubbing. | ||
var biometryType: LABiometryType = LABiometryType.none |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: type can be inferred
var biometryType: LABiometryType = .none
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed throughout.
class FLALocalAuthPluginTests: XCTestCase { | ||
|
||
override func setUp() { | ||
continueAfterFailure = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious why? (also maybe add comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No clue, it looks like it dates back to my adding the original test file. Copypasta from an XCUITest maybe? Removed.
let timeout: TimeInterval = 30.0 | ||
|
||
/// A context factory that returns preset contexts. | ||
class StubAuthContextFactory: NSObject, FLADAuthContextFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can be final class
(unless we intend to subclass it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
auto label is removed for flutter/packages/6779, due to - The status or check suite Linux repo_checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
Changelog override: only affects tests. |
flutter/packages@ba19b24...6525441 2024-05-22 stuartmorgan@google.com [local_auth] Convert native unit tests to Swift (flutter/packages#6779) 2024-05-22 49699333+dependabot[bot]@users.noreply.github.com [interactive_media_ads]: Bump androidx.annotation:annotation from 1.5.0 to 1.8.0 in /packages/interactive_media_ads/android (flutter/packages#6771) 2024-05-22 vongrejadam@gmail.com [in_app_purchase_android] Introduced new ReplacementMode for Android's billing client (flutter/packages#6515) 2024-05-21 hashirshoaeb@gmail.com [go_router] New feature improve debug full path (flutter/packages#6714) 2024-05-21 stuartmorgan@google.com [interactive_media_ads] Add SPM support (flutter/packages#6756) 2024-05-21 engine-flutter-autoroll@skia.org Roll Flutter from 02a6c91 to d02292d (22 revisions) (flutter/packages#6778) 2024-05-21 stuartmorgan@google.com [local_auth] Remove use of OCMock (flutter/packages#6757) 2024-05-21 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.25.3 to 3.25.6 (flutter/packages#6777) 2024-05-20 49699333+dependabot[bot]@users.noreply.github.com [file_selector]: Bump androidx.annotation:annotation from 1.7.1 to 1.8.0 in /packages/file_selector/file_selector_android/android (flutter/packages#6769) 2024-05-20 49699333+dependabot[bot]@users.noreply.github.com [in_app_pur]: Bump androidx.annotation:annotation from 1.7.1 to 1.8.0 in /packages/in_app_purchase/in_app_purchase_android/android (flutter/packages#6765) 2024-05-20 49699333+dependabot[bot]@users.noreply.github.com [url_launcher]: Bump androidx.annotation:annotation from 1.7.1 to 1.8.0 in /packages/url_launcher/url_launcher_android/android (flutter/packages#6762) 2024-05-20 engine-flutter-autoroll@skia.org Roll Flutter from adf279f to 02a6c91 (8 revisions) (flutter/packages#6776) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@ba19b24...6525441 2024-05-22 stuartmorgan@google.com [local_auth] Convert native unit tests to Swift (flutter/packages#6779) 2024-05-22 49699333+dependabot[bot]@users.noreply.github.com [interactive_media_ads]: Bump androidx.annotation:annotation from 1.5.0 to 1.8.0 in /packages/interactive_media_ads/android (flutter/packages#6771) 2024-05-22 vongrejadam@gmail.com [in_app_purchase_android] Introduced new ReplacementMode for Android's billing client (flutter/packages#6515) 2024-05-21 hashirshoaeb@gmail.com [go_router] New feature improve debug full path (flutter/packages#6714) 2024-05-21 stuartmorgan@google.com [interactive_media_ads] Add SPM support (flutter/packages#6756) 2024-05-21 engine-flutter-autoroll@skia.org Roll Flutter from 02a6c91 to d02292d (22 revisions) (flutter/packages#6778) 2024-05-21 stuartmorgan@google.com [local_auth] Remove use of OCMock (flutter/packages#6757) 2024-05-21 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.25.3 to 3.25.6 (flutter/packages#6777) 2024-05-20 49699333+dependabot[bot]@users.noreply.github.com [file_selector]: Bump androidx.annotation:annotation from 1.7.1 to 1.8.0 in /packages/file_selector/file_selector_android/android (flutter/packages#6769) 2024-05-20 49699333+dependabot[bot]@users.noreply.github.com [in_app_pur]: Bump androidx.annotation:annotation from 1.7.1 to 1.8.0 in /packages/in_app_purchase/in_app_purchase_android/android (flutter/packages#6765) 2024-05-20 49699333+dependabot[bot]@users.noreply.github.com [url_launcher]: Bump androidx.annotation:annotation from 1.7.1 to 1.8.0 in /packages/url_launcher/url_launcher_android/android (flutter/packages#6762) 2024-05-20 engine-flutter-autoroll@skia.org Roll Flutter from adf279f to 02a6c91 (8 revisions) (flutter/packages#6776) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Converts native unit tests from Objective-C to Swift, as a first step toward an eventual plugin conversion. Since OCMock usage was removed in a previous PR, the tests are converted essentially directly (the rewrites were largely mechanical syntax replacement), without any changes needed to production code. There are a few places where interacting with the Pigeon-generated Obj-C is somewhat awkward because the NSError signature isn't auto-converting to `throw` in cases where we use `NSNumber` wrapping, but all that will get cleaned up when we switch the plugin over to Swift Pigeon generation and have idiomatic Swift APIs that the tests will be calling instead. Fixes a couple of false positives in the repo tooling surfaced by this PR: - `darwin/Tests/` wasn't recognized as a test directory. - Swift tests weren't recognized as exempt from requiring Swift entries in the podspec. Part of flutter/flutter#119104
Converts native unit tests from Objective-C to Swift, as a first step toward an eventual plugin conversion. Since OCMock usage was removed in a previous PR, the tests are converted essentially directly (the rewrites were largely mechanical syntax replacement), without any changes needed to production code.
There are a few places where interacting with the Pigeon-generated Obj-C is somewhat awkward because the NSError signature isn't auto-converting to
throw
in cases where we useNSNumber
wrapping, but all that will get cleaned up when we switch the plugin over to Swift Pigeon generation and have idiomatic Swift APIs that the tests will be calling instead.Fixes a couple of false positives in the repo tooling surfaced by this PR:
darwin/Tests/
wasn't recognized as a test directory.Part of flutter/flutter#119104
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).