Skip to content

Commit 123cc3f

Browse files
Implemented coverage for skipping empty imported file entries by adding multifile fixtures and a new BridgeJS codegen snapshot test to assert only non-empty import data is emitted (Plugins/BridgeJS/Tests/BridgeJSToolTests/Inputs/MacroSwift/Multifile/ImportedFunctions.swift, .../ExportedOnly.swift, BridgeJSCodegenTests.swift). Generated corresponding snapshots (__Snapshots__/BridgeJSCodegenTests/CrossFileSkipsEmptyImportedFiles.{json,swift}).
Tests: - `UPDATE_SNAPSHOTS=1 swift test --package-path ./Plugins/BridgeJS --filter BridgeJSCodegenTests/codegenSkipsEmptyImportedFiles` - `swift test --package-path ./Plugins/BridgeJS` If you want full runtime coverage, next run `make unittest SWIFT_SDK_ID=DEVELOPMENT-SNAPSHOT-2025-11-03-a-wasm32-unknown-wasip1`.
1 parent 19a1da7 commit 123cc3f

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

Plugins/BridgeJS/Tests/BridgeJSToolTests/BridgeJSCodegenTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,21 @@ import Testing
166166
let skeleton = try swiftAPI.finalize()
167167
try snapshotCodegen(skeleton: skeleton, name: "CrossFileFunctionTypes.ReverseOrder")
168168
}
169+
170+
@Test
171+
func codegenSkipsEmptyImportedFiles() throws {
172+
let swiftAPI = SwiftToSkeleton(progress: .silent, moduleName: "TestModule", exposeToGlobal: false)
173+
let importedURL = Self.multifileInputsDirectory.appendingPathComponent("ImportedFunctions.swift")
174+
swiftAPI.addSourceFile(
175+
Parser.parse(source: try String(contentsOf: importedURL, encoding: .utf8)),
176+
inputFilePath: "ImportedFunctions.swift"
177+
)
178+
let exportedOnlyURL = Self.multifileInputsDirectory.appendingPathComponent("ExportedOnly.swift")
179+
swiftAPI.addSourceFile(
180+
Parser.parse(source: try String(contentsOf: exportedOnlyURL, encoding: .utf8)),
181+
inputFilePath: "ExportedOnly.swift"
182+
)
183+
let skeleton = try swiftAPI.finalize()
184+
try snapshotCodegen(skeleton: skeleton, name: "CrossFileSkipsEmptyImportedFiles")
185+
}
169186
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
struct ExportedOnly {
2+
let value: Int = 0
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@JSFunction func fetchNumber() throws(JSException) -> Int
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"exported" : {
3+
"classes" : [
4+
5+
],
6+
"enums" : [
7+
8+
],
9+
"exposeToGlobal" : false,
10+
"functions" : [
11+
12+
],
13+
"protocols" : [
14+
15+
],
16+
"structs" : [
17+
18+
]
19+
},
20+
"imported" : {
21+
"children" : [
22+
{
23+
"functions" : [
24+
{
25+
"name" : "fetchNumber",
26+
"parameters" : [
27+
28+
],
29+
"returnType" : {
30+
"int" : {
31+
32+
}
33+
}
34+
}
35+
],
36+
"types" : [
37+
38+
]
39+
}
40+
]
41+
},
42+
"moduleName" : "TestModule"
43+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#if arch(wasm32)
2+
@_extern(wasm, module: "TestModule", name: "bjs_fetchNumber")
3+
fileprivate func bjs_fetchNumber() -> Int32
4+
#else
5+
fileprivate func bjs_fetchNumber() -> Int32 {
6+
fatalError("Only available on WebAssembly")
7+
}
8+
#endif
9+
10+
func _$fetchNumber() throws(JSException) -> Int {
11+
let ret = bjs_fetchNumber()
12+
if let error = _swift_js_take_exception() {
13+
throw error
14+
}
15+
return Int.bridgeJSLiftReturn(ret)
16+
}

0 commit comments

Comments
 (0)