Skip to content
This repository has been archived by the owner on Aug 19, 2020. It is now read-only.

Commit

Permalink
Prove named(name, action) works on monomorphic named containers
Browse files Browse the repository at this point in the history
#1104

Signed-off-by: Paul Merlin <[email protected]>
  • Loading branch information
eskatos committed Sep 16, 2018
1 parent 5c5dd62 commit b6178c1
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.kotlin.dsl

import org.gradle.kotlin.dsl.fixtures.TestWithTempFiles
import org.gradle.kotlin.dsl.fixtures.eval
import org.gradle.kotlin.dsl.fixtures.newProjectBuilderProject

import org.hamcrest.CoreMatchers.hasItems
import org.hamcrest.MatcherAssert.assertThat

import org.junit.Test


class NamedContainersEvalTest : TestWithTempFiles() {

@Test
fun `monomorphic named domain object container api extensions`() {
root.newProjectBuilderProject().run {

eval("""
configurations.create("foo")
configurations.create("bar") {
extendsFrom(configurations["foo"])
}
configurations.getByName("bar") {
extendsFrom(configurations.getByName("foo"))
}
configurations.register("bazar")
configurations.register("cathedral") {
extendsFrom(configurations.named("bazar").get())
}
configurations.named("cathedral") {
extendsFrom(configurations.named("bazar").get())
}
""")

assertThat(
configurations.names,
hasItems("foo", "bar", "bazar", "cathedral")
)
}
}

@Test
fun `monomorphic named domain object container scope api extensions`() {
root.newProjectBuilderProject().run {

eval("""
configurations {
create("foo")
create("bar") {
extendsFrom(getByName("foo"))
}
getByName("bar") {
extendsFrom(getByName("foo"))
}
register("bazar")
register("cathedral") {
extendsFrom(named("bazar").get())
}
named("cathedral") {
extendsFrom(named("bazar").get())
}
}
""")

assertThat(
configurations.names,
hasItems("foo", "bar", "bazar", "cathedral")
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.gradle.kotlin.dsl.fixtures

import org.gradle.api.Project

import org.gradle.testfixtures.ProjectBuilder

import java.io.File


fun File.newProjectBuilder(name: String = this.name): ProjectBuilder =
ProjectBuilder.builder().withName(name).withProjectDir(this)


fun File.newProjectBuilderProject(name: String = this.name): Project =
newProjectBuilder(name).build()
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ import java.io.File
import java.net.URLClassLoader


/**
* Evaluates the given Kotlin [script] against this [Project] writing compiled classes
* to sub-directories of `$projectDir/.gradle/kotlin-dsl-eval-cache`.
*/
fun Project.eval(
script: String,
baseCacheDir: File = file(".gradle/kotlin-dsl-eval-cache")
) {
eval(script, this, baseCacheDir)
}


/**
* Evaluates the given Kotlin [script] against the given [target] writing compiled classes
* to sub-directories of [baseCacheDir].
Expand Down

0 comments on commit b6178c1

Please sign in to comment.