|
| 1 | +/// Implementation-only dependencies of modules imported as testable are |
| 2 | +/// optional, we attempt to load them but don't error if they are missing. |
| 3 | + |
| 4 | +// RUN: %empty-directory(%t) |
| 5 | +// RUN: split-file %s %t |
| 6 | + |
| 7 | +/// Build the hidden implementation-only dependency and the testable module. |
| 8 | +// RUN: %target-swift-frontend -emit-module %t/HiddenDep.swift -o %t \ |
| 9 | +// RUN: -swift-version 5 -enable-library-evolution |
| 10 | +// RUN: %target-swift-frontend -emit-module %t/TestedLib.swift -o %t \ |
| 11 | +// RUN: -swift-version 5 -enable-library-evolution -I %t \ |
| 12 | +// RUN: -enable-testing |
| 13 | + |
| 14 | +/// A client should ignore the transitive implementation-only dependency for a |
| 15 | +/// normal import. |
| 16 | +// RUN: %target-swift-frontend -typecheck %t/ClientNormalImport.swift -o %t \ |
| 17 | +// RUN: -swift-version 5 -I %t -Rmodule-loading 2>&1 | \ |
| 18 | +// RUN: %FileCheck --check-prefix=CHECK-NOT-LOADED %s |
| 19 | + |
| 20 | +/// A client should load the transitive implementation-only dependency of |
| 21 | +/// a module imported @testable. |
| 22 | +// RUN: %target-swift-frontend -typecheck %t/ClientTestableImport.swift -o %t \ |
| 23 | +// RUN: -swift-version 5 -I %t -Rmodule-loading 2>&1 | %FileCheck %s |
| 24 | + |
| 25 | +/// If the dependency is missing we don't fail at loading, but we may still |
| 26 | +/// fail later accessing decls missing because of references to the not-loaded module. |
| 27 | +// RUN: rm %t/HiddenDep.swiftmodule |
| 28 | + |
| 29 | +/// The transitive dependency is not loaded but a client can still build fine. |
| 30 | +// RUN: %target-swift-frontend -typecheck %t/ClientNormalImport.swift -o %t \ |
| 31 | +// RUN: -swift-version 5 -I %t -Rmodule-loading 2>&1 | \ |
| 32 | +// RUN: %FileCheck %s --check-prefix=CHECK-NOT-LOADED |
| 33 | + |
| 34 | +/// Clients referencing a decl that depends on the hidden module don't see the |
| 35 | +/// decl, it is dropped by deserialization recovery. |
| 36 | +// RUN: %target-swift-frontend -typecheck %t/ClientTestableImport.swift -o %t \ |
| 37 | +// RUN: -swift-version 5 -I %t -verify |
| 38 | + |
| 39 | +//--- HiddenDep.swift |
| 40 | + |
| 41 | +public struct HiddenType {} |
| 42 | + |
| 43 | +//--- TestedLib.swift |
| 44 | + |
| 45 | +@_implementationOnly import HiddenDep |
| 46 | + |
| 47 | +internal func dependsOnHiddenType() -> HiddenType { fatalError() } |
| 48 | + |
| 49 | +//--- ClientNormalImport.swift |
| 50 | + |
| 51 | +/// Note that the import doesn't have to be testable, only the imported module |
| 52 | +/// needs to enable testing. We may want to improve upon this in the future. |
| 53 | +import TestedLib |
| 54 | +// CHECK-NOT-LOADED-NOT: remark: loaded module 'HiddenDep' |
| 55 | + |
| 56 | +//--- ClientTestableImport.swift |
| 57 | + |
| 58 | +@testable import TestedLib |
| 59 | +// CHECK: remark: loaded module 'HiddenDep' |
| 60 | + |
| 61 | +let _ = dependsOnHiddenType() // expected-error {{cannot find 'dependsOnHiddenType' in scope}} |
0 commit comments