Skip to content

Commit 2e747fb

Browse files
committed
[Tests] Add static keypaths tests.
1 parent eab59cc commit 2e747fb

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

build.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
MODE=$1
2+
TEST=$2
3+
4+
pushd ../build/${MODE}/swift-macosx-arm64
5+
xcrun ninja -j 8 swift-frontend
6+
#xcrun ninja -j 8 swift-refactor
7+
#xcrun ninja swift-demangle
8+
#xcrun ninja swift-serialize-diagnostics
9+
#xcrun ninja sil-opt
10+
#xcrun ninja swift-ide-test
11+
#xcrun ninja sourcekitd-test
12+
#xcrun ninja stdlib
13+
#xcrun ninja swift-remoteast
14+
popd
15+
python3 ../llvm-project/llvm/utils/lit/lit.py -sv --param swift_site_config=../build/${MODE}/swift-macosx-arm64/test-macosx-x86_64/lit.site.cfg ${TEST}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
24+
//--- LibA.swift
25+
public struct AStruct {
26+
public static var property1: Int = 1
27+
public static var property2: Int = 2
28+
private(set) public static var property3: Int = 1
29+
private(set) public static var property4: Int = 4
30+
}
31+
32+
//--- LibB.swift
33+
import LibA
34+
35+
public let keyPath1FromLibB = \AStruct.Type.property1
36+
public let keyPath2FromLibB = \AStruct.Type.property2
37+
public let keyPath3FromLibB = \AStruct.Type.property3
38+
public let keyPath4FromLibB = \AStruct.Type.property4
39+
public var keyPath5FromLibB = \AStruct.Type.property1 // WritableKeyPath with public setter
40+
41+
//--- LibC.swift
42+
import LibA
43+
44+
public let keyPath1FromLibC = \AStruct.Type.property1
45+
public let keyPath2FromLibC = \AStruct.Type.property2
46+
public let keyPath3FromLibC = \AStruct.Type.property3 // Read-only with private setter
47+
public let keyPath4FromLibC = \AStruct.Type.property4
48+
49+
//--- main.swift
50+
import LibB
51+
import LibC
52+
53+
// CHECK: true
54+
print(keyPath1FromLibB == keyPath1FromLibC)
55+
// CHECK: true
56+
print(keyPath1FromLibB != keyPath2FromLibC)
57+
58+
// CHECK: true
59+
print(keyPath3FromLibB == keyPath3FromLibC)
60+
// CHECK: true
61+
print(keyPath3FromLibB != keyPath4FromLibC)
62+
63+
// CHECK: false
64+
print(keyPath5FromLibB == keyPath3FromLibC)

0 commit comments

Comments
 (0)