Skip to content

Commit 1face1f

Browse files
committed
Move SwiftJavaToolTests/JavaRepositoryTests to SwiftJavaToolLibTests/JavaResolverTests
1 parent 8fe1360 commit 1face1f

File tree

5 files changed

+35
-43
lines changed

5 files changed

+35
-43
lines changed

Package.swift

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -462,20 +462,6 @@ let package = Package(
462462
]
463463
),
464464

465-
.testTarget(
466-
name: "SwiftJavaToolTests",
467-
dependencies: [
468-
"SwiftJavaTool",
469-
],
470-
exclude: [
471-
"SimpleJavaProject",
472-
],
473-
swiftSettings: [
474-
.swiftLanguageMode(.v5),
475-
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])
476-
]
477-
),
478-
479465
.testTarget(
480466
name: "JavaTypesTests",
481467
dependencies: [
@@ -502,6 +488,9 @@ let package = Package(
502488
dependencies: [
503489
"SwiftJavaToolLib"
504490
],
491+
exclude: [
492+
"SimpleJavaProject",
493+
],
505494
swiftSettings: [
506495
.swiftLanguageMode(.v5),
507496
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"])

Tests/SwiftJavaToolTests/JavaRepositoryTests.swift renamed to Tests/SwiftJavaToolLibTests/JavaResolverTests.swift

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
import Foundation
1616
@testable import SwiftJavaConfigurationShared
17-
@testable import SwiftJavaTool // test in terminal with sandbox disabled, if xcode can't find the module
17+
@testable import SwiftJavaToolLib
1818
import Testing
1919

2020
@Suite(.serialized)
21-
class JavaRepositoryTests {
21+
class JavaResolverTests {
2222
static let localRepo: String = String.localRepoRootDirectory.appending("/All")
2323

2424
static let localJarRepo: String = String.localRepoRootDirectory.appending("/JarOnly")
@@ -39,16 +39,16 @@ class JavaRepositoryTests {
3939
#if compiler(>=6.2)
4040
@Test
4141
func nonResolvableDependency() async throws {
42-
try await #expect(processExitsWith: .failure, "commonCSVWithUnknownDependencies") {
42+
await #expect(processExitsWith: .failure, "commonCSVWithUnknownDependencies") {
4343
try await resolve(configuration: .commonCSVWithUnknownDependencies)
4444
}
45-
try await #expect(processExitsWith: .failure, "helloWorldInLocalRepoIncludeIOOnly") {
45+
await #expect(processExitsWith: .failure, "helloWorldInLocalRepoIncludeIOOnly") {
4646
try await resolve(configuration: .helloWorldInLocalRepoIncludeIOOnly)
4747
}
48-
try await #expect(processExitsWith: .failure, "androidCoreInCentral") {
48+
await #expect(processExitsWith: .failure, "androidCoreInCentral") {
4949
try await resolve(configuration: .androidCoreInCentral)
5050
}
51-
try await #expect(processExitsWith: .failure, "helloWorldInRepoWithoutArtifact") {
51+
await #expect(processExitsWith: .failure, "helloWorldInRepoWithoutArtifact") {
5252
try await resolve(configuration: .helloWorldInRepoWithoutArtifact)
5353
}
5454
}
@@ -90,18 +90,16 @@ class JavaRepositoryTests {
9090
// Wired issue with #require, marking the function as static seems to resolve it
9191
private func resolve(configuration: SwiftJavaConfigurationShared.Configuration) async throws {
9292
var config = configuration
93-
var command = try SwiftJava.ResolveCommand.parse([
94-
"--output-directory",
95-
".build/\(configuration.swiftModule!)/destination/SwiftJavaPlugin",
96-
97-
"--swift-module",
98-
configuration.swiftModule!,
99-
])
10093
try config.publishSampleJavaProjectIfNeeded()
101-
try await command.runSwiftJavaCommand(config: &config)
94+
try await JavaResolver.runResolveCommand(
95+
config: &config,
96+
input: nil,
97+
swiftModule: configuration.swiftModule!,
98+
outputDirectory: ".build/\(configuration.swiftModule!)/destination/SwiftJavaPlugin"
99+
)
102100
}
103101

104-
extension SwiftJavaConfigurationShared.Configuration {
102+
extension SwiftJavaConfigurationShared.Configuration: @unchecked Sendable {
105103
static var resolvableConfigurations: [Configuration] = [
106104
.commonCSV, .jitpackJson,
107105
.helloWorldInTempRepo,
@@ -140,7 +138,7 @@ extension SwiftJavaConfigurationShared.Configuration {
140138
]
141139
configuration.packageToPublish = "SimpleJavaProject"
142140

143-
configuration.repositories = [.maven(url: JavaRepositoryTests.localRepo)]
141+
configuration.repositories = [.maven(url: JavaResolverTests.localRepo)]
144142
return configuration
145143
}()
146144

@@ -156,8 +154,8 @@ extension SwiftJavaConfigurationShared.Configuration {
156154
static let helloWorldInRepoWithCustomArtifacts: Configuration = {
157155
var configuration = Configuration.helloWorldInTempRepo
158156
configuration.repositories = [
159-
.maven(url: JavaRepositoryTests.localPomRepo, artifactUrls: [
160-
JavaRepositoryTests.localJarRepo,
157+
.maven(url: JavaResolverTests.localPomRepo, artifactUrls: [
158+
JavaResolverTests.localJarRepo,
161159
]),
162160
]
163161
return configuration
@@ -207,8 +205,8 @@ extension SwiftJavaConfigurationShared.Configuration {
207205
var configuration = Configuration.helloWorldInTempRepo
208206

209207
configuration.repositories = [
210-
.maven(url: JavaRepositoryTests.localJarRepo /* , artifactUrls: [
211-
JavaRepositoryTests.localPomRepo
208+
.maven(url: JavaResolverTests.localJarRepo /* , artifactUrls: [
209+
JavaResolverTests.localPomRepo
212210
] */ ),
213211
]
214212
return configuration
@@ -230,10 +228,17 @@ private extension SwiftJavaConfigurationShared.Configuration {
230228
return
231229
}
232230

231+
var gradlewPath = String.packageDirectory + "/gradlew"
232+
if !FileManager.default.fileExists(atPath: gradlewPath) {
233+
let currentWorkingDir = URL(filePath: .packageDirectory).appendingPathComponent(".build", isDirectory: true)
234+
try JavaResolver.copyGradlew(to: currentWorkingDir)
235+
gradlewPath = currentWorkingDir.appendingPathComponent("gradlew").path
236+
}
233237
let process = Process()
234-
process.executableURL = URL(fileURLWithPath: .gradlewPath)
238+
process.executableURL = URL(fileURLWithPath: gradlewPath)
239+
let packagePath = URL(fileURLWithPath: #file).deletingLastPathComponent().appendingPathComponent(packageName).path
235240
process.arguments = [
236-
"-p", "\(String.packageDirectory)/Tests/SwiftJavaToolTests/\(packageName)",
241+
"-p", "\(packagePath)",
237242
"publishAllArtifacts",
238243
"publishToMavenLocal", // also publish to maven local to test includeGroups"
239244
"-q",
@@ -261,16 +266,14 @@ private extension String {
261266
defer { free(path) }
262267

263268
let dir = String(cString: path)
264-
// TODO: This needs to be tested in Xcode as well, for now Xcode can't run tests, due to this issue: https://github.com/swiftlang/swift-java/issues/281
265-
precondition(dir.hasSuffix("swift-java"), "Please run the tests from the swift-java directory")
266-
return dir
269+
if dir.hasSuffix("swift-java") { // most likely running with `swift test`
270+
return dir
271+
} else {
272+
return FileManager.default.temporaryDirectory.path
273+
}
267274
}
268275

269276
static var localRepoRootDirectory: Self {
270277
packageDirectory + "/.build/SwiftJavaToolTests/LocalRepo"
271278
}
272-
273-
static var gradlewPath: Self {
274-
packageDirectory + "/gradlew"
275-
}
276279
}

0 commit comments

Comments
 (0)