mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Different tests used different os checks for importing Darwin, Glibc and MSVCRT. This commit use the same pattern for importing those libraries, in order to avoid the #else branches of the incorrect patterns to be applied to the wrong platform. This was very normal for Android, which normally should follow the Linux branches, but sometimes was trying to import Darwin or not importing anything. The standarized pattern imports Darwin for macOS, iOS, tvOS and watchOS. It imports Glibc for Linux, FreeBSD, PS4, Android, Cygwin and Haiku; and imports MSVCRT for Windows. If a new platform is introduced, the else branch will report an error, so the new platform can be added to one of the branches (or maybe add a new specific branch). In some cases the standard pattern was modified because some test required it (importing extra modules, or extra type aliases), and in some other cases some branches were removed because the test will not have used them (but it is not exhaustive, so there might be some unnecessary branches). This should, at least, fix three tests for Android (the three dynamic_replacement*.swift ones).
42 lines
954 B
Swift
42 lines
954 B
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-build-swift %s -o %t/a.out -Ounchecked
|
|
// RUN: %target-codesign %t/a.out
|
|
// RUN: %target-run %t/a.out
|
|
// REQUIRES: executable_test
|
|
|
|
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
|
|
import Darwin
|
|
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku)
|
|
import Glibc
|
|
#elseif os(Windows)
|
|
import MSVCRT
|
|
#else
|
|
#error("Unsupported platform")
|
|
#endif
|
|
import StdlibUnittest
|
|
|
|
|
|
var TGMathTestSuite = TestSuite("tgmath")
|
|
|
|
let minusOneDouble = Double(-1.0)
|
|
let minusOneFloat = Float(-1.0)
|
|
|
|
@inline(never)
|
|
func minusOneDoubleFunction() -> Double{
|
|
return minusOneDouble
|
|
}
|
|
|
|
@inline(never)
|
|
func minusOneFloatFunction() -> Float {
|
|
return minusOneFloat
|
|
}
|
|
|
|
TGMathTestSuite.test("sqrt") {
|
|
expectTrue(sqrt(minusOneFloat).isNaN)
|
|
expectTrue(sqrt(minusOneFloatFunction()).isNaN)
|
|
expectTrue(sqrt(minusOneDouble).isNaN)
|
|
expectTrue(sqrt(minusOneDoubleFunction()).isNaN)
|
|
}
|
|
|
|
runAllTests()
|