Skip to content

Commit ea99df2

Browse files
Tests: cover testing multiple async executable targets (#6986)
Test [swiftlang/swift#69113: \[Concurrency\] Hide async_Main from other object files](swiftlang/swift#69113) Merge after the above fix will be merged ### Motivation: To verify that multiple executable targets with async entrypoints can be linked within a single test executable Resolves rdar://114231968 ### Modifications: Added a new test case
1 parent 3552b58 commit ea99df2

File tree

7 files changed

+106
-0
lines changed

7 files changed

+106
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// swift-tools-version: 5.5
2+
import PackageDescription
3+
4+
let package = Package(
5+
name: "TestableAsyncExe",
6+
targets: [
7+
.executableTarget(
8+
name: "TestableAsyncExe1"
9+
),
10+
.executableTarget(
11+
name: "TestableAsyncExe2"
12+
),
13+
.executableTarget(
14+
name: "TestableAsyncExe3"
15+
),
16+
.executableTarget(
17+
name: "TestableAsyncExe4"
18+
),
19+
.testTarget(
20+
name: "TestableAsyncExeTests",
21+
dependencies: [
22+
"TestableAsyncExe1",
23+
"TestableAsyncExe2",
24+
"TestableAsyncExe3",
25+
"TestableAsyncExe4",
26+
]
27+
),
28+
]
29+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public func GetAsyncGreeting1() async -> String {
2+
return "Hello, async world"
3+
}
4+
5+
await print("\(GetAsyncGreeting1())!")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public func GetAsyncGreeting2() async -> String {
2+
return "Hello, async planet"
3+
}
4+
5+
await print("\(GetAsyncGreeting2())!")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@main
2+
struct AsyncMain3 {
3+
static func main() async {
4+
print(await getGreeting3())
5+
}
6+
7+
static func getGreeting3() async -> String {
8+
return "Hello, async galaxy"
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@main
2+
struct AsyncMain4 {
3+
static func main() async {
4+
print(await getGreeting4())
5+
}
6+
7+
static func getGreeting4() async -> String {
8+
return "Hello, async universe"
9+
}
10+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import XCTest
2+
@testable import TestableAsyncExe1
3+
@testable import TestableAsyncExe2
4+
@testable import TestableAsyncExe3
5+
@testable import TestableAsyncExe4
6+
7+
final class TestableAsyncExeTests: XCTestCase {
8+
func testExample() async throws {
9+
let greeting1 = await GetAsyncGreeting1()
10+
print(greeting1)
11+
XCTAssertEqual(greeting1, "Hello, async world")
12+
13+
let greeting2 = await GetAsyncGreeting2()
14+
print(greeting2)
15+
XCTAssertEqual(greeting2, "Hello, async planet")
16+
17+
let greeting3 = await AsyncMain3.getGreeting3()
18+
print(greeting3)
19+
XCTAssertEqual(greeting3, "Hello, async galaxy")
20+
21+
let greeting4 = await AsyncMain4.getGreeting4()
22+
print(greeting4)
23+
XCTAssertEqual(greeting4, "Hello, async universe")
24+
}
25+
}

Tests/FunctionalTests/MiscellaneousTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,28 @@ class MiscellaneousTestCase: XCTestCase {
425425
}
426426
}
427427

428+
func testTestsCanLinkAgainstAsyncExecutable() throws {
429+
#if compiler(<5.10)
430+
try XCTSkipIf(true, "skipping because host compiler doesn't have a fix for symbol conflicts yet")
431+
#endif
432+
try fixture(name: "Miscellaneous/TestableAsyncExe") { fixturePath in
433+
let (stdout, stderr) = try executeSwiftTest(fixturePath)
434+
// in "swift test" build output goes to stderr
435+
XCTAssertMatch(stderr, .contains("Linking TestableAsyncExe1"))
436+
XCTAssertMatch(stderr, .contains("Linking TestableAsyncExe2"))
437+
XCTAssertMatch(stderr, .contains("Linking TestableAsyncExe3"))
438+
XCTAssertMatch(stderr, .contains("Linking TestableAsyncExe4"))
439+
XCTAssertMatch(stderr, .contains("Linking TestableAsyncExePackageTests"))
440+
XCTAssertMatch(stderr, .contains("Build complete!"))
441+
// in "swift test" test output goes to stdout
442+
XCTAssertMatch(stdout, .contains("Executed 1 test"))
443+
XCTAssertMatch(stdout, .contains("Hello, async world"))
444+
XCTAssertMatch(stdout, .contains("Hello, async planet"))
445+
XCTAssertMatch(stdout, .contains("Hello, async galaxy"))
446+
XCTAssertMatch(stdout, .contains("Hello, async universe"))
447+
}
448+
}
449+
428450
func testExecutableTargetMismatch() throws {
429451
try fixture(name: "Miscellaneous/TargetMismatch") { path in
430452
do {

0 commit comments

Comments
 (0)