Skip to content

Commit af8e3be

Browse files
committed
Add a client side test that loads package interface
1 parent edc5aba commit af8e3be

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
/// Generate a package swiftinterface. Note -package-name is repeated; the last value should be picked.
5+
// RUN: %target-swift-frontend -emit-module %t/Bar.swift -I %t \
6+
// RUN: -module-name Bar -package-name foopkg -package-name barpkg \
7+
// RUN: -enable-library-evolution -swift-version 5 \
8+
// RUN: -emit-module-interface-path %t/Bar.swiftinterface \
9+
// RUN: -emit-private-module-interface-path %t/Bar.private.swiftinterface \
10+
// RUN: -emit-package-module-interface-path %t/Bar.package.swiftinterface
11+
12+
/// Client should load a package interface module if enabled with -experimental-package-interface-load
13+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
14+
// RUN: -package-name barpkg \
15+
// RUN: -experimental-package-interface-load \
16+
// RUN: -Rmodule-loading 2> %t/load-pkg-flag.output
17+
// RUN: %FileCheck -check-prefix=CHECK-LOAD-PKG-ENABLED %s < %t/load-pkg-flag.output
18+
19+
/// Client should load a package interface module if enabled with env var `SWIFT_ENABLE_PACKAGE_INTERFACE_LOAD`
20+
// RUN: env SWIFT_ENABLE_PACKAGE_INTERFACE_LOAD=true \
21+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
22+
// RUN: -package-name barpkg \
23+
// RUN: -Rmodule-loading 2> %t/load-pkg-env-var.output
24+
// RUN: %FileCheck -check-prefix=CHECK-LOAD-PKG-ENABLED %s < %t/load-pkg-env-var.output
25+
26+
// CHECK-LOAD-PKG-ENABLED: loaded module 'Bar'; source: '{{.*}}Bar.package.swiftinterface', loaded: '{{.*}}Bar-{{.*}}.swiftmodule'
27+
28+
/// Client should not load a package interface module without the flag or the env var
29+
// RUN: not %target-swift-frontend -typecheck %t/Client.swift -I %t \
30+
// RUN: -package-name barpkg \
31+
// RUN: -Rmodule-loading 2> %t/load-pkg-off.output
32+
// RUN: %FileCheck -check-prefix=CHECK-LOAD-PKG-OFF %s < %t/load-pkg-off.output
33+
// CHECK-LOAD-PKG-OFF: loaded module 'Bar'; source: '{{.*}}Bar.private.swiftinterface', loaded: '{{.*}}Bar-{{.*}}.swiftmodule'
34+
// CHECK-LOAD-PKG-OFF: error: module 'Bar' is in package 'barpkg' but was built from a non-package interface; modules of the same package can only be loaded if built from source or package interface: {{.*}}Bar.private.swiftinterface
35+
36+
/// Client loads a private interface since the package-name is different from the loaded module's.
37+
// RUN: %target-swift-frontend -typecheck %t/Client.swift -I %t \
38+
// RUN: -package-name foopkg \
39+
// RUN: -experimental-package-interface-load \
40+
// RUN: -Rmodule-loading 2> %t/load-diff-pkg.output
41+
// RUN: %FileCheck -check-prefix=CHECK-LOAD-DIFF-PKG %s < %t/load-diff-pkg.output
42+
// CHECK-LOAD-DIFF-PKG: loaded module 'Bar'; source: '{{.*}}Bar.private.swiftinterface', loaded: '{{.*}}Bar-{{.*}}.swiftmodule'
43+
44+
// RUN: rm -rf %t/*.swiftmodule
45+
// RUN: rm -rf %t/Bar.package.swiftinterface
46+
47+
/// Client loads a private interface since package interface doesn't exist. It should error since the loaded module is not built from a package interface.
48+
// RUN: not %target-swift-frontend -typecheck %t/Client.swift -I %t \
49+
// RUN: -package-name barpkg \
50+
// RUN: -experimental-package-interface-load \
51+
// RUN: -Rmodule-loading 2> %t/load-priv.output
52+
// RUN: %FileCheck -check-prefix=CHECK-LOAD-PRIV %s < %t/load-priv.output
53+
// CHECK-LOAD-PRIV: loaded module 'Bar'; source: '{{.*}}Bar.private.swiftinterface', loaded: '{{.*}}Bar-{{.*}}.swiftmodule'
54+
// CHECK-LOAD-PRIV: error: module 'Bar' is in package 'barpkg' but was built from a non-package interface; modules of the same package can only be loaded if built from source or package interface: {{.*}}Bar.private.swiftinterface
55+
56+
// RUN: rm -rf %t/*.swiftmodule
57+
// RUN: rm -rf %t/Bar.private.swiftinterface
58+
59+
/// Client loads a public interface since package or private interface doesn't exist.
60+
/// It should error since the loaded module is not built from a package interface.
61+
// RUN: not %target-swift-frontend -typecheck %t/Client.swift -I %t \
62+
// RUN: -package-name barpkg \
63+
// RUN: -experimental-package-interface-load \
64+
// RUN: -Rmodule-loading 2> %t/load-pub.output
65+
66+
// RUN: %FileCheck -check-prefix=CHECK-LOAD-PUB %s < %t/load-pub.output
67+
// CHECK-LOAD-PUB: loaded module 'Bar'; source: '{{.*}}Bar.swiftinterface', loaded: '{{.*}}Bar-{{.*}}.swiftmodule'
68+
// CHECK-LOAD-PUB: error: module 'Bar' is in package 'barpkg' but was built from a non-package interface; modules of the same package can only be loaded if built from source or package interface: {{.*}}Bar.swiftinterface
69+
70+
//--- Bar.swift
71+
public class PubKlass {
72+
public var pubVar = "1"
73+
public init() {}
74+
}
75+
76+
package class PkgKlass {
77+
package var pkgVar = "2"
78+
package init() {}
79+
}
80+
81+
//--- Client.swift
82+
import Bar
83+
84+
func foo() {
85+
print(PubKlass().pubVar, PkgKlass().pkgVar)
86+
}

0 commit comments

Comments
 (0)