Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 44 additions & 14 deletions Tests/Functional/Asynchronous/Expectations/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class ExpectationsTestCase: XCTestCase {

// CHECK: Test Case 'ExpectationsTestCase.test_multipleExpectations_async' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: Test Case 'ExpectationsTestCase.test_multipleExpectations_async' passed \(\d+\.\d+ seconds\)
@available(macOS 12.0, *)
func test_multipleExpectations_async() async {
let foo = expectation(description: "foo")
let bar = XCTestExpectation(description: "bar")
Expand Down Expand Up @@ -551,6 +552,7 @@ class ExpectationsTestCase: XCTestCase {

// CHECK: Test Case 'ExpectationsTestCase.test_waitForExpectationsAsync' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: Test Case 'ExpectationsTestCase.test_waitForExpectationsAsync' passed \(\d+\.\d+ seconds\)
@available(macOS 12.0, *)
func test_waitForExpectationsAsync() async {
// Basic check that waitForExpectations() is functional when used with the
// await keyword in an async function.
Expand All @@ -561,6 +563,7 @@ class ExpectationsTestCase: XCTestCase {

// CHECK: Test Case 'ExpectationsTestCase.test_waitForExpectationsFromMainActor' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: Test Case 'ExpectationsTestCase.test_waitForExpectationsFromMainActor' passed \(\d+\.\d+ seconds\)
@available(macOS 12.0, *)
func test_waitForExpectationsFromMainActor() async {
await MainActor.run {
// Basic check that waitForExpectations() is functional and does not need
Expand All @@ -571,63 +574,90 @@ class ExpectationsTestCase: XCTestCase {
}
}

static var allTests = {
return [
static var allTests: [(String, (ExpectationsTestCase) -> () throws -> Void)] = {
var tests: [(String, (ExpectationsTestCase) -> () throws -> Void)] = []
tests += [
("test_waitingForAnUnfulfilledExpectation_fails", test_waitingForAnUnfulfilledExpectation_fails),
("test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails", test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails),
("test_waitingForAnImmediatelyFulfilledExpectation_passes", test_waitingForAnImmediatelyFulfilledExpectation_passes),
("test_waitingForAnEventuallyFulfilledExpectation_passes", test_waitingForAnEventuallyFulfilledExpectation_passes),
("test_waitingForAnExpectationFulfilledAfterTheTimeout_fails", test_waitingForAnExpectationFulfilledAfterTheTimeout_fails),
("test_whenTimeoutIsImmediate_andAllExpectationsAreFulfilled_passes", test_whenTimeoutIsImmediate_andAllExpectationsAreFulfilled_passes),
("test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails", test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails),
]

// Multiple Expectations
// Multiple Expectations
tests += [
("test_multipleExpectations", test_multipleExpectations),
("test_multipleExpectations_async", asyncTest(test_multipleExpectations_async)),
]
if #available(macOS 12.0, *) {
tests += [
("test_multipleExpectations_async", asyncTest(test_multipleExpectations_async)),
]
}
tests += [
("test_multipleExpectationsEnforceOrderingCorrect", test_multipleExpectationsEnforceOrderingCorrect),
("test_multipleExpectationsEnforceOrderingCorrectBeforeWait", test_multipleExpectationsEnforceOrderingCorrectBeforeWait),
("test_multipleExpectationsEnforceOrderingIncorrect", test_multipleExpectationsEnforceOrderingIncorrect),
("test_multipleExpectationsIncludingInvertedEnforceOrderingIncorrect", test_multipleExpectationsIncludingInvertedEnforceOrderingIncorrect),
("test_multipleExpectationsEnforceOrderingIncorrectBeforeWait", test_multipleExpectationsEnforceOrderingIncorrectBeforeWait),
("test_multipleExpectationsEnforceOrderingStressTest", test_multipleExpectationsEnforceOrderingStressTest),
]

// Inverse Expectations
// Inverse Expectations
tests += [
("test_inverseExpectationPass", test_inverseExpectationPass),
("test_inverseExpectationFail", test_inverseExpectationFail),
("test_inverseExpectationFulfilledBeforeWait", test_inverseExpectationFulfilledBeforeWait),
("test_combiningInverseAndStandardExpectationsPass", test_combiningInverseAndStandardExpectationsPass),
("test_combiningInverseAndStandardExpectationsFailWithTimeout", test_combiningInverseAndStandardExpectationsFailWithTimeout),
("test_combiningInverseAndStandardExpectationsFailWithInverseFulfillment", test_combiningInverseAndStandardExpectationsFailWithInverseFulfillment),
("test_combiningInverseAndStandardExpectationsWithOrderingEnforcement", test_combiningInverseAndStandardExpectationsWithOrderingEnforcement),
]

// Counted Expectations
// Counted Expectations
tests += [
("test_countedConditionPass", test_countedConditionPass),
("test_countedConditionPassBeforeWaiting", test_countedConditionPassBeforeWaiting),
("test_countedConditionFail", test_countedConditionFail),
]

// assertForOverFulfill
// assertForOverFulfill
tests += [
("test_assertForOverfulfill_disabled", test_assertForOverfulfill_disabled),
("test_assertForOverfulfill_failure", test_assertForOverfulfill_failure),
]

// Interrupted Waiters
// Interrupted Waiters
tests += [
// ("test_outerWaiterTimesOut_InnerWaitersAreInterrupted", test_outerWaiterTimesOut_InnerWaitersAreInterrupted),
("test_outerWaiterCompletes_InnerWaiterTimesOut", test_outerWaiterCompletes_InnerWaiterTimesOut),
]

// Waiter Conveniences
// Waiter Conveniences
tests += [
("test_classWait", test_classWait),
("test_classWaitEnforcingOrder", test_classWaitEnforcingOrder),
("test_classWaitInverseExpectationFail", test_classWaitInverseExpectationFail),
]

// Regressions
// Regressions
tests += [
("test_fulfillmentOnSecondaryThread", test_fulfillmentOnSecondaryThread),
("test_expectationCreationOnSecondaryThread", test_expectationCreationOnSecondaryThread),
("test_expectationCreationWhileWaiting", test_expectationCreationWhileWaiting),
("test_runLoopInsideDispatch", test_runLoopInsideDispatch),

// waitForExpectations() + @MainActor
("test_waitForExpectationsAsync", asyncTest(test_waitForExpectationsAsync)),
("test_waitForExpectationsFromMainActor", asyncTest(test_waitForExpectationsFromMainActor)),
]

// waitForExpectations() + @MainActor
if #available(macOS 12.0, *) {
tests += [
("test_waitForExpectationsAsync", asyncTest(test_waitForExpectationsAsync)),
("test_waitForExpectationsFromMainActor", asyncTest(test_waitForExpectationsFromMainActor)),
]
}

return tests
}()
}
// CHECK: Test Suite 'ExpectationsTestCase' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import XCTest
#endif

let expectation = XCTestExpectation()
Task.detached {
expectation.fulfill()
if #available(macOS 10.15, *) {
let expectation = XCTestExpectation()
Task.detached {
expectation.fulfill()
}
}
6 changes: 5 additions & 1 deletion Tests/Functional/Asynchronous/Use/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ actor TestActor {

// CHECK: Test Suite 'AsyncAwaitTests' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+

@available(macOS 12.0, *)
class AsyncAwaitTests: XCTestCase {

lazy var subject = TestActor()
Expand Down Expand Up @@ -141,6 +142,7 @@ class AsyncAwaitTests: XCTestCase {
}
}

@available(macOS 12.0, *)
private extension AsyncAwaitTests {

func makeString() async -> String {
Expand Down Expand Up @@ -174,7 +176,9 @@ private extension AsyncAwaitTests {
// CHECK: Test Suite '.*\.xctest' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: \t Executed 8 tests, with 4 failures \(3 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds

XCTMain([testCase(AsyncAwaitTests.allTests)])
if #available(macOS 12.0, *) {
XCTMain([testCase(AsyncAwaitTests.allTests)])
}

// CHECK: Test Suite 'All tests' failed at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: \t Executed 8 tests, with 4 failures \(3 unexpected\) in \d+\.\d+ \(\d+\.\d+\) seconds
Expand Down