File tree 5 files changed +47
-5
lines changed
Fixtures/MixedTargets/BasicMixedTargets
Sources/MixedTargetWithPublicCXXAPI
Tests/MixedTargetWithPublicCXXAPITests 5 files changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -102,8 +102,10 @@ let package = Package(
102
102
// In order to import this target into downstream targets, two
103
103
// additional things must be done (depending on whether the target is
104
104
// 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.
107
109
// - Swift context: The mixed target needs to make a custom module
108
110
// map that only exposes public CXX headers in a non-Swift context.
109
111
//
Original file line number Diff line number Diff line change 1
1
import Foundation
2
2
3
+ @objc public class Factorial : NSObject {
4
+ @objc public static func text( ) -> String {
5
+ return " Hello, World! "
6
+ }
7
+ }
8
+
3
9
public func factorial( _ x: Int32 ) -> Int {
4
10
return ObjcCalculator . factorial ( for: x)
5
11
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change 2
2
3
3
@import MixedTargetWithPublicCXXAPI;
4
4
5
- @interface ObjcMixedTargetWithPublicCXXAPITests : XCTestCase
5
+ @interface ObjcMixedTargetWithPublicCXXAPIViaModuleImportTests : XCTestCase
6
6
@end
7
7
8
- @implementation ObjcMixedTargetWithPublicCXXAPITests
8
+ @implementation ObjcMixedTargetWithPublicCXXAPIViaModuleImportTests
9
9
10
10
- (void )testPublicObjcAPI {
11
11
XCTAssertEqual ([ObjcCalculator factorialForInt: 5 ], 120 );
12
12
XCTAssertEqual ([ObjcCalculator sumX: 1 andY: 2 ], 3 );
13
13
}
14
14
15
+ - (void )testPublicSwiftAPI {
16
+ XCTAssertEqualObjects ([Factorial text ], @" Hello, World!" );
17
+ }
18
+
15
19
- (void )testPublicCXXAPI {
16
20
CXXSumFinder sf;
17
21
XCTAssertEqual (sf.sum (1 ,2 ), 3 );
Original file line number Diff line number Diff line change @@ -150,7 +150,11 @@ final class MixedTargetTests: XCTestCase {
150
150
try fixture ( name: " MixedTargets/BasicMixedTargets " ) { fixturePath in
151
151
XCTAssertBuilds (
152
152
fixturePath,
153
- extraArgs: [ " --target " , " MixedTargetWithPublicCXXAPITests " ]
153
+ extraArgs: [ " --target " , " MixedTargetWithPublicCXXAPI " ]
154
+ )
155
+ XCTAssertSwiftTest (
156
+ fixturePath,
157
+ extraArgs: [ " --filter " , " MixedTargetWithPublicCXXAPITests " ]
154
158
)
155
159
}
156
160
}
You can’t perform that action at this time.
0 commit comments