Skip to content

Commit

Permalink
Consistent platforms: Added test cases for targetting the wrong type …
Browse files Browse the repository at this point in the history
…of components
  • Loading branch information
freekh committed Oct 9, 2014
1 parent 72e64cf commit 92332d8
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,57 @@ Binaries
"""
}

def "shows an error when targeting a native platform from a jvm component"() {
given:
buildFile << """
apply plugin: 'jvm-component'
apply plugin: 'native-component'
apply plugin: 'java-lang'
model {
platforms {
i386 { architecture 'i386' }
}
}
jvm {
libraries {
myLib {
targetPlatform "i386"
}
}
}
"""
when:
fails "components"

then:
failure.assertHasCause("Invalid JavaPlatform: i386")
}


def "shows an error when targeting a jvm platform from a native component"() {
given:
buildFile << """
apply plugin: 'jvm-component'
apply plugin: 'native-component'
apply plugin: 'java-lang'
nativeRuntime {
libraries {
myLib {
targetPlatform "java8"
}
}
}
"""
when:
fails "components"

then:
failure.assertHasCause("Invalid NativePlatform: java8")
}

private boolean outputMatches(String actualOutput, String expectedOutput) {
String cleaned = actualOutput.substring(0, actualOutput.lastIndexOf("BUILD SUCCESSFUL"))
assert cleaned == expected(expectedOutput)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.gradle.language.java
import org.gradle.api.JavaVersion
import org.gradle.integtests.fixtures.AbstractIntegrationSpec
import org.gradle.jvm.platform.internal.DefaultJavaPlatform
import org.gradle.language.fixtures.BadJavaLibrary
import org.gradle.language.fixtures.TestJavaLibrary
import org.gradle.test.fixtures.archive.JarTestFixture
Expand Down Expand Up @@ -313,6 +314,33 @@ class JavaLanguageIntegrationTest extends AbstractIntegrationSpec {
assert failure.assertHasCause("Invalid JavaPlatform: $badName")
}

@Requires(TestPrecondition.JDK8_OR_EARLIER)
def "builds all buildable and skips non-buildable platforms when assembling"() {
def current = new DefaultJavaPlatform(JavaVersion.current())
when:
app.sources*.writeToDir(file("src/myLib/java"))

and:
buildFile << """
apply plugin: 'jvm-component'
apply plugin: 'java-lang'
jvm {
libraries {
myLib {
targetPlatform "${current.name}", "java9"
}
}
}
"""
then:
succeeds "assemble"

and:
jarFile("build/jars/myLibJar/${current.name}/myLib.jar").javaVersion == current.targetCompatibility
}


@Requires(TestPrecondition.JDK8_OR_EARLIER)
def "too high JDK target should produce reasonable error message"() {
when:
Expand Down

0 comments on commit 92332d8

Please sign in to comment.