Skip to content

Commit e7c0635

Browse files
committed
fix: test harness would incorrectly match less than "detect" size chunks
1 parent 49e95c6 commit e7c0635

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

Sources/JExtractSwiftLib/FFM/FFMSwift2JavaGenerator+SwiftThunkPrinting.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ extension FFMSwift2JavaGenerator {
131131
}
132132
printer.print("import \(module)")
133133
}
134+
printer.println()
134135
}
135136
}
136137

Tests/JExtractSwiftTests/Asserts/TextAssertions.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func assertOutput(
2828
_ mode: JExtractGenerationMode,
2929
_ renderKind: RenderKind,
3030
swiftModuleName: String = "SwiftModule",
31-
detectChunkByInitialLines: Int = 4,
31+
detectChunkByInitialLines _detectChunkByInitialLines: Int = 4,
3232
expectedChunks: [String],
3333
fileID: String = #fileID,
3434
filePath: String = #filePath,
@@ -79,19 +79,22 @@ func assertOutput(
7979
let gotLines = output.split(separator: "\n").filter { l in
8080
l.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).count > 0
8181
}
82-
for expected in expectedChunks {
83-
let expectedLines = expected.split(separator: "\n")
82+
for expectedChunk in expectedChunks {
83+
let expectedLines = expectedChunk.split(separator: "\n")
84+
let detectChunkByInitialLines = min(expectedLines.count, _detectChunkByInitialLines)
85+
precondition(detectChunkByInitialLines > 0, "Chunk size to detect cannot be zero lines!")
8486

8587
var matchingOutputOffset: Int? = nil
8688
let expectedInitialMatchingLines = expectedLines[0..<min(expectedLines.count, detectChunkByInitialLines)]
8789
.map({$0.trimmingCharacters(in: .whitespacesAndNewlines)})
8890
.joined(separator: "\n")
89-
for offset in 0..<gotLines.count where gotLines.count > (offset+detectChunkByInitialLines) {
90-
let textLinesAtOffset = gotLines[offset..<offset+detectChunkByInitialLines]
91+
92+
for lineOffset in 0..<gotLines.count where gotLines.count > (lineOffset+detectChunkByInitialLines) {
93+
let textLinesAtOffset = gotLines[lineOffset..<lineOffset+detectChunkByInitialLines]
9194
.map({$0.trimmingCharacters(in: .whitespacesAndNewlines)})
9295
.joined(separator: "\n")
9396
if textLinesAtOffset == expectedInitialMatchingLines {
94-
matchingOutputOffset = offset
97+
matchingOutputOffset = lineOffset
9598
break
9699
}
97100
}
@@ -105,13 +108,13 @@ func assertOutput(
105108

106109
print("==== ---------------------------------------------------------------")
107110
print("Expected output:")
108-
print(expected.yellow)
111+
print("'\(expectedChunk.yellow)'")
109112
print("==== ---------------------------------------------------------------")
110113
print("Got output:")
111114
print(output)
112115
print("==== ---------------------------------------------------------------")
113116

114-
#expect(output.contains(expected), sourceLocation: sourceLocation)
117+
#expect(output.contains(expectedChunk), sourceLocation: sourceLocation)
115118
fatalError("Failed: \(filePath):\(line)")
116119
continue
117120
}

Tests/JExtractSwiftTests/DataImportTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ final class DataImportTests {
402402

403403
// Just to make sure 'Data' is imported.
404404
"""
405-
public final class Data
405+
public final class Data extends FFMSwiftInstance implements SwiftValue {
406406
"""
407407
]
408408
)

Tests/JExtractSwiftTests/OptionalImportTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ final class OptionalImportTests {
4747
private static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);
4848
public static void call(java.lang.foreign.MemorySegment arg) {
4949
try {
50-
if (SwiftRuntime.TRACE_DOWNCALLS) {
51-
SwiftRuntime.traceDowncall(arg);
50+
if (CallTraces.TRACE_DOWNCALLS) {
51+
CallTraces.traceDowncall(arg);
5252
}
5353
HANDLE.invokeExact(arg);
5454
} catch (Throwable ex$) {
@@ -87,8 +87,8 @@ final class OptionalImportTests {
8787
private static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);
8888
public static void call(java.lang.foreign.MemorySegment arg) {
8989
try {
90-
if (SwiftRuntime.TRACE_DOWNCALLS) {
91-
SwiftRuntime.traceDowncall(arg);
90+
if (CallTraces.TRACE_DOWNCALLS) {
91+
CallTraces.traceDowncall(arg);
9292
}
9393
HANDLE.invokeExact(arg);
9494
} catch (Throwable ex$) {
@@ -128,8 +128,8 @@ final class OptionalImportTests {
128128
private static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);
129129
public static void call(java.lang.foreign.MemorySegment arg) {
130130
try {
131-
if (SwiftRuntime.TRACE_DOWNCALLS) {
132-
SwiftRuntime.traceDowncall(arg);
131+
if (CallTraces.TRACE_DOWNCALLS) {
132+
CallTraces.traceDowncall(arg);
133133
}
134134
HANDLE.invokeExact(arg);
135135
} catch (Throwable ex$) {

0 commit comments

Comments
 (0)