Skip to content

Commit f40df96

Browse files
committed
refactor(carthage): Make a test use resolveSingleProject()
Reuse this function to align with other tests. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent f4bfeee commit f40df96

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

plugins/package-managers/carthage/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ dependencies {
3838

3939
funTestImplementation(testFixtures(projects.analyzer))
4040

41+
testImplementation(testFixtures(projects.analyzer))
42+
4143
testImplementation(libs.mockk)
4244
}

plugins/package-managers/carthage/src/test/kotlin/CarthageTest.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919

2020
package org.ossreviewtoolkit.plugins.packagemanagers.carthage
2121

22-
import io.kotest.assertions.throwables.shouldThrow
2322
import io.kotest.core.spec.style.WordSpec
2423
import io.kotest.core.test.TestCase
2524
import io.kotest.engine.test.TestResult
25+
import io.kotest.matchers.collections.beEmpty
26+
import io.kotest.matchers.collections.shouldBeSingleton
27+
import io.kotest.matchers.should
2628
import io.kotest.matchers.shouldBe
29+
import io.kotest.matchers.string.shouldContain
2730

2831
import io.mockk.every
2932
import io.mockk.mockkStatic
@@ -32,9 +35,8 @@ import io.mockk.unmockkAll
3235
import java.io.File
3336
import java.net.URI
3437

38+
import org.ossreviewtoolkit.analyzer.resolveSingleProject
3539
import org.ossreviewtoolkit.model.VcsType
36-
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
37-
import org.ossreviewtoolkit.model.config.Excludes
3840

3941
class CarthageTest : WordSpec() {
4042
private val carthage = CarthageFactory.create()
@@ -48,7 +50,7 @@ class CarthageTest : WordSpec() {
4850
"parse a github dependency" {
4951
val cartfile = File("src/test/assets/Cartfile-github.resolved")
5052

51-
val result = carthage.resolveDependencies(cartfile).single()
53+
val result = carthage.resolveSingleProject(cartfile)
5254

5355
with(result.packages) {
5456
size shouldBe 1
@@ -63,7 +65,7 @@ class CarthageTest : WordSpec() {
6365
"parse a generic git dependency" {
6466
val cartfile = File("src/test/assets/Cartfile-generic-git.resolved")
6567

66-
val result = carthage.resolveDependencies(cartfile).single()
68+
val result = carthage.resolveSingleProject(cartfile)
6769

6870
with(result.packages) {
6971
size shouldBe 1
@@ -83,7 +85,7 @@ class CarthageTest : WordSpec() {
8385

8486
val cartfile = File("src/test/assets/Cartfile-binary.resolved")
8587

86-
val result = carthage.resolveDependencies(cartfile).single()
88+
val result = carthage.resolveSingleProject(cartfile)
8789
with(result.packages) {
8890
size shouldBe 1
8991
single().apply {
@@ -101,7 +103,7 @@ class CarthageTest : WordSpec() {
101103

102104
val cartfile = File("src/test/assets/Cartfile-mixed.resolved")
103105

104-
val result = carthage.resolveDependencies(cartfile).single()
106+
val result = carthage.resolveSingleProject(cartfile)
105107

106108
with(result.packages) {
107109
size shouldBe 3
@@ -118,13 +120,13 @@ class CarthageTest : WordSpec() {
118120
"throw an error for a wrongly defined dependency" {
119121
val cartfile = File("src/test/assets/Cartfile-faulty.resolved")
120122

121-
shouldThrow<IllegalArgumentException> {
122-
carthage.resolveDependencies(cartfile)
123+
val result = carthage.resolveSingleProject(cartfile)
124+
125+
result.packages should beEmpty()
126+
result.issues.shouldBeSingleton {
127+
it.message shouldContain "IllegalArgumentException"
123128
}
124129
}
125130
}
126131
}
127132
}
128-
129-
private fun Carthage.resolveDependencies(definitionFile: File) =
130-
resolveDependencies(definitionFile.parentFile, definitionFile, Excludes.EMPTY, AnalyzerConfiguration(), emptyMap())

0 commit comments

Comments
 (0)