Skip to content

Commit 307c08c

Browse files
committed
Add tests with chained dependency scenarios with module aliasing
1 parent 0cad63e commit 307c08c

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/// Test the -module-alias flag on a sample scenario:
2+
/// Module 'Utils' imports module 'Logging'.
3+
/// 'Logging' needs to be aliased due to a name collision, so is renamed 'AppleLogging'.
4+
5+
// RUN: %empty-directory(%t)
6+
7+
/// Logging has a source file that has a reference to its module name Logging
8+
// RUN: echo 'public struct Logger { }' > %t/FileLog.swift
9+
// RUN: echo 'public func setup() -> Logging.Logger? { return nil }' >> %t/FileLog.swift
10+
11+
/// Create AppleLogging.swiftmodule by aliasing Logging via -module-alias Logging=AppleLogging
12+
// RUN: %target-swift-frontend -module-name AppleLogging -module-alias Logging=AppleLogging %t/FileLog.swift -emit-module -emit-module-path %t/AppleLogging.swiftmodule
13+
14+
/// Check AppleLogging.swiftmodule is created
15+
// RUN: test -f %t/AppleLogging.swiftmodule
16+
// RUN: not test -f %t/Logging.swiftmodule
17+
18+
/// Create a module Utils that imports Logging with -module-alias Logging=AppleLogging
19+
// RUN: echo 'import Logging' > %t/FileUtils.swift
20+
// RUN: echo 'public func start() { Logging.setup() }' >> %t/FileUtils.swift
21+
// RUN: %target-swift-frontend -module-name Utils %t/FileUtils.swift -module-alias Logging=AppleLogging -I %t -emit-module -emit-module-path %t/Utils.swiftmodule -Rmodule-loading 2> %t/load-result.output
22+
23+
/// Check Utils.swiftmodule is created and AppleLogging.swiftmodule is loaded
24+
// RUN: test -f %t/Utils.swiftmodule
25+
// RUN: test -f %t/AppleLogging.swiftmodule
26+
// RUN: not test -f %t/Logging.swiftmodule
27+
28+
// RUN: %FileCheck %s -input-file %t/load-result.output -check-prefix CHECK-LOAD
29+
// CHECK-LOAD: remark: loaded module at {{.*}}AppleLogging.swiftmodule
30+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/// Test the -module-alias flag on the following scenario:
2+
/// Module 'Utils' imports module 'Logging', and module 'UserN' imports both 'Utils' and 'Logging'.
3+
/// 'Logging' needs to be aliased due to a name collision, so is renamed 'AppleLogging'.
4+
5+
// RUN: %empty-directory(%t)
6+
7+
/// Input file with a reference to its enclosing module called Logging
8+
// RUN: echo 'public struct Logger { }' > %t/FileLog.swift
9+
// RUN: echo 'public func setup() -> Logging.Logger? { return nil }' >> %t/FileLog.swift
10+
11+
/// Create AppleLogging.swiftmodule by aliasing Logging via -module-alias Logging=AppleLogging
12+
// RUN: %target-swift-frontend -module-name AppleLogging -module-alias Logging=AppleLogging %t/FileLog.swift -emit-module -emit-module-path %t/AppleLogging.swiftmodule
13+
14+
/// Check AppleLogging.swiftmodule is created
15+
// RUN: test -f %t/AppleLogging.swiftmodule
16+
// RUN: not test -f %t/Logging.swiftmodule
17+
18+
/// Create a module Utils that imports Logging with -module-alias Logging=AppleLogging
19+
// RUN: echo 'import Logging' > %t/FileUtils.swift
20+
// RUN: echo 'public func start() { Logging.setup() }' >> %t/FileUtils.swift
21+
// RUN: %target-swift-frontend -module-name Utils %t/FileUtils.swift -module-alias Logging=AppleLogging -I %t -emit-module -emit-module-path %t/Utils.swiftmodule -Rmodule-loading 2> %t/result-Utils.output
22+
23+
/// Check Utils.swiftmodule is created and AppleLogging.swiftmodule is loaded
24+
// RUN: test -f %t/Utils.swiftmodule
25+
// RUN: test -f %t/AppleLogging.swiftmodule
26+
// RUN: not test -f %t/Logging.swiftmodule
27+
28+
// RUN: %FileCheck %s -input-file %t/result-Utils.output -check-prefix CHECK-UTILS
29+
// CHECK-UTILS: remark: loaded module at {{.*}}AppleLogging.swiftmodule
30+
31+
/// Create a module User1 that imports both Utils and Logging, with module aliasing for Logging
32+
// RUN: echo 'import Logging' > %t/File.swift
33+
// RUN: echo 'import Utils' >> %t/File.swift
34+
// RUN: echo 'public func run() { Utils.start() }' >> %t/File.swift
35+
// RUN: %target-swift-frontend -module-name User1 %t/File.swift -module-alias Logging=AppleLogging -I %t -emit-module -emit-module-path %t/User1.swiftmodule -Rmodule-loading 2> %t/result-User1.output
36+
37+
/// Check User1.swiftmodule is created and Utils.swiftmodule and AppleLogging.swiftmodule are loaded
38+
// RUN: test -f %t/User1.swiftmodule
39+
// RUN: test -f %t/Utils.swiftmodule
40+
// RUN: test -f %t/AppleLogging.swiftmodule
41+
// RUN: not test -f %t/Logging.swiftmodule
42+
43+
// RUN: %FileCheck %s -input-file %t/result-User1.output -check-prefix CHECK-1
44+
// CHECK-1: remark: loaded module at {{.*}}AppleLogging.swiftmodule
45+
// CHECK-1: remark: loaded module at {{.*}}Utils.swiftmodule
46+
47+
/// Try creating a module User2 that imports both Utils and Logging, without module aliasing
48+
// RUN: not %target-swift-frontend -module-name User2 %t/File.swift -I %t -emit-module -emit-module-path %t/User2.swiftmodule 2> %t/result-User2.output
49+
50+
/// Check that it fails
51+
// RUN: %FileCheck %s -input-file %t/result-User2.output -check-prefix CHECK-2
52+
// CHECK-2: {{.*}}error: no such module 'Logging'
53+
54+
/// Try creating a module User3 that imports both Utils and AppleLogging, without module aliasing
55+
// RUN: echo 'import AppleLogging' > %t/AnotherFile.swift
56+
// RUN: echo 'import Utils' >> %t/AnotherFile.swift
57+
// RUN: echo 'public func run() { _ = AppleLogging.setup() }' >> %t/AnotherFile.swift
58+
// RUN: not %target-swift-frontend -module-name User3 %t/AnotherFile.swift -I %t -emit-module -emit-module-path %t/User3.swiftmodule 2> %t/result-User3.output
59+
60+
/// Check that it fails
61+
// RUN: %FileCheck %s -input-file %t/result-User3.output -check-prefix CHECK-3
62+
// CHECK-3: {{.*}}error: missing required module 'Logging'
63+
64+
/// Try creating a module User4 that imports both Utils and AppleLogging, with module aliasing for Logging
65+
// RUN: %target-swift-frontend -module-name User4 -module-alias Logging=AppleLogging %t/AnotherFile.swift -I %t -emit-module -emit-module-path %t/User4.swiftmodule -Rmodule-loading 2> %t/result-User4.output
66+
67+
/// Check that it fails
68+
// RUN: %FileCheck %s -input-file %t/result-User4.output -check-prefix CHECK-4
69+
// CHECK-4: remark: loaded module at {{.*}}AppleLogging.swiftmodule
70+
// CHECK-4: remark: loaded module at {{.*}}Utils.swiftmodule

0 commit comments

Comments
 (0)