diff --git a/Tests/JExtractSwiftTests/VariableImportTests.swift b/Tests/JExtractSwiftTests/VariableImportTests.swift index 2f58c5c8..f59b8ff4 100644 --- a/Tests/JExtractSwiftTests/VariableImportTests.swift +++ b/Tests/JExtractSwiftTests/VariableImportTests.swift @@ -41,7 +41,7 @@ final class VariableImportTests { ) st.log.logLevel = .error - try st.analyze(swiftInterfacePath: "/fake/Fake.swiftinterface", text: class_interfaceFile) + try await st.analyze(swiftInterfacePath: "/fake/Fake.swiftinterface", text: class_interfaceFile) let identifier = "counterInt" let varDecl: ImportedVariable? = @@ -59,6 +59,7 @@ final class VariableImportTests { } assertOutput( + dump: true, output, expected: """ diff --git a/Tests/JavaKitTests/BasicRuntimeTests.swift b/Tests/JavaKitTests/BasicRuntimeTests.swift index e8e9ac82..33f795b9 100644 --- a/Tests/JavaKitTests/BasicRuntimeTests.swift +++ b/Tests/JavaKitTests/BasicRuntimeTests.swift @@ -15,30 +15,25 @@ import JavaKit import JavaKitNetwork import JavaKitVM -import Testing -import Foundation - -#if os(Linux) -import Glibc -#else -import Darwin -#endif +import XCTest // NOTE: Workaround for https://github.com/swiftlang/swift-java/issues/43 @MainActor let jvm = try! JavaVirtualMachine(vmOptions: []) -@Suite @MainActor -struct BasicRuntimeTests { - @Test("Object management", .disabled(if: isMacOSTerminal || isLinux, "JVM creation fails occasionally in terminal on macOS, and some issues on Linux")) - func javaObjectManagement() throws { +class BasicRuntimeTests: XCTestCase { + func testJavaObjectManagement() async throws { + if isLinux { + throw XCTSkip("Attempts to refcount a null pointer on Linux") + } + let sneakyJavaThis: jobject do { let object = JavaObject(environment: jvm.environment) - #expect(object.toString().starts(with: "java.lang.Object")) + XCTAssert(object.toString().starts(with: "java.lang.Object")) // Make sure this object was promoted to a global reference. - #expect(object.javaEnvironment.pointee?.pointee.GetObjectRefType(object.javaEnvironment, object.javaThis) == JNIGlobalRefType) + XCTAssertEqual(object.javaEnvironment.pointee?.pointee.GetObjectRefType(object.javaEnvironment, object.javaThis), JNIGlobalRefType) // Keep track of the Java object. sneakyJavaThis = object.javaThis @@ -46,37 +41,42 @@ struct BasicRuntimeTests { // The reference should now be invalid, because we've deleted the // global reference. - #expect(jvm.environment.pointee?.pointee.GetObjectRefType(jvm.environment, sneakyJavaThis) == JNIInvalidRefType) + XCTAssertEqual(jvm.environment.pointee?.pointee.GetObjectRefType(jvm.environment, sneakyJavaThis), JNIInvalidRefType) // 'super' and 'as' don't require allocating a new holder. let url = try URL("http://swift.org", environment: jvm.environment) let superURL = url.super - #expect(url.javaHolder === superURL.javaHolder) + XCTAssert(url.javaHolder === superURL.javaHolder) let urlAgain = superURL.as(URL.self)! - #expect(url.javaHolder === urlAgain.javaHolder) + XCTAssert(url.javaHolder === urlAgain.javaHolder) } - @Test("Java exceptions", .disabled(if: isMacOSTerminal || isLinux, "JVM creation fails occasionally in terminal on macOS, and some issues on Linux")) - func javaExceptionsInSwift() throws { + func testJavaExceptionsInSwift() async throws { + if isLinux { + throw XCTSkip("Attempts to refcount a null pointer on Linux") + } + do { _ = try URL("bad url", environment: jvm.environment) } catch { - #expect(String(describing: error) == "no protocol: bad url") + XCTAssert(String(describing: error) == "no protocol: bad url") } } - @Test("Static methods", .disabled(if: isMacOSTerminal || isLinux, "JVM creation fails occasionally in terminal on macOS, and some issues on Linux")) - func staticMethods() throws { + func testStaticMethods() async throws { + if isLinux { + throw XCTSkip("Attempts to refcount a null pointer on Linux") + } + let urlConnectionClass = try JavaClass(in: jvm.environment) - #expect(urlConnectionClass.getDefaultAllowUserInteraction() == false) + XCTAssert(urlConnectionClass.getDefaultAllowUserInteraction() == false) } - @Test("Class instance lookup", .disabled(if: isMacOSTerminal || isLinux, "JVM creation fails occasionally in terminal on macOS, and some issues on Linux")) - func classInstanceLookup() throws { + func testClassInstanceLookup() async throws { do { _ = try JavaClass(in: jvm.environment) } catch { - #expect(String(describing: error) == "org/swift/javakit/Nonexistent") + XCTAssertEqual(String(describing: error), "org/swift/javakit/Nonexistent") } } } @@ -92,20 +92,3 @@ var isLinux: Bool { return false #endif } - -/// Whether we're running on MacOS in an interactive terminal session. -var isMacOSTerminal: Bool { - isMacOS && ( - isatty(STDOUT_FILENO) == 1 || - ProcessInfo.processInfo.environment["IS_TTY"] != nil // since 'swift test' still sometimes hides the fact we're in tty - ) -} - -/// Whether we're running on MacOS. -var isMacOS: Bool { - #if os(macOS) - return true - #else - return false - #endif -}