Skip to content

Commit cabc4e9

Browse files
authored
Add a test target to SwiftPM package. (#9557)
1 parent 3a55f32 commit cabc4e9

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

Package.swift

+20-1
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,24 @@ let package = Package(
8282
(value["libraries"] as? [String] ?? []).map { .linkedLibrary($0) }
8383
),
8484
]
85-
}
85+
} + [
86+
.testTarget(
87+
name: "tests",
88+
dependencies: [
89+
.target(name: "executorch_debug"),
90+
.target(name: "kernels_portable"),
91+
],
92+
path: "extension/apple/ExecuTorch/__tests__",
93+
resources: [
94+
.copy("resources/add.pte")
95+
],
96+
linkerSettings: [
97+
.linkedLibrary("c++"),
98+
.unsafeFlags([
99+
"-Xlinker", "-force_load",
100+
"-Xlinker", "cmake-out/kernels_portable.xcframework/macos-arm64/libkernels_portable_macos.a",
101+
])
102+
]
103+
)
104+
]
86105
)

extension/apple/ExecuTorch/__tests__/ModuleTest.swift

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,16 @@
1111
import XCTest
1212

1313
class ModuleTest: XCTestCase {
14+
var resourceBundle: Bundle {
15+
#if SWIFT_PACKAGE
16+
return Bundle.module
17+
#else
18+
return Bundle(for: type(of: self))
19+
#endif
20+
}
21+
1422
func test() throws {
15-
let bundle = Bundle(for: type(of: self))
16-
guard let modelPath = bundle.path(forResource: "add", ofType: "pte") else {
23+
guard let modelPath = resourceBundle.path(forResource: "add", ofType: "pte") else {
1724
XCTFail("Couldn't find the model file")
1825
return
1926
}

scripts/build_apple_frameworks.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ cmake_build() {
206206
cmake --build . \
207207
--config "$mode" \
208208
--verbose
209-
cd ..
209+
cd -
210210
}
211211

212212
for index in ${!PLATFORMS[*]}; do
@@ -285,4 +285,9 @@ done
285285

286286
rm -rf "$HEADERS_PATH"
287287

288+
echo "Running tests"
289+
290+
cd "$SOURCE_ROOT_DIR"
291+
swift test
292+
288293
echo "Build succeeded!"

0 commit comments

Comments
 (0)