Skip to content

Commit c561af5

Browse files
authored
Merge pull request #64 from DougGregor/workaround-jdk-macos-terminal-issue
Temporarily switch JavaKitTests target to XCTest
2 parents 1102157 + 6d4c9f1 commit c561af5

File tree

2 files changed

+28
-44
lines changed

2 files changed

+28
-44
lines changed

Tests/JExtractSwiftTests/VariableImportTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class VariableImportTests {
4141
)
4242
st.log.logLevel = .error
4343

44-
try st.analyze(swiftInterfacePath: "/fake/Fake.swiftinterface", text: class_interfaceFile)
44+
try await st.analyze(swiftInterfacePath: "/fake/Fake.swiftinterface", text: class_interfaceFile)
4545

4646
let identifier = "counterInt"
4747
let varDecl: ImportedVariable? =
@@ -59,6 +59,7 @@ final class VariableImportTests {
5959
}
6060

6161
assertOutput(
62+
dump: true,
6263
output,
6364
expected:
6465
"""

Tests/JavaKitTests/BasicRuntimeTests.swift

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,68 +15,68 @@
1515
import JavaKit
1616
import JavaKitNetwork
1717
import JavaKitVM
18-
import Testing
19-
import Foundation
20-
21-
#if os(Linux)
22-
import Glibc
23-
#else
24-
import Darwin
25-
#endif
18+
import XCTest // NOTE: Workaround for https://github.com/swiftlang/swift-java/issues/43
2619

2720
@MainActor
2821
let jvm = try! JavaVirtualMachine(vmOptions: [])
2922

30-
@Suite
3123
@MainActor
32-
struct BasicRuntimeTests {
33-
@Test("Object management", .disabled(if: isMacOSTerminal || isLinux, "JVM creation fails occasionally in terminal on macOS, and some issues on Linux"))
34-
func javaObjectManagement() throws {
24+
class BasicRuntimeTests: XCTestCase {
25+
func testJavaObjectManagement() async throws {
26+
if isLinux {
27+
throw XCTSkip("Attempts to refcount a null pointer on Linux")
28+
}
29+
3530
let sneakyJavaThis: jobject
3631
do {
3732
let object = JavaObject(environment: jvm.environment)
38-
#expect(object.toString().starts(with: "java.lang.Object"))
33+
XCTAssert(object.toString().starts(with: "java.lang.Object"))
3934

4035
// Make sure this object was promoted to a global reference.
41-
#expect(object.javaEnvironment.pointee?.pointee.GetObjectRefType(object.javaEnvironment, object.javaThis) == JNIGlobalRefType)
36+
XCTAssertEqual(object.javaEnvironment.pointee?.pointee.GetObjectRefType(object.javaEnvironment, object.javaThis), JNIGlobalRefType)
4237

4338
// Keep track of the Java object.
4439
sneakyJavaThis = object.javaThis
4540
}
4641

4742
// The reference should now be invalid, because we've deleted the
4843
// global reference.
49-
#expect(jvm.environment.pointee?.pointee.GetObjectRefType(jvm.environment, sneakyJavaThis) == JNIInvalidRefType)
44+
XCTAssertEqual(jvm.environment.pointee?.pointee.GetObjectRefType(jvm.environment, sneakyJavaThis), JNIInvalidRefType)
5045

5146
// 'super' and 'as' don't require allocating a new holder.
5247
let url = try URL("http://swift.org", environment: jvm.environment)
5348
let superURL = url.super
54-
#expect(url.javaHolder === superURL.javaHolder)
49+
XCTAssert(url.javaHolder === superURL.javaHolder)
5550
let urlAgain = superURL.as(URL.self)!
56-
#expect(url.javaHolder === urlAgain.javaHolder)
51+
XCTAssert(url.javaHolder === urlAgain.javaHolder)
5752
}
5853

59-
@Test("Java exceptions", .disabled(if: isMacOSTerminal || isLinux, "JVM creation fails occasionally in terminal on macOS, and some issues on Linux"))
60-
func javaExceptionsInSwift() throws {
54+
func testJavaExceptionsInSwift() async throws {
55+
if isLinux {
56+
throw XCTSkip("Attempts to refcount a null pointer on Linux")
57+
}
58+
6159
do {
6260
_ = try URL("bad url", environment: jvm.environment)
6361
} catch {
64-
#expect(String(describing: error) == "no protocol: bad url")
62+
XCTAssert(String(describing: error) == "no protocol: bad url")
6563
}
6664
}
6765

68-
@Test("Static methods", .disabled(if: isMacOSTerminal || isLinux, "JVM creation fails occasionally in terminal on macOS, and some issues on Linux"))
69-
func staticMethods() throws {
66+
func testStaticMethods() async throws {
67+
if isLinux {
68+
throw XCTSkip("Attempts to refcount a null pointer on Linux")
69+
}
70+
7071
let urlConnectionClass = try JavaClass<URLConnection>(in: jvm.environment)
71-
#expect(urlConnectionClass.getDefaultAllowUserInteraction() == false)
72+
XCTAssert(urlConnectionClass.getDefaultAllowUserInteraction() == false)
7273
}
7374

74-
@Test("Class instance lookup", .disabled(if: isMacOSTerminal || isLinux, "JVM creation fails occasionally in terminal on macOS, and some issues on Linux"))
75-
func classInstanceLookup() throws {
75+
func testClassInstanceLookup() async throws {
7676
do {
7777
_ = try JavaClass<Nonexistent>(in: jvm.environment)
7878
} catch {
79-
#expect(String(describing: error) == "org/swift/javakit/Nonexistent")
79+
XCTAssertEqual(String(describing: error), "org/swift/javakit/Nonexistent")
8080
}
8181
}
8282
}
@@ -92,20 +92,3 @@ var isLinux: Bool {
9292
return false
9393
#endif
9494
}
95-
96-
/// Whether we're running on MacOS in an interactive terminal session.
97-
var isMacOSTerminal: Bool {
98-
isMacOS && (
99-
isatty(STDOUT_FILENO) == 1 ||
100-
ProcessInfo.processInfo.environment["IS_TTY"] != nil // since 'swift test' still sometimes hides the fact we're in tty
101-
)
102-
}
103-
104-
/// Whether we're running on MacOS.
105-
var isMacOS: Bool {
106-
#if os(macOS)
107-
return true
108-
#else
109-
return false
110-
#endif
111-
}

0 commit comments

Comments
 (0)