Skip to content

Commit dc94501

Browse files
committed
[Tests] Automatically substitute [[@line]] numbers
1. Enhance xctest_checker such that it substitutes the string "[[@line]]" and "[[@line+<offset>]]" with the current line number of the source file when performing checks. 2. Replace all hardcoded and regex line numbers in the functional test suite with the new substitution. This allows us to add and remove arbitary lines in the functional test suite without manually updating line numbers in most cases. Line offsets will still need to be updated when the distance between the CHECK and the test failure changes.
1 parent 5b9b6ad commit dc94501

File tree

11 files changed

+80
-41
lines changed

11 files changed

+80
-41
lines changed

Tests/Functional/Asynchronous/Expectations/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212

1313
class ExpectationsTestCase: XCTestCase {
1414
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnUnfulfilledExpectation_fails' started.
15-
// CHECK: .*/Asynchronous/Expectations/main.swift:19: error: ExpectationsTestCase.test_waitingForAnUnfulfilledExpectation_fails : Asynchronous wait failed - Exceeded timeout of 0.2 seconds, with unfulfilled expectations: foo
15+
// CHECK: .*/Asynchronous/Expectations/main.swift:[[@LINE+4]]: error: ExpectationsTestCase.test_waitingForAnUnfulfilledExpectation_fails : Asynchronous wait failed - Exceeded timeout of 0.2 seconds, with unfulfilled expectations: foo
1616
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnUnfulfilledExpectation_fails' failed \(\d+\.\d+ seconds\).
1717
func test_waitingForAnUnfulfilledExpectation_fails() {
1818
expectationWithDescription("foo")
1919
waitForExpectationsWithTimeout(0.2, handler: nil)
2020
}
2121

2222
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails' started.
23-
// CHECK: .*/Asynchronous/Expectations/main.swift:28: error: ExpectationsTestCase.test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails : Asynchronous wait failed - Exceeded timeout of 0.2 seconds, with unfulfilled expectations: bar, baz
23+
// CHECK: .*/Asynchronous/Expectations/main.swift:[[@LINE+5]]: error: ExpectationsTestCase.test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails : Asynchronous wait failed - Exceeded timeout of 0.2 seconds, with unfulfilled expectations: bar, baz
2424
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails' failed \(\d+\.\d+ seconds\).
2525
func test_waitingForUnfulfilledExpectations_outputsAllExpectations_andFails() {
2626
expectationWithDescription("bar")
@@ -48,7 +48,7 @@ class ExpectationsTestCase: XCTestCase {
4848
}
4949

5050
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnExpectationFulfilledAfterTheTimeout_fails' started.
51-
// CHECK: .*/Asynchronous/Expectations/main.swift:59: error: ExpectationsTestCase.test_waitingForAnExpectationFulfilledAfterTheTimeout_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: hog
51+
// CHECK: .*/Asynchronous/Expectations/main.swift:[[@LINE+8]]: error: ExpectationsTestCase.test_waitingForAnExpectationFulfilledAfterTheTimeout_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: hog
5252
// CHECK: Test Case 'ExpectationsTestCase.test_waitingForAnExpectationFulfilledAfterTheTimeout_fails' failed \(\d+\.\d+ seconds\).
5353
func test_waitingForAnExpectationFulfilledAfterTheTimeout_fails() {
5454
let expectation = expectationWithDescription("hog")
@@ -68,7 +68,7 @@ class ExpectationsTestCase: XCTestCase {
6868
}
6969

7070
// CHECK: Test Case 'ExpectationsTestCase.test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails' started.
71-
// CHECK: .*/Asynchronous/Expectations/main.swift:75: error: ExpectationsTestCase.test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails : Asynchronous wait failed - Exceeded timeout of -1.0 seconds, with unfulfilled expectations: dog
71+
// CHECK: .*/Asynchronous/Expectations/main.swift:[[@LINE+4]]: error: ExpectationsTestCase.test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails : Asynchronous wait failed - Exceeded timeout of -1.0 seconds, with unfulfilled expectations: dog
7272
// CHECK: Test Case 'ExpectationsTestCase.test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails' failed \(\d+\.\d+ seconds\).
7373
func test_whenTimeoutIsImmediate_butNotAllExpectationsAreFulfilled_fails() {
7474
expectationWithDescription("dog")

Tests/Functional/Asynchronous/Handler/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class HandlerTestCase: XCTestCase {
1414
// CHECK: Test Case 'HandlerTestCase.test_whenExpectationsAreNotFulfilled_handlerCalled_andFails' started.
15-
// CHECK: .*/Asynchronous/Handler/main.swift:21: error: HandlerTestCase.test_whenExpectationsAreNotFulfilled_handlerCalled_andFails : Asynchronous wait failed - Exceeded timeout of 0.2 seconds, with unfulfilled expectations: fog
15+
// CHECK: .*/Asynchronous/Handler/main.swift:[[@LINE+6]]: error: HandlerTestCase.test_whenExpectationsAreNotFulfilled_handlerCalled_andFails : Asynchronous wait failed - Exceeded timeout of 0.2 seconds, with unfulfilled expectations: fog
1616
// CHECK: Test Case 'HandlerTestCase.test_whenExpectationsAreNotFulfilled_handlerCalled_andFails' failed \(\d+\.\d+ seconds\).
1717
func test_whenExpectationsAreNotFulfilled_handlerCalled_andFails() {
1818
self.expectationWithDescription("fog")

Tests/Functional/Asynchronous/Misuse/main.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010

1111
class MisuseTestCase: XCTestCase {
1212
// CHECK: Test Case 'MisuseTestCase.test_whenExpectationsAreMade_butNotWaitedFor_fails' started.
13-
// CHECK: .*/Asynchronous/Misuse/main.swift:17: unexpected error: MisuseTestCase.test_whenExpectationsAreMade_butNotWaitedFor_fails : - Failed due to unwaited expectations.
13+
// CHECK: .*/Asynchronous/Misuse/main.swift:[[@LINE+4]]: unexpected error: MisuseTestCase.test_whenExpectationsAreMade_butNotWaitedFor_fails : - Failed due to unwaited expectations.
1414
// CHECK: Test Case 'MisuseTestCase.test_whenExpectationsAreMade_butNotWaitedFor_fails' failed \(\d+\.\d+ seconds\).
1515
func test_whenExpectationsAreMade_butNotWaitedFor_fails() {
1616
self.expectationWithDescription("the first expectation")
1717
self.expectationWithDescription("the second expectation (the file and line number for this one are included in the failure message")
1818
}
1919

2020
// CHECK: Test Case 'MisuseTestCase.test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails' started.
21-
// CHECK: .*/Asynchronous/Misuse/main.swift:24: unexpected error: MisuseTestCase.test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails : API violation - call made to wait without any expectations having been set.
21+
// CHECK: .*/Asynchronous/Misuse/main.swift:[[@LINE+3]]: unexpected error: MisuseTestCase.test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails : API violation - call made to wait without any expectations having been set.
2222
// CHECK: Test Case 'MisuseTestCase.test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails' failed \(\d+\.\d+ seconds\).
2323
func test_whenNoExpectationsAreMade_butTheyAreWaitedFor_fails() {
2424
self.waitForExpectationsWithTimeout(0.1, handler: nil)
2525
}
2626

2727
// CHECK: Test Case 'MisuseTestCase.test_whenExpectationIsFulfilledMultipleTimes_fails' started.
28-
// CHECK: .*/Asynchronous/Misuse/main.swift:34: unexpected error: MisuseTestCase.test_whenExpectationIsFulfilledMultipleTimes_fails : API violation - multiple calls made to XCTestExpectation.fulfill\(\) for rob.
29-
// CHECK: .*/Asynchronous/Misuse/main.swift:44: unexpected error: MisuseTestCase.test_whenExpectationIsFulfilledMultipleTimes_fails : API violation - multiple calls made to XCTestExpectation.fulfill\(\) for rob.
28+
// CHECK: .*/Asynchronous/Misuse/main.swift:[[@LINE+6]]: unexpected error: MisuseTestCase.test_whenExpectationIsFulfilledMultipleTimes_fails : API violation - multiple calls made to XCTestExpectation.fulfill\(\) for rob.
29+
// CHECK: .*/Asynchronous/Misuse/main.swift:[[@LINE+15]]: unexpected error: MisuseTestCase.test_whenExpectationIsFulfilledMultipleTimes_fails : API violation - multiple calls made to XCTestExpectation.fulfill\(\) for rob.
3030
// CHECK: Test Case 'MisuseTestCase.test_whenExpectationIsFulfilledMultipleTimes_fails' failed \(\d+\.\d+ seconds\).
3131
func test_whenExpectationIsFulfilledMultipleTimes_fails() {
3232
let expectation = self.expectationWithDescription("rob")

Tests/Functional/ErrorHandling/main.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class ErrorHandling: XCTestCase {
1212
// CHECK: Test Case 'ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion' started.
13-
// CHECK: .*/ErrorHandling/main.swift:16: error: ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion : XCTAssertThrowsError failed: did not throw error - $
13+
// CHECK: .*/ErrorHandling/main.swift:[[@LINE+3]]: error: ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion : XCTAssertThrowsError failed: did not throw error - $
1414
// CHECK: Test Case 'ErrorHandling.test_shouldButDoesNotThrowErrorInAssertion' failed \(\d+\.\d+ seconds\).
1515
func test_shouldButDoesNotThrowErrorInAssertion() {
1616
XCTAssertThrowsError(try functionThatDoesNotThrowError())
@@ -33,7 +33,7 @@ class ErrorHandling: XCTestCase {
3333
}
3434

3535
// CHECK: Test Case 'ErrorHandling.test_throwsErrorInAssertionButFailsWhenCheckingError' started.
36-
// CHECK: .*/ErrorHandling/main.swift:47: error: ErrorHandling.test_throwsErrorInAssertionButFailsWhenCheckingError : XCTAssertEqual failed: \("Optional\("an error message"\)"\) is not equal to \("Optional\(""\)"\) - $
36+
// CHECK: .*/ErrorHandling/main.swift:[[@LINE+11]]: error: ErrorHandling.test_throwsErrorInAssertionButFailsWhenCheckingError : XCTAssertEqual failed: \("Optional\("an error message"\)"\) is not equal to \("Optional\(""\)"\) - $
3737
// CHECK: Test Case 'ErrorHandling.test_throwsErrorInAssertionButFailsWhenCheckingError' failed \(\d+\.\d+ seconds\).
3838
func test_throwsErrorInAssertionButFailsWhenCheckingError() {
3939
XCTAssertThrowsError(try functionThatDoesThrowError()) { error in
@@ -63,7 +63,7 @@ class ErrorHandling: XCTestCase {
6363
}
6464

6565
// CHECK: Test Case 'ErrorHandling.test_assertionExpressionCanThrow' started.
66-
// CHECK: .*/ErrorHandling/main.swift:69: unexpected error: ErrorHandling.test_assertionExpressionCanThrow : XCTAssertEqual threw error "AnError\("did not actually return"\)" - $
66+
// CHECK: .*/ErrorHandling/main.swift:[[@LINE+3]]: unexpected error: ErrorHandling.test_assertionExpressionCanThrow : XCTAssertEqual threw error "AnError\("did not actually return"\)" - $
6767
// CHECK: Test Case 'ErrorHandling.test_assertionExpressionCanThrow' failed \(\d+\.\d+ seconds\).
6868
func test_assertionExpressionCanThrow() {
6969
XCTAssertEqual(try functionThatShouldReturnButThrows(), 1)

Tests/Functional/FailingTestSuite/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ class FailingTestCase: XCTestCase {
3030
}
3131

3232
// CHECK: Test Case 'FailingTestCase.test_fails' started.
33-
// CHECK: .*/FailingTestSuite/main.swift:\d+: error: FailingTestCase.test_fails : XCTAssertTrue failed - $
33+
// CHECK: .*/FailingTestSuite/main.swift:[[@LINE+3]]: error: FailingTestCase.test_fails : XCTAssertTrue failed - $
3434
// CHECK: Test Case 'FailingTestCase.test_fails' failed \(\d+\.\d+ seconds\).
3535
func test_fails() {
3636
XCTAssert(false)
3737
}
3838

3939
// CHECK: Test Case 'FailingTestCase.test_fails_with_message' started.
40-
// CHECK: .*/FailingTestSuite/main.swift:\d+: error: FailingTestCase.test_fails_with_message : XCTAssertTrue failed - Foo bar.
40+
// CHECK: .*/FailingTestSuite/main.swift:[[@LINE+3]]: error: FailingTestCase.test_fails_with_message : XCTAssertTrue failed - Foo bar.
4141
// CHECK: Test Case 'FailingTestCase.test_fails_with_message' failed \(\d+\.\d+ seconds\).
4242
func test_fails_with_message() {
4343
XCTAssert(false, "Foo bar.")

0 commit comments

Comments
 (0)