Skip to content

Commit 41770f7

Browse files
committed
Add additional CXX tests
1 parent 58288bd commit 41770f7

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

Fixtures/MixedTargets/BasicMixedTargets/Package.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ let package = Package(
102102
// In order to import this target into downstream targets, two
103103
// additional things must be done (depending on whether the target is
104104
// being imported into a Clang vs. Swift context):
105-
// - Clang context: The downstream target must pass `-fcxx-modules`
106-
// and `-fmodules` as unsafe flags in the target's `cSettings`.
105+
// - Clang context: If the client wants to import the module, client
106+
// must pass `-fcxx-modules` and `-fmodules` as unsafe flags in
107+
// the target's `cSettings`. Else, the client can just import
108+
// individual public headers without further configuring the target.
107109
// - Swift context: The mixed target needs to make a custom module
108110
// map that only exposes public CXX headers in a non-Swift context.
109111
//
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import Foundation
22

3+
@objc public class Factorial: NSObject {
4+
@objc public static func text() -> String {
5+
return "Hello, World!"
6+
}
7+
}
8+
39
public func factorial(_ x: Int32) -> Int {
410
return ObjcCalculator.factorial(for: x)
511
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#import <XCTest/XCTest.h>
2+
3+
#import "CXXSumFinder.hpp"
4+
#import "ObjcCalculator.h"
5+
#import "MixedTargetWithPublicCXXAPI-Swift.h"
6+
7+
@interface ObjcMixedTargetWithPublicCXXAPIViaModuleImportTests : XCTestCase
8+
@end
9+
10+
@implementation ObjcMixedTargetWithPublicCXXAPIViaModuleImportTests
11+
12+
- (void)testPublicObjcAPI {
13+
XCTAssertEqual([ObjcCalculator factorialForInt:5], 120);
14+
XCTAssertEqual([ObjcCalculator sumX:1 andY:2], 3);
15+
}
16+
17+
- (void)testPublicSwiftAPI {
18+
XCTAssertEqualObjects([Factorial text], @"Hello, World!");
19+
}
20+
21+
- (void)testPublicCXXAPI {
22+
CXXSumFinder sf;
23+
XCTAssertEqual(sf.sum(1,2), 3);
24+
}
25+
26+
@end
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@
22

33
@import MixedTargetWithPublicCXXAPI;
44

5-
@interface ObjcMixedTargetWithPublicCXXAPITests : XCTestCase
5+
@interface ObjcMixedTargetWithPublicCXXAPIViaModuleImportTests : XCTestCase
66
@end
77

8-
@implementation ObjcMixedTargetWithPublicCXXAPITests
8+
@implementation ObjcMixedTargetWithPublicCXXAPIViaModuleImportTests
99

1010
- (void)testPublicObjcAPI {
1111
XCTAssertEqual([ObjcCalculator factorialForInt:5], 120);
1212
XCTAssertEqual([ObjcCalculator sumX:1 andY:2], 3);
1313
}
1414

15+
- (void)testPublicSwiftAPI {
16+
XCTAssertEqualObjects([Factorial text], @"Hello, World!");
17+
}
18+
1519
- (void)testPublicCXXAPI {
1620
CXXSumFinder sf;
1721
XCTAssertEqual(sf.sum(1,2), 3);

Tests/FunctionalTests/MixedTargetTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ final class MixedTargetTests: XCTestCase {
150150
try fixture(name: "MixedTargets/BasicMixedTargets") { fixturePath in
151151
XCTAssertBuilds(
152152
fixturePath,
153-
extraArgs: ["--target", "MixedTargetWithPublicCXXAPITests"]
153+
extraArgs: ["--target", "MixedTargetWithPublicCXXAPI"]
154+
)
155+
XCTAssertSwiftTest(
156+
fixturePath,
157+
extraArgs: ["--filter", "MixedTargetWithPublicCXXAPITests"]
154158
)
155159
}
156160
}

0 commit comments

Comments
 (0)