diff --git a/Tests/JExtractSwiftTests/Asserts/TextAssertions.swift b/Tests/JExtractSwiftTests/Asserts/TextAssertions.swift index e975d2239..1f768fb2d 100644 --- a/Tests/JExtractSwiftTests/Asserts/TextAssertions.swift +++ b/Tests/JExtractSwiftTests/Asserts/TextAssertions.swift @@ -124,18 +124,49 @@ func assertOutput( continue } - for (no, (g, e)) in zip(gotLines.dropFirst(matchingOutputOffset), expectedLines).enumerated() { - if g.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).count == 0 - || e.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).count == 0 { - continue - } + var currentExpectedLine: Int = 0 + var currentGotLine: Int = matchingOutputOffset + + outer: while currentExpectedLine < expectedLines.count { + let expectedLine = expectedLines[currentExpectedLine].trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) - let ge = g.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) - let ee = e.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) - if ge.commonPrefix(with: ee) != ee { - diffLineNumbers.append(no + matchingOutputOffset) + if expectedLine == "..." { + // Ignore the rest of output, if last line is placeholder. + guard currentExpectedLine != (expectedLines.count - 1) else { + break + } - #expect(ge == ee, sourceLocation: sourceLocation) + let nextLine = expectedLines[currentExpectedLine + 1].trimmingCharacters(in: .whitespacesAndNewlines) + while currentGotLine < gotLines.count { + let gottenLine = gotLines[currentGotLine].trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) + if gottenLine.commonPrefix(with: nextLine) == nextLine { + currentExpectedLine += 2 + break + } else if nextLine == "..." { + // Skip any following "..." + currentExpectedLine += 1 + break + } else { + currentGotLine += 1 + } + + if currentGotLine == gotLines.count { + diffLineNumbers.append(currentExpectedLine + matchingOutputOffset + 1) + Issue.record("Expected to find '\(nextLine)' after wildcard, but end of file reached.", sourceLocation: sourceLocation) + break outer + } + } + + currentGotLine += 1 + } else { + let gottenLine = gotLines[currentGotLine].trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) + if gottenLine.commonPrefix(with: expectedLine) != expectedLine { + diffLineNumbers.append(currentExpectedLine + matchingOutputOffset) + + #expect(gottenLine == expectedLine, sourceLocation: sourceLocation) + } + currentGotLine += 1 + currentExpectedLine += 1 } } @@ -155,9 +186,17 @@ func assertOutput( print("==== ---------------------------------------------------------------") print("Got output:") let printFromLineNo = matchingOutputOffset - let printToLineNo = matchingOutputOffset + expectedLines.count - for (n, g) in gotLines.enumerated() where n >= printFromLineNo && n <= printToLineNo { - print("\(n): \(g)".red(if: diffLineNumbers.contains(n))) + for (n, g) in gotLines.enumerated() where n >= printFromLineNo { + let baseLine = "\(n): \(g)" + var line = baseLine + if diffLineNumbers.contains(n) { + line += "\n" + let leadingCount = "\(n): ".count + let message = "\(String(repeating: " ", count: leadingCount))\(String(repeating: "^", count: 8)) EXPECTED MATCH OR SEARCHING FROM HERE " + line += "\(message)\(String(repeating: "^", count: max(0, line.count - message.count)))" + line = line.red + } + print(line) } print("==== ---------------------------------------------------------------\n") } diff --git a/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift b/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift index 933e4f088..c9d313a50 100644 --- a/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift +++ b/Tests/JExtractSwiftTests/JNI/JNIVariablesTests.swift @@ -69,12 +69,7 @@ struct JNIVariablesTests { """ @_cdecl("Java_com_example_swift_MyClass__00024getConstant__J") func Java_com_example_swift_MyClass__00024getConstant__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jlong { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment!)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") - } + ... return self$.pointee.constant.getJNIValue(in: environment!) } """ @@ -134,11 +129,12 @@ struct JNIVariablesTests { @_cdecl("Java_com_example_swift_MyClass__00024getMutable__J") func Java_com_example_swift_MyClass__00024getMutable__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jlong { assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment!)) + ... let self$ = UnsafeMutablePointer(bitPattern: selfBits$) guard let self$ else { fatalError("self memory address was null in call to \\(#function)!") } + ... return self$.pointee.mutable.getJNIValue(in: environment!) } """, @@ -146,11 +142,7 @@ struct JNIVariablesTests { @_cdecl("Java_com_example_swift_MyClass__00024setMutable__JJ") func Java_com_example_swift_MyClass__00024setMutable__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, self: jlong) { assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment!)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") - } + ... self$.pointee.mutable = Int64(fromJNI: newValue, in: environment!) } """ @@ -195,12 +187,7 @@ struct JNIVariablesTests { """ @_cdecl("Java_com_example_swift_MyClass__00024getComputed__J") func Java_com_example_swift_MyClass__00024getComputed__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jlong { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment!)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") - } + ... return self$.pointee.computed.getJNIValue(in: environment!) } """, @@ -245,12 +232,7 @@ struct JNIVariablesTests { """ @_cdecl("Java_com_example_swift_MyClass__00024getComputedThrowing__J") func Java_com_example_swift_MyClass__00024getComputedThrowing__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jlong { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment!)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") - } + ... do { return try self$.pointee.computedThrowing.getJNIValue(in: environment!) } catch { @@ -314,24 +296,14 @@ struct JNIVariablesTests { """ @_cdecl("Java_com_example_swift_MyClass__00024getGetterAndSetter__J") func Java_com_example_swift_MyClass__00024getGetterAndSetter__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jlong { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment!)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") - } + ... return self$.pointee.getterAndSetter.getJNIValue(in: environment!) } """, """ @_cdecl("Java_com_example_swift_MyClass__00024setGetterAndSetter__JJ") func Java_com_example_swift_MyClass__00024setGetterAndSetter__JJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jlong, self: jlong) { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment!)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") - } + ... self$.pointee.getterAndSetter = Int64(fromJNI: newValue, in: environment!) } """ @@ -390,24 +362,14 @@ struct JNIVariablesTests { """ @_cdecl("Java_com_example_swift_MyClass__00024isSomeBoolean__J") func Java_com_example_swift_MyClass__00024isSomeBoolean__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jboolean { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment!)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") - } + ... return self$.pointee.someBoolean.getJNIValue(in: environment!) } """, """ @_cdecl("Java_com_example_swift_MyClass__00024setSomeBoolean__ZJ") func Java_com_example_swift_MyClass__00024setSomeBoolean__ZJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jboolean, self: jlong) { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment!)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") - } + ... self$.pointee.someBoolean = Bool(fromJNI: newValue, in: environment!) } """ @@ -466,24 +428,14 @@ struct JNIVariablesTests { """ @_cdecl("Java_com_example_swift_MyClass__00024isBoolean__J") func Java_com_example_swift_MyClass__00024isBoolean__J(environment: UnsafeMutablePointer!, thisClass: jclass, self: jlong) -> jboolean { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment!)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") - } + ... return self$.pointee.isBoolean.getJNIValue(in: environment!) } """, """ @_cdecl("Java_com_example_swift_MyClass__00024setBoolean__ZJ") func Java_com_example_swift_MyClass__00024setBoolean__ZJ(environment: UnsafeMutablePointer!, thisClass: jclass, newValue: jboolean, self: jlong) { - assert(self != 0, "self memory address was null") - let selfBits$ = Int(Int64(fromJNI: self, in: environment!)) - let self$ = UnsafeMutablePointer(bitPattern: selfBits$) - guard let self$ else { - fatalError("self memory address was null in call to \\(#function)!") - } + ... self$.pointee.isBoolean = Bool(fromJNI: newValue, in: environment!) } """