Files
swift-mirror/validation-test/stdlib/FloatingPointConversionTraps.swift.gyb

144 lines
4.3 KiB
Plaintext

// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: %S/../../utils/gyb %s -o %t/FloatingPointConversionTraps.swift
// RUN: %S/../../utils/line-directive %t/FloatingPointConversionTraps.swift -- %target-build-swift %t/FloatingPointConversionTraps.swift -Xfrontend -disable-access-control -o %t/a.out_Debug
// RUN: %S/../../utils/line-directive %t/FloatingPointConversionTraps.swift -- %target-build-swift %t/FloatingPointConversionTraps.swift -Xfrontend -disable-access-control -o %t/a.out_Release -O
//
// RUN: %S/../../utils/line-directive %t/FloatingPointConversionTraps.swift -- %target-run %t/a.out_Debug
// RUN: %S/../../utils/line-directive %t/FloatingPointConversionTraps.swift -- %target-run %t/a.out_Release
// REQUIRES: executable_test
import StdlibUnittest
// Also import modules which are used by StdlibUnittest internally. This
// workaround is needed to link all required libraries in case we compile
// StdlibUnittest with -sil-serialize-all.
import SwiftPrivate
#if _runtime(_ObjC)
import ObjectiveC
#endif
%{
from SwiftIntTypes import all_integer_types
# Test cases are written in a way that they don't depend on the word size.
word_bits = 4
}%
#if arch(i386) || arch(x86_64)
extension Float80 {
public static var infinity: Float80 {
return 1.0 / 0.0
}
public static var quietNaN: Float80 {
return 0.0 / 0.0
}
}
#endif
func getInfiniteOrNaNMessage(floatType: String) -> String {
// FIXME: <rdar://problem/17958458> Int(Float80.quietNaN) is garbage
if floatType == "Float80" {
return ""
}
if _isDebugAssertConfiguration() {
return "either infinite or NaN"
}
return ""
}
func getTooSmallMessage() -> String {
if _isDebugAssertConfiguration() {
return "it is less than"
}
return ""
}
func getTooLargeMessage() -> String {
if _isDebugAssertConfiguration() {
return "it is greater than"
}
return ""
}
var FloatingPointConversion = TestSuite("FloatingPointConversion")
% for FloatSelf in ['Float32', 'Float64', 'Float80']:
% for int_ty in all_integer_types(word_bits):
% IntSelf = int_ty.stdlib_name
% if FloatSelf == 'Float80':
#if arch(i386) || arch(x86_64)
% end
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/+inf")
.xfail(.custom({ "${FloatSelf}" == "Float80" }, reason: "<rdar://problem/17958458> Int(Float80.quietNaN) is garbage"))
.crashOutputMatches(getInfiniteOrNaNMessage("${FloatSelf}")).code {
do {
var a = get${IntSelf}(${IntSelf}(get${FloatSelf}(0.0)))
expectEqual(0, a)
}
do {
var a = get${IntSelf}(${IntSelf}(get${FloatSelf}(123.0)))
expectEqual(123, a)
}
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(+${FloatSelf}.infinity)))
}
% if int_ty.is_signed:
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/-inf")
.xfail(.custom({ "${FloatSelf}" == "Float80" }, reason: "<rdar://problem/17958458> Int(Float80.quietNaN) is garbage"))
.crashOutputMatches(getInfiniteOrNaNMessage("${FloatSelf}")).code {
do {
var a = get${IntSelf}(${IntSelf}(get${FloatSelf}(-0.0)))
expectEqual(0, a)
}
do {
var a = get${IntSelf}(${IntSelf}(get${FloatSelf}(-123.0)))
expectEqual(-123, a)
}
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(-${FloatSelf}.infinity)))
}
% else:
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/negative")
.xfail(.custom({ "${FloatSelf}" == "Float80" }, reason: "<rdar://problem/17958458> Int(Float80.quietNaN) is garbage"))
.crashOutputMatches(getTooSmallMessage()).code {
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(-123.0)))
}
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/-inf")
.xfail(.custom({ "${FloatSelf}" == "Float80" }, reason: "<rdar://problem/17958458> Int(Float80.quietNaN) is garbage"))
.crashOutputMatches(getInfiniteOrNaNMessage("${FloatSelf}")).code {
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(-${FloatSelf}.infinity)))
}
% end
FloatingPointConversion.test("${FloatSelf}/${IntSelf}/NaN")
.xfail(.custom({ "${FloatSelf}" == "Float80" }, reason: "<rdar://problem/17958458> Int(Float80.quietNaN) is garbage"))
.crashOutputMatches(getInfiniteOrNaNMessage("${FloatSelf}")).code {
expectCrashLater()
get${IntSelf}(${IntSelf}(get${FloatSelf}(${FloatSelf}.quietNaN)))
}
% if FloatSelf == 'Float80':
#endif
% end
% end
% end
runAllTests()