swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
66.71k stars 10.28k forks source link

[SR-11250] Different behavior during testing between Xcode and SPM #53651

Open swift-ci opened 4 years ago

swift-ci commented 4 years ago
Previous ID SR-11250
Radar rdar://problem/53865954
Original Reporter DanielM (JIRA User)
Type Bug

Attachment: Download

Environment macOS 10.14.6 Xcode 11 beta5 Swift version 5.1-dev (LLVM af1f73e9e9, Swift 76e4d7f5ab) Swift Package Manager - Swift 5.1.0 (1e376cb3)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Standard Library | |Labels | Bug, 5.1Regression | |Assignee | @rxwei | |Priority | Medium | md5: 9977c576b3fd79f56fb4d8df664cb128

Issue Description:

I have a test for an angle calculation, in Xcode the test is successful, but if I use SPM to run the test, the calculation returns "nan" and the test fails. I've added a small project to show the strange behavior of SPM.

SPM

[7/7] Linking testswiftPackageTests
Test Suite 'All tests' started at 2019-08-02 13:11:01.065
Test Suite 'testswiftPackageTests.xctest' started at 2019-08-02 13:11:01.065
Test Suite 'testswiftTests' started at 2019-08-02 13:11:01.065
Test Case '-[testswiftTests.testswiftTests testExample]' started.
/Users/daniel/testswift/Tests/testswiftTests/testswiftTests.swift:37: error: [testswiftTests.testswiftTests testExample] : XCTAssertEqualWithAccuracy failed: ("nan") is not equal to ("55.53491470050634") +/ ("0.01")
Test Case '-[testswiftTests.testswiftTests testExample]' failed (0.133 seconds).
Test Suite 'testswiftTests' failed at 2019-08-02 13:11:01.198.
Executed 1 test, with 1 failure (0 unexpected) in 0.133 (0.133) seconds
Test Suite 'testswiftPackageTests.xctest' failed at 2019-08-02 13:11:01.198.
Executed 1 test, with 1 failure (0 unexpected) in 0.133 (0.134) seconds
Test Suite 'All tests' failed at 2019-08-02 13:11:01.198.
Executed 1 test, with 1 failure (0 unexpected) in 0.133 (0.134) seconds

Xcode

Test Suite 'All tests' started at 2019-08-02 13:23:12.967
Test Suite 'testswiftTests.xctest' started at 2019-08-02 13:23:12.967
Test Suite 'testswiftTests' started at 2019-08-02 13:23:12.968
Test Case '-[testswiftTests.testswiftTests testExample]' started.
Test Case '-[testswiftTests.testswiftTests testExample]' passed (0.081 seconds).
Test Suite 'testswiftTests' passed at 2019-08-02 13:23:13.049.
Executed 1 test, with 0 failures (0 unexpected) in 0.081 (0.082) seconds
Test Suite 'testswiftTests.xctest' passed at 2019-08-02 13:23:13.051.
Executed 1 test, with 0 failures (0 unexpected) in 0.081 (0.083) seconds
Test Suite 'All tests' passed at 2019-08-02 13:23:13.051.
Executed 1 test, with 0 failures (0 unexpected) in 0.081 (0.084) seconds

swift-ci commented 4 years ago

Comment by Daniel Müllenborn (JIRA)

I found out that the following code cannot be compiled correctly with SPM.

import Foundation

precedencegroup ExponentiationPrecedence {
  associativity: right
  higherThan: MultiplicationPrecedence
}

infix operator **: ExponentiationPrecedence
infix operator **=: AssignmentPrecedence

extension Double {
  static func ** (lhs: Double, rhs: Double) -> Double {
    return pow(lhs, rhs)
  }

  static func **= (lhs: inout Double, rhs: Double) {
    lhs = lhs ** rhs
  }
}
let az: Double = 2.737712023738262
let el: Double = 0.4587429800191673
let beta: Double = 0
let sfaz: Double = 0

let theta: Double = (cos(az - sfaz) / abs(cos(az - sfaz)) * 180
  / .pi * acos(sqrt(1 - (cos(el - beta) - cos(beta) * cos(el)
    * (1 - cos(az - sfaz))) ** 2)))

print(theta) // prints "nan" only when build with SPM
belkadan commented 4 years ago

@swift-ci create

belkadan commented 4 years ago

Hm, I'm not seeing this with a non-dev build. DanielM (JIRA User), did you get your 5.1 from a downloadable toolchain, or did you build it yourself?

belkadan commented 4 years ago

And with master I get failures both in Xcode and in SwiftPM. So I'm going to assume that Xcode wasn't actually using your toolchain for whatever reason and hand this over to the stdlib folks. @stephentyrone?

swift-ci commented 4 years ago

Comment by Daniel Müllenborn (JIRA)

I also installed the Swift for TensorFlow Toolchain 0.4RC4, maybe this is the reason.

swift-ci commented 4 years ago

Comment by Daniel Müllenborn (JIRA)

I checked the SPM version again, and noticed that I accidentally used the TensorFlow toolchain.

swift-ci commented 4 years ago

Comment by Daniel Müllenborn (JIRA)

I think this bug should be fixed by your team.