[test] Update tests for new (conditional) _debugPrecondition behavior

This commit is contained in:
Karoy Lorentey
2022-02-18 21:54:02 -08:00
parent 2643e8dcf3
commit 5274295e3f
7 changed files with 101 additions and 6 deletions

View File

@@ -202,6 +202,7 @@ normalize_boolean_spelling(SWIFT_OPTIMIZED)
normalize_boolean_spelling(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME)
normalize_boolean_spelling(SWIFT_ENABLE_REFLECTION)
normalize_boolean_spelling(SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS)
normalize_boolean_spelling(SWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE)
normalize_boolean_spelling(SWIFT_HAVE_LIBXML2)
normalize_boolean_spelling(SWIFT_INCLUDE_TOOLS)
normalize_boolean_spelling(SWIFT_STDLIB_STATIC_PRINT)

View File

@@ -143,6 +143,8 @@ if "@SWIFT_STDLIB_ENABLE_UNICODE_DATA" == "TRUE":
config.available_features.add('stdlib_unicode_data')
if "@SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING@" == "TRUE":
config.available_features.add('string_processing')
if "@SWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE@" == "TRUE":
config.available_features.add('swift_stdlib_debug_preconditions_in_release')
config.swift_freestanding_is_darwin = "@SWIFT_FREESTANDING_IS_DARWIN@" == "TRUE"
config.swift_enable_dispatch = "@SWIFT_ENABLE_DISPATCH@" == "TRUE"

View File

@@ -129,7 +129,7 @@ if #available(SwiftStdlib 5.5, *) {
// Debug check was introduced in https://github.com/apple/swift/pull/34961
RangeTraps.test("UncheckedHalfOpen")
.xfail(.custom(
{ !_isDebugAssertConfiguration() },
{ !_isStdlibDebugChecksEnabled() },
reason: "assertions are disabled in Release and Unchecked mode"))
.code {
expectCrashLater()
@@ -138,7 +138,7 @@ if #available(SwiftStdlib 5.5, *) {
RangeTraps.test("UncheckedClosed")
.xfail(.custom(
{ !_isDebugAssertConfiguration() },
{ !_isStdlibDebugChecksEnabled() },
reason: "assertions are disabled in Release and Unchecked mode"))
.code {
expectCrashLater()

View File

@@ -122,6 +122,8 @@ if "@SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED@" == "TRUE":
config.available_features.add('distributed')
if "@SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING@" == "TRUE":
config.available_features.add('string_processing')
if "@SWIFT_STDLIB_ENABLE_DEBUG_PRECONDITIONS_IN_RELEASE@" == "TRUE":
config.available_features.add('swift_stdlib_debug_preconditions_in_release')
config.swift_freestanding_is_darwin = "@SWIFT_FREESTANDING_IS_DARWIN@" == "TRUE"
config.swift_enable_dispatch = "@SWIFT_ENABLE_DISPATCH@" == "TRUE"

View File

@@ -0,0 +1,34 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -Xfrontend -disable-access-control -o %t/Assert_Debug -Onone
// RUN: %target-build-swift %s -Xfrontend -disable-access-control -o %t/Assert_Release -O
// RUN: %target-build-swift %s -Xfrontend -disable-access-control -o %t/Assert_Unchecked -Ounchecked
// RUN: %target-codesign %t/Assert_Debug
// RUN: %target-codesign %t/Assert_Release
// RUN: %target-codesign %t/Assert_Unchecked
// RUN: %target-run %t/Assert_Debug | %FileCheck --check-prefixes=DEBUG %s
// RUN: %target-run %t/Assert_Release | %FileCheck --check-prefixes=RELEASE %s
// RUN: %target-run %t/Assert_Unchecked | %FileCheck --check-prefixes=UNCHECKED %s
// UNSUPPORTED: swift_stdlib_debug_preconditions_in_release
// DEBUG: _isStdlibDebugChecksEnabled: true
// RELEASE: _isStdlibDebugChecksEnabled: false
// UNCHECKED: _isStdlibDebugChecksEnabled: false
print("_isStdlibDebugChecksEnabled: \(_isStdlibDebugChecksEnabled())")
func check() -> Bool {
print("Debug preconditions are active")
return true
}
// DEBUG-NEXT: Debug preconditions are active
// RELEASE-NOT: Debug preconditions are active
// UNCHECKED-NOT: Debug preconditions are active
_debugPrecondition(check()) // Note: side effects in an assert are a terrible
// idea; do not emulate this pattern in real code.
// DEBUG-NEXT: Done
// RELEASE-NEXT: Done
// UNCHECKED-NEXT: Done
print("Done")

View File

@@ -0,0 +1,34 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -Xfrontend -disable-access-control -o %t/Assert_Debug -Onone
// RUN: %target-build-swift %s -Xfrontend -disable-access-control -o %t/Assert_Release -O
// RUN: %target-build-swift %s -Xfrontend -disable-access-control -o %t/Assert_Unchecked -Ounchecked
// RUN: %target-codesign %t/Assert_Debug
// RUN: %target-codesign %t/Assert_Release
// RUN: %target-codesign %t/Assert_Unchecked
// RUN: %target-run %t/Assert_Debug | %FileCheck --check-prefixes=DEBUG %s
// RUN: %target-run %t/Assert_Release | %FileCheck --check-prefixes=RELEASE %s
// RUN: %target-run %t/Assert_Unchecked | %FileCheck --check-prefixes=UNCHECKED %s
// REQUIRES: swift_stdlib_debug_preconditions_in_release
// DEBUG: _isStdlibDebugChecksEnabled: true
// RELEASE: _isStdlibDebugChecksEnabled: true
// UNCHECKED: _isStdlibDebugChecksEnabled: false
print("_isStdlibDebugChecksEnabled: \(_isStdlibDebugChecksEnabled())")
func check() -> Bool {
print("Debug preconditions are active")
return true
}
// DEBUG-NEXT: Debug preconditions are active
// RELEASE-NEXT: Debug preconditions are active
// UNCHECKED-NOT: Debug preconditions are active
_debugPrecondition(check()) // Note: side effects in an assert are a terrible
// idea; do not emulate this pattern in real code.
// DEBUG-NEXT: Done
// RELEASE-NEXT: Done
// UNCHECKED-NEXT: Done
print("Done")

View File

@@ -174,10 +174,32 @@ Assert.test("preconditionFailure")
preconditionFailure("this should fail")
}
Assert.test("_precondition")
.xfail(.custom(
{ _isFastAssertConfiguration() },
reason: "preconditions are disabled in Unchecked mode"))
.crashOutputMatches(_isDebugAssertConfiguration() ? "this should fail" : "")
.code {
var x = 2
_precondition(x * 21 == 42, "should not fail")
expectCrashLater()
_precondition(x == 42, "this should fail")
}
Assert.test("_preconditionFailure")
.skip(.custom(
{ _isFastAssertConfiguration() },
reason: "optimizer assumes that the code path is unreachable"))
.crashOutputMatches(_isDebugAssertConfiguration() ? "this should fail" : "")
.code {
expectCrashLater()
_preconditionFailure("this should fail")
}
Assert.test("_debugPrecondition")
.xfail(.custom(
{ !_isDebugAssertConfiguration() },
reason: "debug preconditions are disabled in Release and Unchecked mode"))
{ !_isStdlibDebugChecksEnabled() },
reason: "debug preconditions are disabled"))
.crashOutputMatches(_isDebugAssertConfiguration() ? "this should fail" : "")
.code {
var x = 2
@@ -188,9 +210,9 @@ Assert.test("_debugPrecondition")
Assert.test("_debugPreconditionFailure")
.skip(.custom(
{ !_isDebugAssertConfiguration() },
{ !_isStdlibDebugChecksEnabled() },
reason: "optimizer assumes that the code path is unreachable"))
.crashOutputMatches("this should fail")
.crashOutputMatches(_isDebugAssertConfiguration() ? "this should fail" : "")
.code {
expectCrashLater()
_debugPreconditionFailure("this should fail")