diff --git a/analyzer/src/funTest/kotlin/BabelTest.kt b/analyzer/src/funTest/kotlin/BabelTest.kt index 432637973f0a5..b947eb04be909 100644 --- a/analyzer/src/funTest/kotlin/BabelTest.kt +++ b/analyzer/src/funTest/kotlin/BabelTest.kt @@ -32,6 +32,7 @@ import com.here.ort.utils.test.patchExpectedResult import io.kotlintest.TestCase import io.kotlintest.TestResult +import io.kotlintest.matchers.maps.shouldContainKey import io.kotlintest.shouldBe import io.kotlintest.specs.WordSpec @@ -60,16 +61,20 @@ class BabelTest : WordSpec() { init { "Babel dependencies" should { "be correctly analyzed" { - val packageFile = File(projectDir, "package.json") + val definitionFile = File(projectDir, "package.json") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "${projectDir.name}-expected-output.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val actualResult = createNPM().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] - patchActualResult(yamlMapper.writeValueAsString(actualResult)) shouldBe expectedResult + val result = createNPM().resolveDependencies(USER_DIR, listOf(definitionFile)) + + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + patchActualResult(yamlMapper.writeValueAsString(resultForDefinitionFile)) shouldBe expectedResult + } } } } diff --git a/analyzer/src/funTest/kotlin/BowerTest.kt b/analyzer/src/funTest/kotlin/BowerTest.kt index f172bc839bdaa..2a63702619903 100644 --- a/analyzer/src/funTest/kotlin/BowerTest.kt +++ b/analyzer/src/funTest/kotlin/BowerTest.kt @@ -29,9 +29,9 @@ import com.here.ort.utils.test.USER_DIR import com.here.ort.utils.test.patchExpectedResult import io.kotlintest.matchers.beEmpty +import io.kotlintest.matchers.maps.shouldContainKey import io.kotlintest.should import io.kotlintest.shouldBe -import io.kotlintest.shouldNotBe import io.kotlintest.specs.StringSpec import java.io.File @@ -44,7 +44,7 @@ class BowerTest : StringSpec() { init { "Project dependencies are detected correctly" { - val packageFile = File(projectDir, "bower.json") + val definitionFile = File(projectDir, "bower.json") val vcsPath = vcsDir.getPathToRoot(projectDir) val expectedResult = patchExpectedResult(File(projectDir.parentFile, "bower-expected-output.yml"), definitionFilePath = "$vcsPath/bower.json", @@ -52,11 +52,13 @@ class BowerTest : StringSpec() { revision = vcsRevision, url = normalizeVcsUrl(vcsUrl)) - val result = createBower().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createBower().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors should beEmpty() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors should beEmpty() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } } diff --git a/analyzer/src/funTest/kotlin/BundlerTest.kt b/analyzer/src/funTest/kotlin/BundlerTest.kt index d34945ff3ae86..dda11f03a679b 100644 --- a/analyzer/src/funTest/kotlin/BundlerTest.kt +++ b/analyzer/src/funTest/kotlin/BundlerTest.kt @@ -30,8 +30,8 @@ import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION import com.here.ort.utils.test.USER_DIR import com.here.ort.utils.test.patchExpectedResult +import io.kotlintest.matchers.maps.shouldContainKey import io.kotlintest.shouldBe -import io.kotlintest.shouldNotBe import io.kotlintest.matchers.startWith import io.kotlintest.specs.WordSpec @@ -66,16 +66,19 @@ class BundlerTest : WordSpec() { "show error if no lockfile is present" { val definitionFile = File(projectsDir, "no-lockfile/Gemfile") - val actualResult = createBundler().resolveDependencies(USER_DIR, listOf(definitionFile))[definitionFile] + val result = createBundler().resolveDependencies(USER_DIR, listOf(definitionFile)) - actualResult shouldNotBe null - actualResult!!.project.id shouldBe - Identifier("Bundler::src/funTest/assets/projects/synthetic/bundler/no-lockfile/Gemfile:") - actualResult.project.definitionFilePath shouldBe - "analyzer/src/funTest/assets/projects/synthetic/bundler/no-lockfile/Gemfile" - actualResult.packages.size shouldBe 0 - actualResult.errors.size shouldBe 1 - actualResult.errors.first().message should startWith("IllegalArgumentException: No lockfile found in") + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.project.id shouldBe + Identifier("Bundler::src/funTest/assets/projects/synthetic/bundler/no-lockfile/Gemfile:") + resultForDefinitionFile.project.definitionFilePath shouldBe + "analyzer/src/funTest/assets/projects/synthetic/bundler/no-lockfile/Gemfile" + resultForDefinitionFile.packages.size shouldBe 0 + resultForDefinitionFile.errors.size shouldBe 1 + resultForDefinitionFile.errors.first().message should + startWith("IllegalArgumentException: No lockfile found in") + } } "resolve dependencies correctly when the project is a Gem" { diff --git a/analyzer/src/funTest/kotlin/GoDepTest.kt b/analyzer/src/funTest/kotlin/GoDepTest.kt index d381fe6e42f3f..c88a95159d8bb 100644 --- a/analyzer/src/funTest/kotlin/GoDepTest.kt +++ b/analyzer/src/funTest/kotlin/GoDepTest.kt @@ -21,8 +21,6 @@ package com.here.ort.analyzer import com.here.ort.analyzer.managers.GoDep import com.here.ort.downloader.VersionControlSystem -import com.here.ort.model.Identifier -import com.here.ort.model.Project import com.here.ort.model.VcsInfo import com.here.ort.model.config.AnalyzerConfiguration import com.here.ort.model.yamlMapper @@ -30,62 +28,75 @@ import com.here.ort.utils.test.DEFAULT_ANALYZER_CONFIGURATION import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION import com.here.ort.utils.test.USER_DIR +import io.kotlintest.matchers.maps.shouldContainKey import io.kotlintest.matchers.startWith import io.kotlintest.shouldBe -import io.kotlintest.shouldNotBe import io.kotlintest.specs.WordSpec import java.io.File class GoDepTest : WordSpec() { private val projectsDir = File("src/funTest/assets/projects") + private val vcsDir = VersionControlSystem.forDirectory(projectsDir)!! + private val vcsRevision = vcsDir.getRevision() init { "GoDep" should { "resolve dependencies from a lockfile correctly" { - val manifestFile = File(projectsDir, "external/qmstr/Gopkg.toml") - val result = createGoDep().resolveDependencies(USER_DIR, listOf(manifestFile))[manifestFile] + val definitionFile = File(projectsDir, "external/qmstr/Gopkg.toml") + val result = createGoDep().resolveDependencies(USER_DIR, listOf(definitionFile))[definitionFile] val expectedResult = File(projectsDir, "external/qmstr-expected-output.yml").readText() yamlMapper.writeValueAsString(result) shouldBe expectedResult } "show error if no lockfile is present" { - val manifestFile = File(projectsDir, "synthetic/godep/no-lockfile/Gopkg.toml") - val result = createGoDep().resolveDependencies(USER_DIR, listOf(manifestFile))[manifestFile] - - result shouldNotBe null - result!!.project.id shouldBe - Identifier("GoDep::src/funTest/assets/projects/synthetic/godep/no-lockfile/Gopkg.toml:") - result.project.definitionFilePath shouldBe - "analyzer/src/funTest/assets/projects/synthetic/godep/no-lockfile/Gopkg.toml" - result.packages.size shouldBe 0 - result.errors.size shouldBe 1 - result.errors.first().message should startWith("IllegalArgumentException: No lockfile found in") + val definitionFile = File(projectsDir, "synthetic/godep/no-lockfile/Gopkg.toml") + val result = createGoDep().resolveDependencies(USER_DIR, listOf(definitionFile)) + + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + // Note: These fall-back coordinates actually are generated by the PackageManager base class if an + // exception is thrown. + resultForDefinitionFile.project.id.toCoordinates() shouldBe + "GoDep::src/funTest/assets/projects/synthetic/godep/no-lockfile/Gopkg.toml:" + + resultForDefinitionFile.project.definitionFilePath shouldBe + "analyzer/src/funTest/assets/projects/synthetic/godep/no-lockfile/Gopkg.toml" + resultForDefinitionFile.packages.size shouldBe 0 + resultForDefinitionFile.errors.size shouldBe 1 + resultForDefinitionFile.errors.first().message should + startWith("IllegalArgumentException: No lockfile found in") + } } "invoke the dependency solver if no lockfile is present and allowDynamicVersions is set" { - val manifestFile = File(projectsDir, "synthetic/godep/no-lockfile/Gopkg.toml") + val definitionFile = File(projectsDir, "synthetic/godep/no-lockfile/Gopkg.toml") val config = AnalyzerConfiguration(false, true) - val result = createGoDep(config).resolveDependencies(USER_DIR, listOf(manifestFile))[manifestFile] - - result shouldNotBe null - result!!.project shouldNotBe Project.EMPTY - result.packages.size shouldBe 4 - result.errors.size shouldBe 0 + val result = createGoDep(config).resolveDependencies(USER_DIR, listOf(definitionFile)) + + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.project.id.toCoordinates() shouldBe + "GoDep::no-lockfile:$vcsRevision" + resultForDefinitionFile.project.definitionFilePath shouldBe + "analyzer/src/funTest/assets/projects/synthetic/godep/no-lockfile/Gopkg.toml" + resultForDefinitionFile.packages.size shouldBe 4 + resultForDefinitionFile.errors.size shouldBe 0 + } } "import dependencies from Glide" { - val manifestFile = File(projectsDir, "external/sprig/glide.yaml") - val result = createGoDep().resolveDependencies(USER_DIR, listOf(manifestFile))[manifestFile] + val definitionFile = File(projectsDir, "external/sprig/glide.yaml") + val result = createGoDep().resolveDependencies(USER_DIR, listOf(definitionFile))[definitionFile] val expectedResult = File(projectsDir, "external/sprig-expected-output.yml").readText() yamlMapper.writeValueAsString(result) shouldBe expectedResult } "import dependencies from godeps" { - val manifestFile = File(projectsDir, "external/godep/Godeps/Godeps.json") - val result = createGoDep().resolveDependencies(USER_DIR, listOf(manifestFile))[manifestFile] + val definitionFile = File(projectsDir, "external/godep/Godeps/Godeps.json") + val result = createGoDep().resolveDependencies(USER_DIR, listOf(definitionFile))[definitionFile] val expectedResult = File(projectsDir, "external/godep-expected-output.yml").readText() yamlMapper.writeValueAsString(result) shouldBe expectedResult diff --git a/analyzer/src/funTest/kotlin/GradleAndroidTest.kt b/analyzer/src/funTest/kotlin/GradleAndroidTest.kt index 71a11454ee4da..8ac77fea7ba6f 100644 --- a/analyzer/src/funTest/kotlin/GradleAndroidTest.kt +++ b/analyzer/src/funTest/kotlin/GradleAndroidTest.kt @@ -29,8 +29,8 @@ import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION import com.here.ort.utils.test.patchExpectedResult import com.here.ort.utils.test.USER_DIR +import io.kotlintest.matchers.maps.shouldContainKey import io.kotlintest.shouldBe -import io.kotlintest.shouldNotBe import io.kotlintest.specs.StringSpec import java.io.File @@ -43,48 +43,54 @@ class GradleAndroidTest : StringSpec() { init { "Root project dependencies are detected correctly".config(tags = setOf(AndroidTag)) { - val packageFile = File(projectDir, "build.gradle") + val definitionFile = File(projectDir, "build.gradle") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "gradle-android-expected-output-root.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } "Project dependencies are detected correctly".config(tags = setOf(AndroidTag)) { - val packageFile = File(projectDir, "app/build.gradle") + val definitionFile = File(projectDir, "app/build.gradle") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "gradle-android-expected-output-app.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } "External dependencies are detected correctly".config(tags = setOf(AndroidTag)) { - val packageFile = File(projectDir, "lib/build.gradle") + val definitionFile = File(projectDir, "lib/build.gradle") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "gradle-android-expected-output-lib.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } } diff --git a/analyzer/src/funTest/kotlin/GradleKotlinScriptTest.kt b/analyzer/src/funTest/kotlin/GradleKotlinScriptTest.kt index 8beb2f4448862..646cfc72d7cf6 100644 --- a/analyzer/src/funTest/kotlin/GradleKotlinScriptTest.kt +++ b/analyzer/src/funTest/kotlin/GradleKotlinScriptTest.kt @@ -28,8 +28,8 @@ import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION import com.here.ort.utils.test.USER_DIR import com.here.ort.utils.test.patchExpectedResult +import io.kotlintest.matchers.maps.shouldContainKey import io.kotlintest.shouldBe -import io.kotlintest.shouldNotBe import io.kotlintest.specs.StringSpec import java.io.File @@ -42,48 +42,54 @@ class GradleKotlinScriptTest : StringSpec() { init { "root project dependencies are detected correctly" { - val packageFile = File(projectDir, "build.gradle.kts") + val definitionFile = File(projectDir, "build.gradle.kts") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "multi-kotlin-project-expected-output-root.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } "core project dependencies are detected correctly" { - val packageFile = File(projectDir, "core/build.gradle.kts") + val definitionFile = File(projectDir, "core/build.gradle.kts") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "multi-kotlin-project-expected-output-core.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } "cli project dependencies are detected correctly" { - val packageFile = File(projectDir, "cli/build.gradle.kts") + val definitionFile = File(projectDir, "cli/build.gradle.kts") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "multi-kotlin-project-expected-output-cli.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } } diff --git a/analyzer/src/funTest/kotlin/GradleLibraryTest.kt b/analyzer/src/funTest/kotlin/GradleLibraryTest.kt index 27594393604e1..27ab00db34a01 100644 --- a/analyzer/src/funTest/kotlin/GradleLibraryTest.kt +++ b/analyzer/src/funTest/kotlin/GradleLibraryTest.kt @@ -28,8 +28,8 @@ import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION import com.here.ort.utils.test.USER_DIR import com.here.ort.utils.test.patchExpectedResult +import io.kotlintest.matchers.maps.shouldContainKey import io.kotlintest.shouldBe -import io.kotlintest.shouldNotBe import io.kotlintest.specs.StringSpec import java.io.File @@ -42,48 +42,54 @@ class GradleLibraryTest : StringSpec() { init { "Root project dependencies are detected correctly" { - val packageFile = File(projectDir, "build.gradle") + val definitionFile = File(projectDir, "build.gradle") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "gradle-library-expected-output-root.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } "Project dependencies are detected correctly" { - val packageFile = File(projectDir, "app/build.gradle") + val definitionFile = File(projectDir, "app/build.gradle") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "gradle-library-expected-output-app.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } "External dependencies are detected correctly" { - val packageFile = File(projectDir, "lib/build.gradle") + val definitionFile = File(projectDir, "lib/build.gradle") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "gradle-library-expected-output-lib.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } } diff --git a/analyzer/src/funTest/kotlin/GradleTest.kt b/analyzer/src/funTest/kotlin/GradleTest.kt index 5bbb7636b770a..1f71a514508e4 100644 --- a/analyzer/src/funTest/kotlin/GradleTest.kt +++ b/analyzer/src/funTest/kotlin/GradleTest.kt @@ -34,8 +34,8 @@ import com.here.ort.utils.test.patchActualResult import com.here.ort.utils.test.patchExpectedResult import io.kotlintest.Spec +import io.kotlintest.matchers.maps.shouldContainKey import io.kotlintest.shouldBe -import io.kotlintest.shouldNotBe import io.kotlintest.specs.StringSpec import io.kotlintest.tables.forAll import io.kotlintest.tables.headers @@ -59,77 +59,87 @@ class GradleTest : StringSpec() { init { "Root project dependencies are detected correctly" { - val packageFile = File(projectDir, "build.gradle") + val definitionFile = File(projectDir, "build.gradle") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "gradle-expected-output-root.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } "Project dependencies are detected correctly" { - val packageFile = File(projectDir, "app/build.gradle") + val definitionFile = File(projectDir, "app/build.gradle") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "gradle-expected-output-app.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } "External dependencies are detected correctly" { - val packageFile = File(projectDir, "lib/build.gradle") + val definitionFile = File(projectDir, "lib/build.gradle") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "gradle-expected-output-lib.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } "Unresolved dependencies are detected correctly" { - val packageFile = File(projectDir, "lib-without-repo/build.gradle") + val definitionFile = File(projectDir, "lib-without-repo/build.gradle") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "gradle-expected-output-lib-without-repo.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - patchActualResult(yamlMapper.writeValueAsString(result)) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + patchActualResult(yamlMapper.writeValueAsString(resultForDefinitionFile)) shouldBe expectedResult + } } "Fails nicely for Gradle version < 2.14".config(enabled = false) { - val packageFile = File(projectDir.parentFile, "gradle-unsupported-version/build.gradle") + val definitionFile = File(projectDir.parentFile, "gradle-unsupported-version/build.gradle") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "gradle-expected-output-unsupported-version.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } "Is compatible with Gradle >= 2.14".config(tags = setOf(ExpensiveTag), enabled = false) { @@ -175,18 +185,20 @@ class GradleTest : StringSpec() { forAll(gradleVersionTable) { version, resultsFileSuffix -> installGradleWrapper(version) - val packageFile = File(projectDir, "app/build.gradle") + val definitionFile = File(projectDir, "app/build.gradle") val expectedResult = patchExpectedResult( File(projectDir.parentFile, "gradle-expected-output-app$resultsFileSuffix.yml"), url = normalizeVcsUrl(vcsUrl), revision = vcsRevision ) - val result = createGradle().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createGradle().resolveDependencies(USER_DIR, listOf(definitionFile)) - result shouldNotBe null - result!!.errors shouldBe emptyList() - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.errors shouldBe emptyList() + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } } } diff --git a/analyzer/src/funTest/kotlin/NpmTest.kt b/analyzer/src/funTest/kotlin/NpmTest.kt index 7e296b5551d06..a49eb613ec978 100644 --- a/analyzer/src/funTest/kotlin/NpmTest.kt +++ b/analyzer/src/funTest/kotlin/NpmTest.kt @@ -32,6 +32,7 @@ import com.here.ort.utils.test.patchExpectedResult import io.kotlintest.TestCase import io.kotlintest.TestResult +import io.kotlintest.matchers.maps.shouldContainKey import io.kotlintest.shouldBe import io.kotlintest.specs.WordSpec @@ -61,9 +62,9 @@ class NpmTest : WordSpec() { "NPM" should { "resolve shrinkwrap dependencies correctly" { val workingDir = File(projectsDir, "shrinkwrap") - val packageFile = File(workingDir, "package.json") + val definitionFile = File(workingDir, "package.json") - val result = createNPM().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createNPM().resolveDependencies(USER_DIR, listOf(definitionFile)) val vcsPath = vcsDir.getPathToRoot(workingDir) val expectedResult = patchExpectedResult( File(projectsDir.parentFile, "npm-expected-output.yml"), @@ -74,14 +75,17 @@ class NpmTest : WordSpec() { path = vcsPath ) - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } "resolve package-lock dependencies correctly" { val workingDir = File(projectsDir, "package-lock") - val packageFile = File(workingDir, "package.json") + val definitionFile = File(workingDir, "package.json") - val result = createNPM().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createNPM().resolveDependencies(USER_DIR, listOf(definitionFile)) val vcsPath = vcsDir.getPathToRoot(workingDir) val expectedResult = patchExpectedResult( File(projectsDir.parentFile, "npm-expected-output.yml"), @@ -92,14 +96,17 @@ class NpmTest : WordSpec() { path = vcsPath ) - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } "show error if no lockfile is present" { val workingDir = File(projectsDir, "no-lockfile") - val packageFile = File(workingDir, "package.json") + val definitionFile = File(workingDir, "package.json") - val result = createNPM().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createNPM().resolveDependencies(USER_DIR, listOf(definitionFile)) val vcsPath = vcsDir.getPathToRoot(workingDir) val expectedResult = patchExpectedResult( File(projectsDir.parentFile, "npm-expected-output-no-lockfile.yml"), @@ -110,14 +117,17 @@ class NpmTest : WordSpec() { path = vcsPath ) - patchActualResult(yamlMapper.writeValueAsString(result)) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + patchActualResult(yamlMapper.writeValueAsString(resultForDefinitionFile)) shouldBe expectedResult + } } "resolve dependencies even if the node_modules directory already exists" { val workingDir = File(projectsDir, "node-modules") - val packageFile = File(workingDir, "package.json") + val definitionFile = File(workingDir, "package.json") - val result = createNPM().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createNPM().resolveDependencies(USER_DIR, listOf(definitionFile)) val vcsPath = vcsDir.getPathToRoot(workingDir) val expectedResult = patchExpectedResult( File(projectsDir.parentFile, "npm-expected-output.yml"), @@ -128,7 +138,10 @@ class NpmTest : WordSpec() { path = vcsPath ) - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } } } diff --git a/analyzer/src/funTest/kotlin/NpmVersionUrlTest.kt b/analyzer/src/funTest/kotlin/NpmVersionUrlTest.kt index 14431794b1999..637707bec709a 100644 --- a/analyzer/src/funTest/kotlin/NpmVersionUrlTest.kt +++ b/analyzer/src/funTest/kotlin/NpmVersionUrlTest.kt @@ -32,6 +32,7 @@ import com.here.ort.utils.test.patchExpectedResult import io.kotlintest.TestCase import io.kotlintest.TestResult +import io.kotlintest.matchers.maps.shouldContainKey import io.kotlintest.shouldBe import io.kotlintest.specs.WordSpec @@ -56,10 +57,10 @@ class NpmVersionUrlTest : WordSpec() { init { "NPM" should { "resolve dependencies with URLs as versions correctly" { - val packageFile = File(projectDir, "package.json") + val definitionFile = File(projectDir, "package.json") val config = AnalyzerConfiguration(false, true) - val result = createNPM(config).resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val result = createNPM(config).resolveDependencies(USER_DIR, listOf(definitionFile)) val vcsPath = vcsDir.getPathToRoot(projectDir) val expectedResult = patchExpectedResult( File(projectDir.parentFile, "npm-version-urls-expected-output.yml"), @@ -69,7 +70,10 @@ class NpmVersionUrlTest : WordSpec() { path = vcsPath ) - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } } } diff --git a/analyzer/src/funTest/kotlin/PhpComposerTest.kt b/analyzer/src/funTest/kotlin/PhpComposerTest.kt index f7281504605a9..36a4c272b5554 100644 --- a/analyzer/src/funTest/kotlin/PhpComposerTest.kt +++ b/analyzer/src/funTest/kotlin/PhpComposerTest.kt @@ -29,10 +29,10 @@ import com.here.ort.utils.test.DEFAULT_REPOSITORY_CONFIGURATION import com.here.ort.utils.test.USER_DIR import com.here.ort.utils.test.patchExpectedResult +import io.kotlintest.matchers.maps.shouldContainKey import io.kotlintest.matchers.startWith import io.kotlintest.should import io.kotlintest.shouldBe -import io.kotlintest.shouldNotBe import io.kotlintest.specs.StringSpec import java.io.File @@ -60,16 +60,19 @@ class PhpComposerTest : StringSpec() { "Error is shown when no lock file is present" { val definitionFile = File(projectsDir, "no-lockfile/composer.json") - val result = createPhpComposer().resolveDependencies(USER_DIR, listOf(definitionFile))[definitionFile] - - result shouldNotBe null - result!!.project.id shouldBe Identifier("PhpComposer::src/funTest/assets/projects/synthetic/" + - "php-composer/no-lockfile/composer.json:") - result.project.definitionFilePath shouldBe - "analyzer/src/funTest/assets/projects/synthetic/php-composer/no-lockfile/composer.json" - result.packages.size shouldBe 0 - result.errors.size shouldBe 1 - result.errors.first().message should startWith("IllegalArgumentException: No lock file found in") + val result = createPhpComposer().resolveDependencies(USER_DIR, listOf(definitionFile)) + + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + resultForDefinitionFile.project.id shouldBe Identifier("PhpComposer::src/funTest/assets/projects/" + + "synthetic/php-composer/no-lockfile/composer.json:") + resultForDefinitionFile.project.definitionFilePath shouldBe + "analyzer/src/funTest/assets/projects/synthetic/php-composer/no-lockfile/composer.json" + resultForDefinitionFile.packages.size shouldBe 0 + resultForDefinitionFile.errors.size shouldBe 1 + resultForDefinitionFile.errors.first().message should + startWith("IllegalArgumentException: No lock file found in") + } } "No composer.lock is required for projects without dependencies" { diff --git a/analyzer/src/funTest/kotlin/YarnTest.kt b/analyzer/src/funTest/kotlin/YarnTest.kt index c8e884db3c07a..e0f2497ca5b56 100644 --- a/analyzer/src/funTest/kotlin/YarnTest.kt +++ b/analyzer/src/funTest/kotlin/YarnTest.kt @@ -31,6 +31,7 @@ import com.here.ort.utils.test.patchExpectedResult import io.kotlintest.TestCase import io.kotlintest.TestResult +import io.kotlintest.matchers.maps.shouldContainKey import io.kotlintest.shouldBe import io.kotlintest.specs.WordSpec @@ -59,8 +60,8 @@ class YarnTest : WordSpec() { init { "yarn" should { "resolve dependencies correctly" { - val packageFile = File(projectDir, "package.json") - val result = createYarn().resolveDependencies(USER_DIR, listOf(packageFile))[packageFile] + val definitionFile = File(projectDir, "package.json") + val result = createYarn().resolveDependencies(USER_DIR, listOf(definitionFile)) val vcsPath = vcsDir.getPathToRoot(projectDir) val expectedResult = patchExpectedResult( File(projectDir.parentFile, "yarn-expected-output.yml"), @@ -70,7 +71,10 @@ class YarnTest : WordSpec() { path = vcsPath ) - yamlMapper.writeValueAsString(result) shouldBe expectedResult + result shouldContainKey definitionFile + result[definitionFile]!!.let { resultForDefinitionFile -> + yamlMapper.writeValueAsString(resultForDefinitionFile) shouldBe expectedResult + } } } } diff --git a/analyzer/src/funTest/kotlin/integration/AbstractIntegrationSpec.kt b/analyzer/src/funTest/kotlin/integration/AbstractIntegrationSpec.kt index 02861700eee22..daa7c4fb834e5 100644 --- a/analyzer/src/funTest/kotlin/integration/AbstractIntegrationSpec.kt +++ b/analyzer/src/funTest/kotlin/integration/AbstractIntegrationSpec.kt @@ -32,8 +32,8 @@ import com.here.ort.utils.test.ExpensiveTag import com.here.ort.utils.test.USER_DIR import io.kotlintest.Spec -import io.kotlintest.matchers.beEmpty import io.kotlintest.matchers.collections.containExactly +import io.kotlintest.matchers.haveSize import io.kotlintest.should import io.kotlintest.shouldBe import io.kotlintest.shouldNot @@ -124,8 +124,8 @@ abstract class AbstractIntegrationSpec : StringSpec() { VersionControlSystem.forType(result.project.vcsProcessed.type) shouldBe VersionControlSystem.forType(pkg.vcs.type) result.project.vcsProcessed.url shouldBe pkg.vcs.url - result.project.scopes shouldNot beEmpty() - result.packages shouldNot beEmpty() + result.project.scopes shouldNot haveSize(0) + result.packages shouldNot haveSize(0) result.collectErrors().keys should containExactly(identifiersWithExpectedErrors) } } diff --git a/model/src/test/kotlin/config/ExcludesTest.kt b/model/src/test/kotlin/config/ExcludesTest.kt index 963ff9ac03fb0..7d33674668340 100644 --- a/model/src/test/kotlin/config/ExcludesTest.kt +++ b/model/src/test/kotlin/config/ExcludesTest.kt @@ -210,7 +210,13 @@ class ExcludesTest : WordSpec() { val excludesById = excludes.projectExcludesById(setOf(project1, project2, project3)) excludesById.keys should haveSize(3) - excludesById.keys should containAll(projectId1, projectId2, projectId3) + + // Note: kotlintest's containAll() calls toString() on the elements which is not desired here, also see + // https://github.com/kotlintest/kotlintest/pull/638 + excludesById.containsKey(projectId1) shouldBe true + excludesById.containsKey(projectId2) shouldBe true + excludesById.containsKey(projectId3) shouldBe true + excludesById.values should containOnlyNulls() }