|
| 1 | +/// Test diagnostics with module aliasing. |
| 2 | +/// |
| 3 | +/// Module 'Lib' imports module 'XLogging', and 'XLogging' is aliased 'AppleLogging'. |
| 4 | + |
| 5 | +// RUN: %empty-directory(%t) |
| 6 | +// RUN: %{python} %utils/split_file.py -o %t %s |
| 7 | + |
| 8 | +/// Create AppleLogging.swiftmodule by aliasing XLogging |
| 9 | +// RUN: %target-swift-frontend -module-name AppleLogging -module-alias XLogging=AppleLogging %t/FileLogging.swift -emit-module -emit-module-path %t/AppleLogging.swiftmodule |
| 10 | +// RUN: test -f %t/AppleLogging.swiftmodule |
| 11 | + |
| 12 | +/// 1. Pass: load and reference a module with module aliasing |
| 13 | +/// Create module Lib that imports XLogging WITH -module-alias XLogging=AppleLogging |
| 14 | +// RUN: %target-swift-frontend -module-name LibA %t/FileLib.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/LibA.swiftmodule -Rmodule-loading 2> %t/result-LibA.output |
| 15 | +// RUN: test -f %t/LibA.swiftmodule |
| 16 | +// RUN: %FileCheck %s -input-file %t/result-LibA.output -check-prefix CHECK-LOAD |
| 17 | +// CHECK-LOAD: remark: loaded module at {{.*}}AppleLogging.swiftmodule |
| 18 | + |
| 19 | +/// 2. Fail: trying to access a non-member of a module (with module aliasing) should fail with the module alias in the diags |
| 20 | +/// Try building module Lib that imports XLogging WITH -module-alias XLogging=AppleLogging |
| 21 | +// RUN: not %target-swift-frontend -module-name LibB %t/FileLibNoSuchMember.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/LibB.swiftmodule 2> %t/result-LibB.output |
| 22 | +// RUN: %FileCheck %s -input-file %t/result-LibB.output -check-prefix CHECK-NO-MEMBER |
| 23 | +// CHECK-NO-MEMBER: error: module 'XLogging' has no member named 'setupErr' |
| 24 | + |
| 25 | +/// 3. Fail: importing the real module name that's being aliased should fail |
| 26 | +/// Create module Lib that imports XLogging WITH -module-alias XLogging=AppleLogging |
| 27 | +// RUN: not %target-swift-frontend -module-name LibC %t/FileLibImportRealName.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/LibC.swiftmodule 2> %t/result-LibC.output |
| 28 | +// RUN: %FileCheck %s -input-file %t/result-LibC.output -check-prefix CHECK-NOT-IMPORT |
| 29 | +// CHECK-NOT-IMPORT: error: cannot refer to module as 'AppleLogging' because it has been aliased; use 'XLogging' instead |
| 30 | + |
| 31 | +/// 4-1. Fail: referencing the real module name that's aliased should fail |
| 32 | +/// Create module Lib that imports XLogging WITH -module-alias XLogging=AppleLogging |
| 33 | +// RUN: not %target-swift-frontend -module-name LibD %t/FileLibRefRealName1.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/LibD.swiftmodule 2> %t/result-LibD.output |
| 34 | +// RUN: %FileCheck %s -input-file %t/result-LibD.output -check-prefix CHECK-NOT-REF1 |
| 35 | +// CHECK-NOT-REF1: error: cannot find 'AppleLogging' in scope |
| 36 | + |
| 37 | +/// 4-2. Fail: referencing the real module name that's aliased should fail |
| 38 | +/// Create module Lib that imports XLogging WITH -module-alias XLogging=AppleLogging |
| 39 | +// RUN: not %target-swift-frontend -module-name LibE %t/FileLibRefRealName2.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/LibE.swiftmodule 2> %t/result-LibE.output |
| 40 | +// RUN: %FileCheck %s -input-file %t/result-LibE.output -check-prefix CHECK-NOT-REF2 |
| 41 | +// CHECK-NOT-REF2: error: cannot find type 'AppleLogging' in scope |
| 42 | + |
| 43 | +/// 4-3. Fail: referencing the real module name that's aliased should fail |
| 44 | +/// Create module Lib that imports XLogging WITH -module-alias XLogging=AppleLogging |
| 45 | +// RUN: not %target-swift-frontend -module-name LibF %t/FileLibRefRealName3.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/LibF.swiftmodule 2> %t/result-LibF.output |
| 46 | +// RUN: %FileCheck %s -input-file %t/result-LibF.output -check-prefix CHECK-NOT-REF3 |
| 47 | +// CHECK-NOT-REF3: error: cannot find type 'AppleLogging' in scope |
| 48 | + |
| 49 | +/// 4-4. Fail: referencing the real module name that's aliased should fail |
| 50 | +/// Create module Lib that imports XLogging WITH -module-alias XLogging=AppleLogging |
| 51 | +// RUN: not %target-swift-frontend -module-name LibG %t/FileLibRefRealName4.swift -module-alias XLogging=AppleLogging -I %t -emit-module -emit-module-path %t/LibG.swiftmodule 2> %t/result-LibG.output |
| 52 | +// RUN: %FileCheck %s -input-file %t/result-LibG.output -check-prefix CHECK-NOT-REF4 |
| 53 | +// CHECK-NOT-REF4: error: cannot find type 'AppleLogging' in scope |
| 54 | + |
| 55 | + |
| 56 | +// BEGIN FileLogging.swift |
| 57 | +public protocol Loggable { |
| 58 | + var verbosity: Int { get } |
| 59 | +} |
| 60 | + |
| 61 | +public struct Logger { |
| 62 | + public init() {} |
| 63 | +} |
| 64 | + |
| 65 | +public func setup() -> XLogging.Logger? { |
| 66 | + return Logger() |
| 67 | +} |
| 68 | + |
| 69 | +// BEGIN FileLib.swift |
| 70 | +import XLogging |
| 71 | + |
| 72 | +public func start() { |
| 73 | + _ = XLogging.setup() |
| 74 | +} |
| 75 | + |
| 76 | +// BEGIN FileLibNoSuchMember.swift |
| 77 | +import XLogging |
| 78 | + |
| 79 | +public func start() { |
| 80 | + _ = XLogging.setupErr() |
| 81 | +} |
| 82 | + |
| 83 | +// BEGIN FileLibImportRealName.swift |
| 84 | +import XLogging |
| 85 | +import AppleLogging |
| 86 | + |
| 87 | +public func start() { |
| 88 | + _ = XLogging.setup() |
| 89 | +} |
| 90 | + |
| 91 | +// BEGIN FileLibRefRealName1.swift |
| 92 | +import XLogging |
| 93 | + |
| 94 | +public func start() { |
| 95 | + _ = AppleLogging.setup() |
| 96 | +} |
| 97 | + |
| 98 | +// BEGIN FileLibRefRealName2.swift |
| 99 | +import XLogging |
| 100 | + |
| 101 | +public struct MyStruct: AppleLogging.Loggable { |
| 102 | + public var verbosity: Int { |
| 103 | + return 3 |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +// BEGIN FileLibRefRealName3.swift |
| 108 | +import XLogging |
| 109 | + |
| 110 | +public struct MyStruct<T> where T: AppleLogging.Loggable { |
| 111 | + func log<T>(_ arg: T) { |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +// BEGIN FileLibRefRealName4.swift |
| 116 | +import XLogging |
| 117 | + |
| 118 | +public struct MyStruct { |
| 119 | + func log<T: AppleLogging.Loggable>(_ arg: T) { |
| 120 | + } |
| 121 | +} |
0 commit comments