forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccess-level-import-dependencies.swift
154 lines (129 loc) · 7.16 KB
/
access-level-import-dependencies.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/// Check that non-public dependencies are hidden from clients.
// RUN: %empty-directory(%t)
// RUN: split-file %s %t
/// Prepare a module to hide or show depending on the import access-level.
// RUN: %target-swift-frontend -emit-module %t/HiddenDep.swift -o %t \
// RUN: -swift-version 5 -enable-library-evolution
//--- HiddenDep.swift
//--- PublicDep.swift
public import HiddenDep
//--- PackageDep.swift
package import HiddenDep
//--- InternalDep.swift
internal import HiddenDep
//--- FileprivateDep.swift
fileprivate import HiddenDep
//--- PrivateDep.swift
private import HiddenDep
/// With resilience, non-public dependencies should be hidden.
// RUN: %target-swift-frontend -emit-module %t/PublicDep.swift -o %t -I %t \
// RUN: -enable-library-evolution \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -emit-module %t/PackageDep.swift -o %t -I %t \
// RUN: -enable-library-evolution -package-name MyPackage \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -emit-module %t/InternalDep.swift -o %t -I %t \
// RUN: -enable-library-evolution \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -emit-module %t/FileprivateDep.swift -o %t -I %t \
// RUN: -enable-library-evolution \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -emit-module %t/PrivateDep.swift -o %t -I %t \
// RUN: -enable-library-evolution \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -typecheck %t/ClientOfPublic.swift -I %t \
// RUN: -package-name MyOtherPackage \
// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=VISIBLE-DEP %s
// VISIBLE-DEP: loaded module 'HiddenDep'
//--- ClientOfPublic.swift
import PublicDep
// RUN: %target-swift-frontend -typecheck %t/ClientOfNonPublic.swift -I %t \
// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=HIDDEN-DEP %s
// HIDDEN-DEP-NOT: loaded module 'HiddenDep'
//--- ClientOfNonPublic.swift
import PackageDep
import InternalDep
import FileprivateDep
import PrivateDep
/// Without resilience, all access-level dependencies are visible to clients.
// RUN: %target-swift-frontend -emit-module %t/PublicDep.swift -o %t -I %t \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -emit-module %t/PackageDep.swift -o %t -I %t \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -emit-module %t/InternalDep.swift -o %t -I %t \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -emit-module %t/FileprivateDep.swift -o %t -I %t \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -emit-module %t/PrivateDep.swift -o %t -I %t \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -typecheck %t/ClientOfPublic.swift -I %t \
// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=VISIBLE-DEP %s
// RUN: %target-swift-frontend -typecheck %t/ClientOfNonPublic.swift -I %t \
// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=VISIBLE-DEP %s
/// Even with resilience and testing enabled, all non-public dependencies are
/// hidden if there are no testable imports.
// RUN: %target-swift-frontend -emit-module %t/PublicDep.swift -o %t -I %t \
// RUN: -enable-library-evolution -enable-testing \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -emit-module %t/PackageDep.swift -o %t -I %t \
// RUN: -enable-library-evolution -enable-testing -package-name MyPackage \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -emit-module %t/InternalDep.swift -o %t -I %t \
// RUN: -enable-library-evolution -enable-testing \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -emit-module %t/FileprivateDep.swift -o %t -I %t \
// RUN: -enable-library-evolution -enable-testing \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -emit-module %t/PrivateDep.swift -o %t -I %t \
// RUN: -enable-library-evolution -enable-testing \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -typecheck %t/ClientOfPublic.swift -I %t \
// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=VISIBLE-DEP %s
// RUN: %target-swift-frontend -typecheck %t/ClientOfNonPublic.swift -I %t \
// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=HIDDEN-DEP %s
/// With testable imports, transitive dependencies are required.
//--- TestableClientOfPublic.swift
@testable import PublicDep
//--- TestableClientOfNonPublic.swift
@testable import PackageDep // expected-error {{missing required module 'HiddenDep'}}
@testable import InternalDep // expected-error {{missing required module 'HiddenDep'}}
@testable import FileprivateDep // expected-error {{missing required module 'HiddenDep'}}
@testable import PrivateDep // expected-error {{missing required module 'HiddenDep'}}
// RUN: %target-swift-frontend -typecheck %t/TestableClientOfPublic.swift -I %t \
// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=VISIBLE-DEP %s
// RUN: %target-swift-frontend -typecheck %t/TestableClientOfNonPublic.swift -I %t \
// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefix=VISIBLE-DEP %s
/// In the case of a testable of a module reexporting another Swift module,
/// only non-public transitive dependencies from the first module are required.
/// Non-public imports from the reexported modules are not loaded, we could
/// revisit this if desired.
// RUN: %target-swift-frontend -emit-module %t/Exporter.swift -o %t -I %t \
// RUN: -enable-library-evolution -enable-testing \
// RUN: -enable-experimental-feature AccessLevelOnImport
// RUN: %target-swift-frontend -typecheck %t/ExporterClient.swift -I %t \
// RUN: -Rmodule-loading 2>&1 | %FileCheck -check-prefixes=CHECK-EXPORTER,HIDDEN-DEP %s
// CHECK-EXPORTER: 'InternalDep' has an ignored transitive dependency on 'HiddenDep'
//--- Exporter.swift
@_exported import InternalDep
//--- ExporterClient.swift
@testable import Exporter
/// Fail if the transitive dependency is missing.
// RUN: rm %t/HiddenDep.swiftmodule
// RUN: %target-swift-frontend -typecheck %t/TestableClientOfNonPublic.swift -I %t \
// RUN: -verify -show-diagnostics-after-fatal
/// In a multi-file scenario, we try and fail to load the transitive dependency
/// only for @testable imports, not regular imports.
// RUN: %target-swift-frontend -typecheck -I %t \
// RUN: %t/TestableClientOfNonPublic_FileA.swift \
// RUN: %t/TestableClientOfNonPublic_FileB.swift \
// RUN: -verify -show-diagnostics-after-fatal
// RUN: %target-swift-frontend -typecheck -wmo -I %t \
// RUN: %t/TestableClientOfNonPublic_FileA.swift \
// RUN: %t/TestableClientOfNonPublic_FileB.swift \
// RUN: -verify -show-diagnostics-after-fatal
//--- TestableClientOfNonPublic_FileA.swift
import InternalDep
@testable import FileprivateDep // expected-error {{missing required module 'HiddenDep'}}
//--- TestableClientOfNonPublic_FileB.swift
@testable import InternalDep // expected-error {{missing required module 'HiddenDep'}}
import FileprivateDep