org.gradle.api.internal.tasks.scala.NormalizingScalaCompilerTest.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 6.9.1 API redistribution.
/*
* Copyright 2012 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.api.internal.tasks.scala
import groovy.transform.InheritConstructors
import org.gradle.api.internal.file.collections.SimpleFileCollection
import org.gradle.api.internal.tasks.compile.CompilationFailedException
import org.gradle.api.tasks.WorkResult
import org.gradle.api.tasks.compile.CompileOptions
import org.gradle.language.base.internal.compile.Compiler
import org.gradle.language.scala.tasks.BaseScalaCompileOptions
import spock.lang.Specification
class NormalizingScalaCompilerTest extends Specification {
Compiler target = Mock()
DefaultScalaJavaJointCompileSpec spec = new DefaultScalaJavaJointCompileSpec()
NormalizingScalaCompiler compiler = new NormalizingScalaCompiler(target)
def setup() {
spec.destinationDir = new File("dest")
spec.source = files("Source1.java", "Source2.java", "Source3.java")
spec.compileClasspath = [new File("Dep1.jar"), new File("Dep2.jar")]
spec.zincClasspath = files("zinc.jar", "zinc-dep.jar")
spec.compileOptions = new CompileOptions()
spec.scalaCompileOptions = new BaseScalaCompileOptions()
}
def "delegates to target compiler after resolving source"() {
def workResult = Mock(WorkResult)
when:
def result = compiler.execute(spec)
then:
1 * target.execute(spec) >> {
assert spec.source as List == old(spec.source as List)
workResult
}
result == workResult
}
def "propagates compile failure"() {
def failure
target.execute(spec) >> { throw failure = new CompilationFailedException() }
when:
compiler.execute(spec)
then:
CompilationFailedException e = thrown()
e == failure
}
def "ignores compile failure when failOnError is false"() {
target.execute(spec) >> { throw new CompilationFailedException() }
spec.scalaCompileOptions.failOnError = false
when:
def result = compiler.execute(spec)
then:
noExceptionThrown()
!result.didWork
}
def "propagates other failure"() {
def failure
target.execute(spec) >> { throw failure = new RuntimeException() }
when:
compiler.execute(spec)
then:
RuntimeException e = thrown()
e == failure
}
def "resolves any non-strings that make it into custom compiler args"() {
spec.compileOptions.compilerArgs << "a dreaded ${"GString"}"
spec.compileOptions.compilerArgs << 42
assert !spec.compileOptions.compilerArgs.any { it instanceof String }
when:
compiler.execute(spec)
then:
1 * target.execute(_) >> { ScalaJavaJointCompileSpec spec ->
assert spec.compileOptions.compilerArgs.every { it instanceof String }
}
}
private files(String... paths) {
new TestFileCollection(paths.collect { new File(it) })
}
// file collection whose type is distinguishable from SimpleFileCollection
@InheritConstructors
static class TestFileCollection extends SimpleFileCollection {}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy