Swift: Accessing value from array in unit test loop crashes with EXC_BAD_ACCESS

Originator:mail
Number:rdar://17222858 Date Originated:2014-06-08
Status:Open Resolved:
Product:Swift Product Version:Xcode 6 beta 1 / OS X 10.9.3
Classification:Crash Reproducible:Yes
 
Summary:
I'm building a unit test that loops through an array of CGPoints. Inside the loop it tries to access the point's .x and .y fields. This crashes the app after a few iterations through the loop with an EXC_BAD_ACCESS error.

Steps to Reproduce:
1. Create a new iOS project in Xcode (template doesn't matter).
2. Add the following unit test case:

import XCTest
import CoreGraphics

class TestThatCrashesTests: XCTestCase {
    
  func testLerp() {

    let expected = [
      CGPoint(x: -100, y: -150),
      CGPoint(x: -80, y: -130),
      CGPoint(x: -60, y: -110),
      CGPoint(x: -40, y: -90),
      CGPoint(x: -20, y: -70),
      CGPoint(x: 0, y: -50),
      CGPoint(x: 20, y: -30),
      CGPoint(x: 40, y: -10),
      CGPoint(x: 60, y: 10),
      CGPoint(x: 80, y: 30),
      CGPoint(x: 100, y: 50)
      ]

    var i = 0
    for var t = 0.0; t <= 1.0; t += 0.1, ++i {

      // silly test, but it crashes here:
      XCTAssertEqual(0.0, expected[i].x)
      XCTAssertEqual(0.0, expected[i].y)
    }
  }
}

3. Run the tests, see the app crash.

Expected Results:
The current test should fail, but not crash the app.

Actual Results:
The test crashes after several iterations of the loop. It is not an array out of bounds, i.e. i is not > 10 when the app crashes but more like 3 or 4.

Comments

It turns out that this is not related to the specific test I posted; it happens to any single test that fails on more than 3 or so assertions. The test runner crashes instead of properly handling the failed tests.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!