Skip to content

[test] Improve testing of Swift features #76740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 21 additions & 0 deletions docs/Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,27 @@ FIXME: full list.
* ``XFAIL: linux``: tests that need to be adapted for Linux, for example parts
that depend on Objective-C interop need to be split out.

#### Features ``REQUIRES: swift_feature_...``

Each of the Swift compiler features defined in `include/swift/Basic/Features.def`
will get a LLVM Lit feature prefixing `swift_feature_` to the feature name
automatically. The LLVM Lit features will be available only in those
configurations where the compiler supports the given feature, and will not be
available when the compiler does not support the feature. This means that
standard language features and upcoming features will always be available,
while experimental features will only be available when the compiler supports
them.

For every test that uses `--enable-experimental-feature` or
`--enable-upcoming-feature` add a `REQUIRES: swift_feature_...` for each of the
used features. The `Misc/verify-swift-feature-testing.test-sh` will check that
every test with those command line arguments have the necessary `REQUIRES:` and
fail otherwise.

Do NOT add `REQUIRES: asserts` for experimental features anymore. The correct
usage of `REQUIRES: swift_feature_...` will take care of testing the feature as
it evolves from experimental, to upcoming, to language feature.

#### Feature ``REQUIRES: executable_test``

This feature marks an executable test. The test harness makes this feature
Expand Down
3 changes: 1 addition & 2 deletions test/ASTGen/attrs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

// REQUIRES: executable_test
// REQUIRES: swift_swift_parser
// REQUIRES: swift_feature_ParserASTGen

// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// rdar://116686158
// UNSUPPORTED: asan

Expand Down
5 changes: 3 additions & 2 deletions test/ASTGen/decls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

// REQUIRES: executable_test
// REQUIRES: swift_swift_parser
// REQUIRES: swift_feature_ParserASTGen
// REQUIRES: swift_feature_SwiftParser
// REQUIRES: swift_feature_ValueGenerics

// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// rdar://116686158
// UNSUPPORTED: asan

Expand Down
3 changes: 1 addition & 2 deletions test/ASTGen/diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-bare-slash-regex -enable-experimental-feature ParserASTGen

// REQUIRES: swift_swift_parser
// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// REQUIRES: swift_feature_ParserASTGen
// rdar://116686158
// UNSUPPORTED: asan

Expand Down
4 changes: 2 additions & 2 deletions test/ASTGen/do_expr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature DoExpressions -enable-experimental-feature ParserASTGen

// REQUIRES: swift_swift_parser
// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// REQUIRES: swift_feature_DoExpressions
// REQUIRES: swift_feature_ParserASTGen
// rdar://116686158
// UNSUPPORTED: asan

Expand Down
4 changes: 2 additions & 2 deletions test/ASTGen/exprs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

// REQUIRES: executable_test
// REQUIRES: swift_swift_parser
// REQUIRES: swift_feature_ParserASTGen
// REQUIRES: swift_feature_SwiftParser

// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// rdar://116686158
// UNSUPPORTED: asan

Expand Down
4 changes: 2 additions & 2 deletions test/ASTGen/if_config.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ParserASTGen -DDISCARDABLE -DNONSENDABLE -swift-version 6
/// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts

// REQUIRES: swift_feature_ParserASTGen

#if NOT_SET
func f { } // expected-error{{expected parameter clause in function signature}}
Expand Down
3 changes: 1 addition & 2 deletions test/ASTGen/if_config_expr.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ParserASTGen -D CONDITION_1

// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// REQUIRES: swift_swift_parser
// REQUIRES: swift_feature_ParserASTGen

postfix operator ++
postfix func ++ (_: Int) -> Int { 0 }
Expand Down
1 change: 1 addition & 0 deletions test/ASTGen/macros.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// REQUIRES: swift_swift_parser, asserts
// REQUIRES: swift_feature_ParserASTGen

// RUN: %empty-directory(%t)

Expand Down
3 changes: 1 addition & 2 deletions test/ASTGen/regex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ParserASTGen -enable-bare-slash-regex -disable-availability-checking

// REQUIRES: swift_swift_parser
// REQUIRES: swift_feature_ParserASTGen

// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// rdar://116686158
// UNSUPPORTED: asan

Expand Down
5 changes: 3 additions & 2 deletions test/ASTGen/stmts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

// REQUIRES: executable_test
// REQUIRES: swift_swift_parser
// REQUIRES: swift_feature_ParserASTGen
// REQUIRES: swift_feature_SwiftParser
// REQUIRES: swift_feature_ThenStatements

// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// rdar://116686158
// UNSUPPORTED: asan

Expand Down
4 changes: 2 additions & 2 deletions test/ASTGen/top_level.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

// RUN: %diff -u %t/astgen.ast %t/cpp-parser.ast

// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// REQUIRES: swift_feature_ParserASTGen

// rdar://116686158
// UNSUPPORTED: asan

Expand Down
4 changes: 2 additions & 2 deletions test/ASTGen/types.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-feature ParserASTGen

// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
// REQUIRES: swift_feature_ParserASTGen

// rdar://116686158
// UNSUPPORTED: asan

Expand Down
2 changes: 1 addition & 1 deletion test/AssociatedTypeInference/associated_type_tuple.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-feature TupleConformances

// REQUIRES: asserts
// REQUIRES: swift_feature_TupleConformances

typealias Tuple<each T> = (repeat each T)

Expand Down
3 changes: 3 additions & 0 deletions test/CAS/block-list.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
// RUN: -cache-replay-prefix-map /^tmp=%t \
// RUN: /^tmp/main.swift @%t/MyApp.cmd 2>&1 | %FileCheck %s --check-prefix CHECK-BLOCKED

// REQUIRES: swift_feature_LayoutStringValueWitnesses
// REQUIRES: swift_feature_LayoutStringValueWitnessesInstantiation

// CHECK-BLOCKED: note: Layout string value witnesses have been disabled for module 'Test' through block list entry
// CHECK-BLOCKED-NOT: type_layout_string

Expand Down
45 changes: 45 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ if(NOT "${COVERAGE_DB}" STREQUAL "")
COMMENT "Touching covering tests")
endif()

if(SWIFT_COMPILER_IS_MSVC_LIKE)
set(C_PREPROCESSOR_COMMAND
"${CMAKE_C_COMPILER}" "/P" "/EP" "/I" "${SWIFT_MAIN_INCLUDE_DIR}" "/TC"
"/Fi<<<OUTPUT_FILE>>>")
else()
set(C_PREPROCESSOR_COMMAND
"${CMAKE_C_COMPILER}" "-E" "-P" "-I${SWIFT_MAIN_INCLUDE_DIR}" "-x" "c" "-o"
"<<<OUTPUT_FILE>>>")
endif()

foreach(SDK ${SWIFT_SDKS})
foreach(ARCH ${SWIFT_SDK_${SDK}_ARCHITECTURES})
# macCatalyst needs to run two sets of tests: one with the normal macosx target triple
Expand Down Expand Up @@ -304,6 +314,38 @@ foreach(SDK ${SWIFT_SDKS})
"${validation_test_bin_dir}/lit.site.cfg"
"validation-test${VARIANT_SUFFIX}.lit.site.cfg")

set(test_lit_swift_features_cmd ${C_PREPROCESSOR_COMMAND})
list(
TRANSFORM test_lit_swift_features_cmd
REPLACE "<<<OUTPUT_FILE>>>" "${test_bin_dir}/lit.swift-features.cfg")
add_custom_command(
OUTPUT "${test_bin_dir}/lit.swift-features.cfg"
COMMAND
${test_lit_swift_features_cmd}
"${CMAKE_CURRENT_SOURCE_DIR}/lit.swift-features.cfg.inc"
DEPENDS
"lit.swift-features.cfg.inc"
"${SWIFT_MAIN_INCLUDE_DIR}/swift/Basic/Features.def"
)

set(validation_test_lit_swift_features_cmd ${C_PREPROCESSOR_COMMAND})
list(
TRANSFORM validation_test_lit_swift_features_cmd
REPLACE "<<<OUTPUT_FILE>>>" "${validation_test_bin_dir}/lit.swift-features.cfg")
add_custom_command(
OUTPUT "${validation_test_bin_dir}/lit.swift-features.cfg"
COMMAND
${validation_test_lit_swift_features_cmd}
"${CMAKE_CURRENT_SOURCE_DIR}/lit.swift-features.cfg.inc"
DEPENDS
"lit.swift-features.cfg.inc"
"${SWIFT_MAIN_INCLUDE_DIR}/swift/Basic/Features.def"
)
add_custom_target(lit_swift_features_cfg_${VARIANT_SUFFIX}
DEPENDS
"${test_bin_dir}/lit.swift-features.cfg"
"${validation_test_bin_dir}/lit.swift-features.cfg")

set(test_dependencies)
get_test_dependencies("${SDK}" test_dependencies)

Expand Down Expand Up @@ -341,6 +383,9 @@ foreach(SDK ${SWIFT_SDKS})

set(validation_test_dependencies)

list(APPEND test_dependencies lit_swift_features_cfg_${VARIANT_SUFFIX})
list(APPEND validation_test_dependencies lit_swift_features_cfg_${VARIANT_SUFFIX})

set(command_upload_stdlib)
set(command_upload_swift_reflection_test)
if("${SDK}" STREQUAL "IOS" OR "${SDK}" STREQUAL "TVOS" OR "${SDK}" STREQUAL "WATCHOS" OR "${SDK}" STREQUAL "XROS")
Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/dynamic_actor_isolation_checks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -disable-availability-checking -enable-upcoming-feature DynamicActorIsolation -emit-silgen -module-name preconcurrency_conformances %t/src/checks.swift | %FileCheck %t/src/checks.swift
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -disable-availability-checking -swift-version 6 -disable-dynamic-actor-isolation -emit-silgen -module-name preconcurrency_conformances %t/src/checks_disabled.swift | %FileCheck %t/src/checks_disabled.swift

// REQUIRES: asserts
// REQUIRES: concurrency
// REQUIRES: objc_interop
// REQUIRES: swift_feature_DynamicActorIsolation

//--- checks.swift
import Foundation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// REQUIRES: objc_interop
// REQUIRES: executable_test
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

// Verify that Clang declarations referencing either of the forward declares types "ForwardDeclaredInterface" or
// "ForwardDeclaredProtocol" are usable from Swift.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// REQUIRES: objc_interop
// REQUIRES: executable_test
// REQUIRES: OS=macosx
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

import Foundation
import IncompleteTypeLibrary1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %target-swift-frontend -import-objc-header %S/Inputs/incomplete_objc_types_bridging_header.h -enable-upcoming-feature ImportObjcForwardDeclarations -enable-objc-interop -typecheck %s

// REQUIRES: objc_interop
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

let foo = CFunctionReturningAForwardDeclaredInterface()
CFunctionTakingAForwardDeclaredInterface(foo)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

// REQUIRES: objc_interop
// REQUIRES: executable_test
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

// "ForwardDeclaredInterface" and "ForwardDeclaredProtocol" are forward declared in IncompleteTypeLibrary1/2, and
// completely declared in CompleteTypes. This test verifies that instances of the complete types can be passed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

// REQUIRES: executable_test
// REQUIRES: objc_interop
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

//--- full_definition.swift

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// RUN: not %target-swift-frontend -enable-upcoming-feature ImportObjcForwardDeclarations -enable-objc-interop -typecheck -I %S/Inputs/custom-modules/IncompleteTypes -I %t %t/incomplete_definition.swift %t/full_definition.swift -diagnostic-style llvm 2>&1 | %FileCheck %s

// REQUIRES: objc_interop
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

//--- full_definition.swift

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

// REQUIRES: objc_interop
// REQUIRES: executable_test
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

// Both libraries "IncompleteTypeConsumer1" and "IncompleteTypeConsumer2" forward declare an interface "ForwardDeclaredInterface"
// and a protocol "ForwardDeclaredProtocol". This test verifies that the synthesized Swift declaration created to represent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

// REQUIRES: objc_interop
// REQUIRES: executable_test
// REQUIRES: swift_feature_ImportObjCForwardDeclarations

import IncompleteTypeLibrary1
import CompleteTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// RUN: not %target-swift-frontend -swift-version 6 -enable-objc-interop -typecheck -I %S/Inputs/custom-modules/IncompleteTypes %s -diagnostic-style llvm 2>&1 | %FileCheck %s

// REQUIRES: objc_interop
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

import IncompleteTypeLibrary1
import IncompleteNoRootTypeProtocolLibrary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// RUN: not %target-swift-frontend -swift-version 6 -enable-objc-interop -typecheck -I %S/Inputs/custom-modules/IncompleteTypes %s 2>&1 | %FileCheck %s

// REQUIRES: objc_interop
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

import IncompleteTypeLibrary1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

// REQUIRES: objc_interop
// REQUIRES: executable_test
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

// Verify that a forward declared protocol not inheriting from NSObject is usable
// from Swift, if cumbersome
Expand Down
1 change: 1 addition & 0 deletions test/ClangImporter/incomplete_objc_types_nsproxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

// REQUIRES: objc_interop
// REQUIRES: executable_test
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

// Verify that a forward declared interface for a type inheriting from NSProxy instead
// of NSObject is still usable from Swift.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: not %target-swift-frontend -swift-version 6 -enable-objc-interop -typecheck -I %S/Inputs/custom-modules/IncompleteTypes -I %t %s -diagnostic-style llvm 2>&1 | %FileCheck %s

// REQUIRES: objc_interop
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

import CompleteSwiftTypes
import ObjCLibraryForwardDeclaringCompleteSwiftTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: not %target-swift-frontend -swift-version 6 -enable-objc-interop -typecheck -I %S/Inputs/custom-modules/IncompleteTypes -I %t %s -diagnostic-style llvm 2>&1 | %FileCheck %s

// REQUIRES: objc_interop
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

@_implementationOnly import CompleteSwiftTypes
import ObjCLibraryForwardDeclaringCompleteSwiftTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// RUN: not %target-swift-frontend -swift-version 6 -enable-objc-interop -typecheck -I %S/Inputs/custom-modules/IncompleteTypes -I %t %s -diagnostic-style llvm 2>&1 | %FileCheck %s

// REQUIRES: objc_interop
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

import CompleteSwiftTypes
import ObjCLibraryForwardDeclaringCompleteSwiftTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

// REQUIRES: objc_interop
// REQUIRES: executable_test
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

import CompleteSwiftTypes
import ObjCLibraryForwardDeclaringCompleteSwiftTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// RUN: -enable-objc-interop -swift-version 6 -source-filename x | %FileCheck %s

// REQUIRES: objc_interop
// REQUIRES: swift_feature_ImportObjcForwardDeclarations

// CHECK: import Foundation
// CHECK: @available(*, unavailable, message: "This Objective-C class has only been forward-declared; import its owning module to use it")
Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/objc_async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// REQUIRES: objc_interop
// REQUIRES: concurrency
// REQUIRES: asserts
// REQUIRES: swift_feature_SendableCompletionHandlers

import Foundation
import ObjCConcurrency
Expand Down
Loading