Skip to content

Convert String/Predicate/ProcessInfo/RecurrenceRule tests to swift-testing #1357

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

Conversation

jmschonfeld
Copy link
Contributor

Applies more patches from #908 to bring a handful more FoundationEssentials test suites to swift-testing (adjusting the patches to account for newly added and modified tests)

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

@jmschonfeld
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@hristost hristost left a comment

Choose a reason for hiding this comment

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

The recurrence rule tests look alright, modulo one comment about Calendar.current

// These are not necessarily valid recurrence rule, they are constructed
// in a way to test all encoding paths
var recurrenceRule1 = Calendar.RecurrenceRule(calendar: .current, frequency: .daily)
Copy link
Contributor

Choose a reason for hiding this comment

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

If I recall correctly, this was meant to test that the current calendar is encoded as such. We don't have any custom logic in RecurrenceRule encoding to handle such cases so it's also okay to encode with other calendars. But it'd be nice to minimize the diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the usage of .current here is important because the .current calendar also implies things like the current TimeZone. Unlike XCTest tests, swift-testing tests run in parallel with each other, including other tests which may change the value of the current calendar/timezone/locale. Tests that use or change the current calendar/timezone/locale need to be serialized to ensure they don't run in parallel like I did with the tests relying on the CWD. I can go ahead and setup the infrastructure for that now (I planned to do that later when refactoring the FoundationInternationalization tests) but if there's no custom logic for the current calendar, to avoid that need for these tests it's likely simpler to just switch to a non-current calendar than switch to an asynchronous task run on an actor.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see! It's good with me then. We can also use GregorianCalendarRecurrenceRuleTests.gregorian, which is initialized only once.

@@ -681,12 +689,12 @@ final class GregorianCalendarRecurrenceRuleTests: XCTestCase {
rule.matchingPolicy = .strict

for _ in rule.recurrences(of: start) {
XCTFail("Recurrence rule is not expected to produce results")
Issue.record("Recurrence rule is not expected to produce results")
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this automatically mark the test as failing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, XCTFail and Issue.record are equivalent - both record an issue that will cause the test to be marked as failed and continue execution to the end of the test to allow for recording additional issues

@jmschonfeld jmschonfeld merged commit 8180dd1 into swiftlang:main Jun 17, 2025
15 checks passed
@jmschonfeld jmschonfeld deleted the swift-testing-predicate-pi-str-recur branch June 17, 2025 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants