Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #714 from mockito/sf-snapshot
Browse files Browse the repository at this point in the history
Improved coverage, added handy assertion method
  • Loading branch information
epeee committed Apr 26, 2018
2 parents 369b96e + 450e2b3 commit 2646713
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 17 deletions.
Expand Up @@ -10,7 +10,7 @@ class ShipkitGradlePluginIntegTest extends GradleSpecification {
gradleVersion = gradleVersionToTest
and:
file("gradle/shipkit.gradle") << """
newFile("gradle/shipkit.gradle") << """
shipkit {
gitHub.readOnlyAuthToken = "foo"
gitHub.repository = "repo"
Expand Down
Expand Up @@ -22,7 +22,7 @@ class ShipkitJavaIntegTest extends GradleSpecification {
gradleVersion = gradleVersionToTest
and:
file("gradle/shipkit.gradle") << """
newFile("gradle/shipkit.gradle") << """
shipkit {
gitHub.readOnlyAuthToken = "foo"
gitHub.writeAuthToken = "secret"
Expand All @@ -45,8 +45,8 @@ class ShipkitJavaIntegTest extends GradleSpecification {
buildFile << "apply plugin: 'org.shipkit.java'"
settingsFile << "include 'api', 'impl'"
file('api/build.gradle') << "apply plugin: 'java'"
file('impl/build.gradle') << "apply plugin: 'java'"
newFile('api/build.gradle') << "apply plugin: 'java'"
newFile('impl/build.gradle') << "apply plugin: 'java'"
expect:
BuildResult result = pass("performRelease", "-m", "-s")
Expand Down
Expand Up @@ -10,28 +10,30 @@ class SnapshotIntegTest extends GradleSpecification {
settingsFile << "include 'java-module'"
buildFile << "apply plugin: 'org.shipkit.java'"

file("java-module/build.gradle") << "apply plugin: 'java'"
newFile("java-module/build.gradle") << "apply plugin: 'java'"

when:
def result = pass("snapshot")

then:
result.task(":java-module:snapshot").outcome == TaskOutcome.SUCCESS
result.task(":snapshot").outcome == TaskOutcome.UP_TO_DATE //this is how Gradle reports tasks with no behavior
assertFileExists("java-module/build/libs/java-module-1.0.0-SNAPSHOT.jar")
}

def "snapshot build for Gradle plugin project"() {
given:
settingsFile << "include 'gradle-plugin-module'"
buildFile << "apply plugin: 'org.shipkit.gradle-plugin'"

file("gradle-plugin-module/build.gradle") << "apply plugin: 'com.gradle.plugin-publish'"
newFile("gradle-plugin-module/build.gradle") << "apply plugin: 'com.gradle.plugin-publish'"

when:
def result = pass("snapshot")

then:
result.task(":gradle-plugin-module:snapshot").outcome == TaskOutcome.SUCCESS
result.task(":snapshot").outcome == TaskOutcome.UP_TO_DATE
assertFileExists("gradle-plugin-module/build/libs/gradle-plugin-module-1.0.0-SNAPSHOT.jar")
}
}
Expand Up @@ -7,7 +7,7 @@ class InitPluginIntegTest extends GradleSpecification {
def "runs initShipkit task in a project without any Shipkit configuration (using gradle version #gradleVersionToTest)"() {
given:
gradleVersion = gradleVersionToTest
assert file("version.properties").delete()
assert file("version.properties").delete() //simulate clean state
and:
buildFile << "apply plugin: 'org.shipkit.java'"
Expand Down
Expand Up @@ -10,7 +10,7 @@ class CiUpgradeDownstreamPluginIntegTest extends GradleSpecification {
gradleVersion = gradleVersionToTest
and:
file("gradle/shipkit.gradle") << """
newFile("gradle/shipkit.gradle") << """
shipkit {
gitHub.url = "http://github.com"
gitHub.readOnlyAuthToken = "token"
Expand Down
Expand Up @@ -10,7 +10,7 @@ class UpgradeDependencyPluginIntegTest extends GradleSpecification {
gradleVersion = gradleVersionToTest
and:
file("gradle/shipkit.gradle") << """
newFile("gradle/shipkit.gradle") << """
shipkit {
gitHub.writeAuthToken = "secret"
gitHub.repository = "repo"
Expand Down
Expand Up @@ -10,7 +10,7 @@ class UpgradeDownstreamPluginIntegTest extends GradleSpecification {
gradleVersion = gradleVersionToTest
and:
file("gradle/shipkit.gradle") << """
newFile("gradle/shipkit.gradle") << """
shipkit {
gitHub.url = "http://github.com"
}
Expand Down
Expand Up @@ -27,7 +27,7 @@ abstract class GradleSpecification extends Specification implements GradleVersio
private static final String RESOURCES_DIR = findResourcesDir(CLASSES_DIR)

void setup() {
buildFile = file('build.gradle')
buildFile = newFile('build.gradle')
buildFile << """buildscript {
dependencies {
classpath files("${CLASSES_DIR}")
Expand All @@ -43,32 +43,58 @@ abstract class GradleSpecification extends Specification implements GradleVersio
}
}
"""
settingsFile = file('settings.gradle')
settingsFile = newFile('settings.gradle')
settingsFile << ""

//Shipkit configuration with sensible defaults
file("gradle/shipkit.gradle") << """
newFile("gradle/shipkit.gradle") << """
shipkit {
gitHub.readOnlyAuthToken = "foo"
gitHub.repository = "repo"
releaseNotes.publicationRepository = "repo"
}
"""

file("version.properties") << "version=1.0.0"
newFile("version.properties") << "version=1.0.0"
}

/**
* Convenience method for creating files using path.
* Convenience method for creating new files using path.
* You can pass "foo.txt" or "foo/bar/baz.txt".
* Creates empty file (including parent dirs) and returns it.
*/
protected File file(String fileName) {
File file = new File(projectDir.root, fileName)
protected File newFile(String filePath) {
File file = file(filePath)
file.getParentFile().mkdirs()
file.createNewFile()
file
}

/**
* Convenience method for selecting files using path.
* You can pass "foo.txt" or "foo/bar/baz.txt".
*/
protected File file(String filePath) {
File file = new File(projectDir.root, filePath)
file
}

/**
* Asserts if file exists, throwing informative exception if not.
* File path is evaluated as {@link #file(java.lang.String)}
*/
protected void assertFileExists(String filePath) {
File file = file(filePath)
if (!file.exists()) {
if (!file.parentFile.exists()) {
throw new AssertionError("Directory does not exist: ${file.parentFile}")
} else {
throw new AssertionError("File does not exist: ${filePath}. All files in this dir:\n " +
file.parentFile.list().join("\n "))
}
}
}

/**
* Runs Gradle with given arguments, prints the build.gradle file to the standard output if the test fails
*/
Expand Down

0 comments on commit 2646713

Please sign in to comment.