|
| 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: no such module 'Bar' |
| 34 | + |
| 35 | +/// Client loads a private interface since the package-name is different from the loaded module's. |
| 36 | +// RUN: not %target-swift-frontend -typecheck %t/Client.swift -I %t \ |
| 37 | +// RUN: -package-name foopkg \ |
| 38 | +// RUN: -experimental-package-interface-load \ |
| 39 | +// RUN: -Rmodule-loading 2> %t/load-diff-pkg.output |
| 40 | +// RUN: %FileCheck -check-prefix=CHECK-LOAD-DIFF-PKG %s < %t/load-diff-pkg.output |
| 41 | +// CHECK-LOAD-DIFF-PKG: remark: loaded module 'Bar'; source: '{{.*}}Bar.private.swiftinterface', loaded: '{{.*}}Bar-{{.*}}.swiftmodule' |
| 42 | +// CHECK-LOAD-DIFF-PKG: error: cannot find 'PkgKlass' in scope; did you mean 'PubKlass'? |
| 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: no such module 'Bar' |
| 54 | + |
| 55 | +// RUN: rm -rf %t/*.swiftmodule |
| 56 | +// RUN: rm -rf %t/Bar.private.swiftinterface |
| 57 | + |
| 58 | +/// Client loads a public interface since package or private interface doesn't exist. |
| 59 | +/// It should error since the loaded module is not built from a package interface. |
| 60 | +// RUN: not %target-swift-frontend -typecheck %t/Client.swift -I %t \ |
| 61 | +// RUN: -package-name barpkg \ |
| 62 | +// RUN: -experimental-package-interface-load \ |
| 63 | +// RUN: -Rmodule-loading 2> %t/load-pub.output |
| 64 | + |
| 65 | +// RUN: %FileCheck -check-prefix=CHECK-LOAD-PUB %s < %t/load-pub.output |
| 66 | +// CHECK-LOAD-PUB: no such module 'Bar' |
| 67 | + |
| 68 | +//--- Bar.swift |
| 69 | +public class PubKlass { |
| 70 | + public var pubVar = "1" |
| 71 | + public init() {} |
| 72 | +} |
| 73 | + |
| 74 | +package class PkgKlass { |
| 75 | + package var pkgVar = "2" |
| 76 | + package init() {} |
| 77 | +} |
| 78 | + |
| 79 | +//--- Client.swift |
| 80 | +import Bar |
| 81 | + |
| 82 | +func foo() { |
| 83 | + print(PubKlass().pubVar, PkgKlass().pkgVar) |
| 84 | +} |
0 commit comments