From 6f6c3500d995dc90d296a15230e66ffbb742f674 Mon Sep 17 00:00:00 2001 From: Konrad `ktoso` Malawski Date: Thu, 10 Oct 2024 18:24:42 +0900 Subject: [PATCH 1/2] Skipping the JVM tests on macOS terminal since unreliable (crashes in JVM create) --- .../VariableImportTests.swift | 3 +-- Tests/JavaKitTests/BasicRuntimeTests.swift | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Tests/JExtractSwiftTests/VariableImportTests.swift b/Tests/JExtractSwiftTests/VariableImportTests.swift index f59b8ff4..2f58c5c8 100644 --- a/Tests/JExtractSwiftTests/VariableImportTests.swift +++ b/Tests/JExtractSwiftTests/VariableImportTests.swift @@ -41,7 +41,7 @@ final class VariableImportTests { ) st.log.logLevel = .error - try await st.analyze(swiftInterfacePath: "/fake/Fake.swiftinterface", text: class_interfaceFile) + try st.analyze(swiftInterfacePath: "/fake/Fake.swiftinterface", text: class_interfaceFile) let identifier = "counterInt" let varDecl: ImportedVariable? = @@ -59,7 +59,6 @@ final class VariableImportTests { } assertOutput( - dump: true, output, expected: """ diff --git a/Tests/JavaKitTests/BasicRuntimeTests.swift b/Tests/JavaKitTests/BasicRuntimeTests.swift index 2e47b84f..ff368fbd 100644 --- a/Tests/JavaKitTests/BasicRuntimeTests.swift +++ b/Tests/JavaKitTests/BasicRuntimeTests.swift @@ -17,13 +17,19 @@ import JavaKitNetwork import JavaKitVM import Testing +#if os(Linux) +import Glibc +#else +import Darwin +#endif + @MainActor let jvm = try! JavaVirtualMachine(vmOptions: []) @Suite @MainActor struct BasicRuntimeTests { - @Test("Object management", .disabled(if: isLinux, "Attempts to refcount a null pointer on Linux")) + @Test("Object management", .disabled(if: isMacOSTerminal || isLinux, "JVM creation fails occasionally in terminal on macOS, and some issues on Linux")) func javaObjectManagement() throws { let sneakyJavaThis: jobject do { @@ -49,7 +55,7 @@ struct BasicRuntimeTests { #expect(url.javaHolder === urlAgain.javaHolder) } - @Test("Java exceptions", .disabled(if: isLinux, "Attempts to refcount a null pointer on Linux")) + @Test("Java exceptions", .disabled(if: isMacOSTerminal || isLinux, "JVM creation fails occasionally in terminal on macOS, and some issues on Linux")) func javaExceptionsInSwift() throws { do { _ = try URL("bad url", environment: jvm.environment) @@ -58,13 +64,13 @@ struct BasicRuntimeTests { } } - @Test("Static methods", .disabled(if: isMacOS, "Fails on macOS command line")) + @Test("Static methods", .disabled(if: isMacOSTerminal || isLinux, "JVM creation fails occasionally in terminal on macOS, and some issues on Linux")) func staticMethods() throws { let urlConnectionClass = try JavaClass(in: jvm.environment) #expect(urlConnectionClass.getDefaultAllowUserInteraction() == false) } - @Test("Class instance lookup") + @Test("Class instance lookup", .disabled(if: isMacOSTerminal || isLinux, "JVM creation fails occasionally in terminal on macOS, and some issues on Linux")) func classInstanceLookup() throws { do { _ = try JavaClass(in: jvm.environment) @@ -86,6 +92,11 @@ var isLinux: Bool { #endif } +/// Whether we're running on MacOS in an interactive terminal session. +var isMacOSTerminal: Bool { + isMacOS && isatty(STDOUT_FILENO) == 1 +} + /// Whether we're running on MacOS. var isMacOS: Bool { #if os(macOS) From c70f3d2b2468e48ff7386b92fd638214909f33f3 Mon Sep 17 00:00:00 2001 From: Konrad `ktoso` Malawski Date: Thu, 10 Oct 2024 18:39:23 +0900 Subject: [PATCH 2/2] additional env var to force saying we're in tty --- Tests/JavaKitTests/BasicRuntimeTests.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/JavaKitTests/BasicRuntimeTests.swift b/Tests/JavaKitTests/BasicRuntimeTests.swift index ff368fbd..e8e9ac82 100644 --- a/Tests/JavaKitTests/BasicRuntimeTests.swift +++ b/Tests/JavaKitTests/BasicRuntimeTests.swift @@ -16,6 +16,7 @@ import JavaKit import JavaKitNetwork import JavaKitVM import Testing +import Foundation #if os(Linux) import Glibc @@ -94,7 +95,10 @@ var isLinux: Bool { /// Whether we're running on MacOS in an interactive terminal session. var isMacOSTerminal: Bool { - isMacOS && isatty(STDOUT_FILENO) == 1 + 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.