Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle project declaration without named arguments. #30

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public class DependencyExtractor(
configuration = configuration,
identifier = identifier
?: error("Could not determine dependency identifier. Failed to parse expression:\n `$fullText`"),
producerConfiguration = identifier.configuration,
capability = capability,
type = type.or(identifier),
fullText = fullText,
Expand Down Expand Up @@ -422,10 +423,6 @@ public class DependencyExtractor(
val explicitPath = firstKey == "path" || secondKey == "path"

if (firstKey == "path" || firstKey == null) {
require(secondKey == "configuration") {
"Expected 'configuration', was '$secondKey'."
}

path = firstValue
configuration = secondValue
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cash.grammar.kotlindsl.utils

import cash.grammar.kotlindsl.model.DependencyDeclaration
import cash.grammar.kotlindsl.model.DependencyDeclaration.Capability
import cash.grammar.kotlindsl.model.DependencyDeclaration.Identifier
import cash.grammar.kotlindsl.model.DependencyDeclaration.Identifier.Companion.asSimpleIdentifier
import cash.grammar.kotlindsl.model.DependencyDeclaration.Type
import cash.grammar.kotlindsl.parse.Parser
Expand Down Expand Up @@ -209,6 +210,15 @@ internal class DependencyExtractorTest {
capability = Capability.DEFAULT,
type = Type.PROJECT,
),
TestCase(
displayName = "project dependency on configuration",
fullText = """api(project(":foo", "shadow"))""",
configuration = "api",
identifier = Identifier(path = "\":foo\"", configuration = "\"shadow\""),
capability = Capability.DEFAULT,
type = Type.PROJECT,
producerConfiguration = "\"shadow\"",
),
TestCase(
displayName = "testFixtures capability for project dependency",
fullText = "testImplementation(testFixtures(project(\":has-test-fixtures\")))",
Expand Down Expand Up @@ -248,20 +258,45 @@ internal class DependencyExtractorTest {
val displayName: String,
val fullText: String,
val configuration: String,
val identifier: String,
val identifier: Identifier,
val capability: Capability,
val type: Type,
val producerConfiguration: String? = null,
val precedingComment: String? = null
) {
override fun toString(): String = displayName

fun toDependencyDeclaration() = DependencyDeclaration(
constructor(
displayName: String,
fullText: String,
configuration: String,
identifier: String,
capability: Capability,
type: Type,
producerConfiguration: String? = null,
precedingComment: String? = null
) : this(
displayName = displayName,
fullText = fullText,
configuration = configuration,
identifier = identifier.asSimpleIdentifier()!!,
capability = capability,
type = type,
fullText = fullText,
producerConfiguration = producerConfiguration,
precedingComment = precedingComment,
)

override fun toString(): String = displayName

fun toDependencyDeclaration(): DependencyDeclaration {
return DependencyDeclaration(
configuration = configuration,
identifier = identifier,
capability = capability,
type = type,
fullText = fullText,
producerConfiguration = producerConfiguration,
precedingComment = precedingComment,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ internal class DependenciesSimplifierTest {
""".trimIndent()
)
}

@Test fun `the project function doesn't require named arguments`() {
DependenciesSimplifier.of(
"""
dependencies {
api(project(":imported-protos", "shadow"))
}
""".trimIndent()
)
}
}
Loading