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

Add a simple plugin test #87

Merged
merged 11 commits into from
Feb 4, 2020
14 changes: 14 additions & 0 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ pluginBundle {
}
}

configure<PublishingExtension> {
martinbonnin marked this conversation as resolved.
Show resolved Hide resolved
repositories {
maven {
name = "pluginTest"
url = uri("file://${rootProject.buildDir}/localMaven")
}
}
martinbonnin marked this conversation as resolved.
Show resolved Hide resolved
}

detekt {
toolVersion = "1.4.0"
input = files("src/")
Expand All @@ -69,3 +78,8 @@ tasks.jacocoTestReport {
tasks.check {
dependsOn(tasks.jacocoTestReport)
}

tasks.withType<Test> {
dependsOn("publishPluginMavenPublicationToPluginTestRepository")
inputs.dir("src/test/testProject")
}
28 changes: 28 additions & 0 deletions plugin/src/test/java/com/yelp/plugin/PluginTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.yelp.plugin

import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Assert
import org.junit.Test
import java.io.File


class PluginTests {
@Test
fun `basic plugin test`() {
martinbonnin marked this conversation as resolved.
Show resolved Hide resolved
val tmpDir = File(".", "build/testProject")
tmpDir.deleteRecursively()

println(File(".").absolutePath)
File(".", "src/test/testProject").copyRecursively(tmpDir)

val result = GradleRunner.create().withProjectDir(tmpDir)
.forwardStdOutput(System.out.writer())
.forwardStdError(System.err.writer())
.withArguments("generateSwagger")
.build()

Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":generateSwagger")?.outcome)
}
}
30 changes: 30 additions & 0 deletions plugin/src/test/testProject/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import com.yelp.codegen.plugin.GenerateTaskConfiguration

buildscript {
repositories {
maven {
cortinico marked this conversation as resolved.
Show resolved Hide resolved
url = uri("../../../build/localMaven")
martinbonnin marked this conversation as resolved.
Show resolved Hide resolved
}
jcenter {
content {
excludeGroup("com.yelp.codegen")
}
}
}
dependencies {
// Always take the latest version from the local test repo
// This is not super robust and we could find a way to communicate the version to the testProject
// by copying the root buildSrc to the testProject or extracting the version in a properties file
classpath("com.yelp.codegen:plugin:+")
}
}

apply(plugin = "com.yelp.codegen.plugin")

configure<GenerateTaskConfiguration> {
platform = "kotlin"
packageName = "com.yelp.codegen.samples"
// this file is in rootDir/plugin/build/testProject/
inputFile = file("../../../samples/junit-tests/junit_tests_specs.json")
outputDir = file("./build/generetadSources")
martinbonnin marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions plugin/src/test/testProject/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name="testProject"
martinbonnin marked this conversation as resolved.
Show resolved Hide resolved