1515import JavaKit
1616import JavaKitNetwork
1717import 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
2821let 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