-
Notifications
You must be signed in to change notification settings - Fork 39
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
Created tests for diktat-gradle-plugin #561
Changes from all commits
777bcb6
8fe247d
bdfee1f
9752255
46691c7
6c3de5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.cqfn.diktat.plugin.gradle | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
class DiktatGradlePluginTest { | ||
private val projectBuilder = ProjectBuilder.builder() | ||
private lateinit var project: Project | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
project = projectBuilder.build() | ||
project.pluginManager.apply(DiktatGradlePlugin::class.java) | ||
} | ||
|
||
@Test | ||
fun `check that tasks are registered`() { | ||
Assertions.assertTrue(project.tasks.findByName("diktatCheck") != null) | ||
Assertions.assertTrue(project.tasks.findByName("diktatFix") != null) | ||
} | ||
|
||
@Test | ||
fun `check default extension properties`() { | ||
val diktatExtension = project.extensions.getByName("diktat") as DiktatExtension | ||
Assertions.assertFalse(diktatExtension.debug) | ||
Assertions.assertIterableEquals(project.fileTree("src").files, diktatExtension.inputs.files) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.cqfn.diktat.plugin.gradle | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.testfixtures.ProjectBuilder | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import java.io.File | ||
|
||
class DiktatJavaExecTaskTest { | ||
private val projectBuilder = ProjectBuilder.builder() | ||
private lateinit var project: Project | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
project = projectBuilder.build() | ||
} | ||
|
||
@Test | ||
fun `check command line for various inputs`() { | ||
val pwd = project.file(".") | ||
assertCommandLineEquals( | ||
listOf(null, "$pwd" + listOf("src", "**", "*.kt").joinToString(File.separator, prefix = File.separator)), | ||
DiktatExtension().apply { | ||
inputs = project.files("src/**/*.kt") | ||
} | ||
) | ||
} | ||
|
||
@Test | ||
fun `check command line in debug mode`() { | ||
val pwd = project.file(".") | ||
assertCommandLineEquals( | ||
listOf(null, "--debug", "$pwd${listOf("src", "**", "*.kt").joinToString(File.separator, prefix = File.separator)}"), | ||
DiktatExtension().apply { | ||
inputs = project.files("src/**/*.kt") | ||
debug = true | ||
} | ||
) | ||
} | ||
|
||
private fun registerDiktatTask(extension: DiktatExtension) = project.tasks.register( | ||
"test", DiktatJavaExecTaskBase::class.java, | ||
"6.7", extension, project.configurations.create("diktat") | ||
) | ||
|
||
private fun assertCommandLineEquals(expected: List<String?>, extension: DiktatExtension) { | ||
val task = registerDiktatTask(extension).get() | ||
Assertions.assertIterableEquals(expected, task.commandLine) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.cqfn.diktat.plugin.gradle | ||
|
||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
|
||
class UtilsTest { | ||
@Test | ||
fun `test gradle version`() { | ||
Assertions.assertEquals( | ||
GradleVersion.fromString("6.6.1"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do you need to test gradle version. It can be changed in any moment. No? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm testing my |
||
GradleVersion(6, 6, 1, null) | ||
) | ||
|
||
Assertions.assertEquals( | ||
GradleVersion.fromString("6.7"), | ||
GradleVersion(6, 7, 0, null) | ||
) | ||
|
||
Assertions.assertEquals( | ||
GradleVersion.fromString("6.7-rc-5"), | ||
GradleVersion(6, 7, 0, "rc-5") | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need test report here? For test coverage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this tasks will execute
test
and then generate jacoco report.