Skip to content

Commit c69e5cb

Browse files
committed
[Tests] Add static keypaths tests.
1 parent c5ebf4e commit c69e5cb

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// RUN: %empty-directory(%t/src)
2+
// RUN: split-file %s %t/src
3+
4+
/// Build LibA
5+
// RUN: %host-build-swift %t/src/LibA.swift -swift-version 5 -emit-module -emit-library -enable-library-evolution -module-name LibA -o %t/%target-library-name(LibA) -emit-module-interface-path %t/LibA.swiftinterface
6+
7+
// Build LibB
8+
// RUN: %target-build-swift %t/src/LibB.swift -I %t -L %t -l LibA -swift-version 5 -emit-module -emit-library -module-name LibB -o %t/%target-library-name(LibB)
9+
10+
// Build LibC
11+
// RUN: %target-build-swift %t/src/LibC.swift -I %t -L %t -l LibA -swift-version 5 -emit-module -emit-library -module-name LibC -o %t/%target-library-name(LibC)
12+
13+
// Build & run main.swift
14+
// RUN: %target-build-swift -I %t -L %t -l LibA -l LibB -l LibC %t/src/main.swift -o %t/a.out
15+
// RUN: %target-codesign %t/%target-library-name(LibA)
16+
// RUN: %target-codesign %t/%target-library-name(LibB)
17+
// RUN: %target-codesign %t/%target-library-name(LibC)
18+
// RUN: %target-codesign %t/a.out
19+
// RUN: %target-run %t/a.out | %FileCheck %s
20+
21+
// REQUIRES: executable_test
22+
// REQUIRES: OS=macosx
23+
// REQUIRES: asserts
24+
25+
// UNSUPPORTED: use_os_stdlib
26+
// UNSUPPORTED: back_deployment_runtime
27+
28+
//--- LibA.swift
29+
public struct AStruct {
30+
public static var property1: Int = 1
31+
public static var property2: Int = 2
32+
private(set) public static var property3: Int = 1
33+
private(set) public static var property4: Int = 4
34+
}
35+
36+
//--- LibB.swift
37+
import LibA
38+
39+
public let keyPath1FromLibB = \AStruct.Type.property1
40+
public let keyPath2FromLibB = \AStruct.Type.property2
41+
public let keyPath3FromLibB = \AStruct.Type.property3
42+
public let keyPath4FromLibB = \AStruct.Type.property4
43+
public var keyPath5FromLibB = \AStruct.Type.property1 // WritableKeyPath with public setter
44+
45+
//--- LibC.swift
46+
import LibA
47+
48+
public let keyPath1FromLibC = \AStruct.Type.property1
49+
public let keyPath2FromLibC = \AStruct.Type.property2
50+
public let keyPath3FromLibC = \AStruct.Type.property3 // Read-only with private setter
51+
public let keyPath4FromLibC = \AStruct.Type.property4
52+
53+
//--- main.swift
54+
import LibB
55+
import LibC
56+
57+
// CHECK: true
58+
print(keyPath1FromLibB == keyPath1FromLibC)
59+
// CHECK: true
60+
print(keyPath1FromLibB != keyPath2FromLibC)
61+
62+
// CHECK: true
63+
print(keyPath3FromLibB == keyPath3FromLibC)
64+
// CHECK: true
65+
print(keyPath3FromLibB != keyPath4FromLibC)
66+
67+
// CHECK: false
68+
print(keyPath5FromLibB == keyPath3FromLibC)

0 commit comments

Comments
 (0)