Skip to content

Commit c9faf3e

Browse files
committed
test(package-managers): Do not use USER_DIR as the analyzer root
`USER_DIR` is the current user / working directory which does not necessarily have anything in common with the definition files. Use a more realistic analyzer root that is a parent of the definition files instead. For `CargoSubcrateFunTest` this actually fixes the `PackageLinkage` as it is determined based in the `analyzerRoot`. This corrects "Crate::lib:0.1.0" to appear in the list of packages. For various other tests, this simplifies the project ID / paths of expected results as the project root now equals the `analyzerRoot`. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent c68daec commit c9faf3e

File tree

17 files changed

+82
-41
lines changed

17 files changed

+82
-41
lines changed

analyzer/src/testFixtures/kotlin/TestUtils.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import org.ossreviewtoolkit.model.config.RepositoryConfiguration
4040
import org.ossreviewtoolkit.model.config.ScopeExclude
4141
import org.ossreviewtoolkit.model.config.ScopeExcludeReason
4242
import org.ossreviewtoolkit.plugins.api.PluginConfig
43-
import org.ossreviewtoolkit.utils.test.USER_DIR
43+
import org.ossreviewtoolkit.utils.common.getCommonParentFile
4444

4545
fun PackageManager.resolveSingleProject(
4646
definitionFile: File,
@@ -49,14 +49,15 @@ fun PackageManager.resolveSingleProject(
4949
resolveScopes: Boolean = false
5050
): ProjectAnalyzerResult {
5151
val definitionFiles = listOf(definitionFile)
52+
val analyzerRoot = getCommonParentFile(definitionFiles)
5253
val analyzerConfig = AnalyzerConfiguration(allowDynamicVersions = allowDynamicVersions)
5354

54-
beforeResolution(USER_DIR, definitionFiles, analyzerConfig)
55+
beforeResolution(analyzerRoot, definitionFiles, analyzerConfig)
5556

5657
val excludes = Excludes(scopes = excludedScopes.map { ScopeExclude(it, ScopeExcludeReason.TEST_DEPENDENCY_OF) })
57-
val managerResult = resolveDependencies(USER_DIR, definitionFiles, excludes, analyzerConfig, emptyMap())
58+
val managerResult = resolveDependencies(analyzerRoot, definitionFiles, excludes, analyzerConfig, emptyMap())
5859

59-
afterResolution(USER_DIR, definitionFiles)
60+
afterResolution(analyzerRoot, definitionFiles)
6061

6162
val resultList = managerResult.projectResults[definitionFile]
6263
resultList.shouldNotBeNull()

plugins/package-managers/bundler/src/funTest/assets/projects/synthetic/bundler-expected-output-lockfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
project:
3-
id: "Bundler::src/funTest/assets/projects/synthetic/lockfile/Gemfile:"
3+
id: "Bundler::Gemfile:"
44
definition_file_path: "plugins/package-managers/bundler/src/funTest/assets/projects/synthetic/lockfile/Gemfile"
55
declared_licenses: []
66
declared_licenses_processed: {}

plugins/package-managers/bundler/src/funTest/kotlin/BundlerFunTest.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ class BundlerFunTest : WordSpec({
4848
val actualResult = BundlerFactory.create().resolveSingleProject(definitionFile)
4949

5050
with(actualResult) {
51-
project.id shouldBe
52-
Identifier("Bundler::src/funTest/assets/projects/synthetic/no-lockfile/Gemfile:")
51+
project.id shouldBe Identifier("Bundler::Gemfile:")
5352
project.definitionFilePath shouldBe
5453
"plugins/package-managers/bundler/src/funTest/assets/projects/synthetic/no-lockfile/Gemfile"
5554
packages should beEmpty()

plugins/package-managers/cargo/src/funTest/assets/projects/synthetic/cargo-subcrate-client-expected-output.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ project:
2121
- name: "dependencies"
2222
dependencies:
2323
- id: "Crate::lib:0.1.0"
24-
linkage: "PROJECT_STATIC"
24+
linkage: "STATIC"
2525
dependencies:
2626
- id: "Crate::cfg-if:0.1.9"
2727
linkage: "STATIC"
@@ -59,3 +59,32 @@ packages:
5959
url: "https://github.com/alexcrichton/cfg-if.git"
6060
revision: ""
6161
path: ""
62+
- id: "Crate::lib:0.1.0"
63+
purl: "pkg:cargo/[email protected]"
64+
declared_licenses:
65+
- "Apache-2.0"
66+
- "MIT"
67+
declared_licenses_processed:
68+
spdx_expression: "Apache-2.0 OR MIT"
69+
description: ""
70+
homepage_url: "https://example.org"
71+
binary_artifact:
72+
url: ""
73+
hash:
74+
value: ""
75+
algorithm: ""
76+
source_artifact:
77+
url: ""
78+
hash:
79+
value: ""
80+
algorithm: ""
81+
vcs:
82+
type: ""
83+
url: ""
84+
revision: ""
85+
path: ""
86+
vcs_processed:
87+
type: "Git"
88+
url: "<REPLACE_URL_PROCESSED>"
89+
revision: "<REPLACE_REVISION>"
90+
path: "plugins/package-managers/cargo/src/funTest/assets/projects/synthetic/cargo-subcrate"

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import java.net.URI
3535
import org.ossreviewtoolkit.model.VcsType
3636
import org.ossreviewtoolkit.model.config.AnalyzerConfiguration
3737
import org.ossreviewtoolkit.model.config.Excludes
38-
import org.ossreviewtoolkit.utils.test.USER_DIR
3938

4039
class CarthageTest : WordSpec() {
4140
private val carthage = CarthageFactory.create()
@@ -128,4 +127,4 @@ class CarthageTest : WordSpec() {
128127
}
129128

130129
private fun Carthage.resolveDependencies(definitionFile: File) =
131-
resolveDependencies(USER_DIR, definitionFile, Excludes.EMPTY, AnalyzerConfiguration(), emptyMap())
130+
resolveDependencies(definitionFile.parentFile, definitionFile, Excludes.EMPTY, AnalyzerConfiguration(), emptyMap())

plugins/package-managers/cocoapods/src/funTest/assets/projects/synthetic/dep-tree-expected-output.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
project:
3-
id: "CocoaPods::src/funTest/assets/projects/synthetic/dep-tree/Podfile:"
3+
id: "CocoaPods::Podfile:"
44
definition_file_path: "plugins/package-managers/cocoapods/src/funTest/assets/projects/synthetic/dep-tree/Podfile"
55
declared_licenses: []
66
declared_licenses_processed: {}

plugins/package-managers/cocoapods/src/funTest/assets/projects/synthetic/external-sources-expected-output.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
project:
3-
id: "CocoaPods::src/funTest/assets/projects/synthetic/external-sources/Podfile:"
3+
id: "CocoaPods::Podfile:"
44
definition_file_path: "plugins/package-managers/cocoapods/src/funTest/assets/projects/synthetic/external-sources/Podfile"
55
declared_licenses: []
66
declared_licenses_processed: {}

plugins/package-managers/cocoapods/src/funTest/assets/projects/synthetic/no-lockfile-expected-output.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
project:
3-
id: "CocoaPods::src/funTest/assets/projects/synthetic/no-lockfile/Podfile:"
3+
id: "CocoaPods::Podfile:"
44
definition_file_path: "plugins/package-managers/cocoapods/src/funTest/assets/projects/synthetic/no-lockfile/Podfile"
55
declared_licenses: []
66
declared_licenses_processed: {}
@@ -20,7 +20,6 @@ packages: []
2020
issues:
2121
- timestamp: "1970-01-01T00:00:00Z"
2222
source: "CocoaPods"
23-
message: "Missing lockfile 'src/funTest/assets/projects/synthetic/no-lockfile/Podfile.lock'\
24-
\ for definition file 'src/funTest/assets/projects/synthetic/no-lockfile/Podfile'.\
25-
\ The analysis of a Podfile without a lockfile is not supported."
23+
message: "Missing lockfile 'Podfile.lock' for definition file 'Podfile'. The analysis\
24+
\ of a Podfile without a lockfile is not supported."
2625
severity: "ERROR"

plugins/package-managers/cocoapods/src/funTest/assets/projects/synthetic/regular-expected-output.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
project:
3-
id: "CocoaPods::src/funTest/assets/projects/synthetic/regular/Podfile:"
3+
id: "CocoaPods::Podfile:"
44
definition_file_path: "plugins/package-managers/cocoapods/src/funTest/assets/projects/synthetic/regular/Podfile"
55
declared_licenses: []
66
declared_licenses_processed: {}

plugins/package-managers/cocoapods/src/funTest/assets/projects/synthetic/version-resolution-expected-output.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
project:
3-
id: "CocoaPods::src/funTest/assets/projects/synthetic/version-resolution/Podfile:"
3+
id: "CocoaPods::Podfile:"
44
definition_file_path: "plugins/package-managers/cocoapods/src/funTest/assets/projects/synthetic/version-resolution/Podfile"
55
declared_licenses: []
66
declared_licenses_processed: {}

0 commit comments

Comments
 (0)