Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions delta-coverage-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation(deps.httpClient)
implementation(deps.openCsv)
implementation(deps.jackson)
implementation(deps.jacksonKotlin)

testImplementation(deps.jimFs)
}
Expand Down
5 changes: 3 additions & 2 deletions delta-coverage-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

gradlePlugin {
website.set("https://github.com/SurpSG/delta-coverage")
website.set("https://gw-kit.github.io/delta-coverage-plugin")
vcsUrl.set("https://github.com/SurpSG/delta-coverage.git")

plugins {
Expand All @@ -22,14 +22,15 @@ dependencies {
implementation(project(":delta-coverage-core"))
implementation(deps.coverJetPlugin)

testImplementation(gradleApi()) // required to add this dependency explicitly after applying shadowJar plugin
testImplementation(gradleApi())
testImplementation(deps.jimFs)
testRuntimeOnly(deps.kotlinJvm)

functionalTestImplementation(project(":delta-coverage-gradle"))
functionalTestImplementation(testFixtures(project))
functionalTestImplementation(deps.jgit)
functionalTestImplementation(deps.gradleProbe)
functionalTestImplementation(deps.jacksonKotlin)

testFixturesApi(project(":delta-coverage-core"))
testFixturesImplementation(deps.kotestAssertions)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import io.github.surpsg.deltacoverage.gradle.CoverageEngine
import io.github.surpsg.deltacoverage.gradle.DeltaCoverageConfiguration
import io.github.surpsg.deltacoverage.gradle.CoverageEntity.*
import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {
java
Expand All @@ -15,6 +16,11 @@ repositories {

tasks.withType<Test> {
useJUnitPlatform()

testLogging {
events(TestLogEvent.SKIPPED, TestLogEvent.FAILED, TestLogEvent.PASSED)
showStandardStreams = true
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
public class Class1 {

public int covered(boolean arg) {
if(arg) {
for (int i = 0; i < 100; i++) {
System.out.println(i);
}
if (arg) {
return 1;
}
return 0;
Expand All @@ -22,4 +25,4 @@ public int partialCovered(boolean arg) {
public int notCovered(boolean arg) {
return arg ? 1 : 0;
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=3.6.0
version=3.7.0
group=io.github.gw-kit
org.gradle.parallel=true
kotlin.code.style=official
Expand Down
6 changes: 5 additions & 1 deletion gradle/deps.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ logbackVer = "1.5.22"

kotlinVer = "2.3.0"
junitVer = "6.0.2"
junitPlatformVer = "1.11.4"
mockkVer = "1.14.7"
kotestVer = "6.1.1"
jimfsVer = "1.3.1"
picocliVer = "4.7.6"

jfrConverterVer = "4.3"
coverJetVer = "0.1.4"
deltaCoverageVer = "3.5.1"
deltaCoverageVer = "3.7.0"
gradleProbeVer = "0.0.2"

[libraries]
Expand All @@ -30,6 +32,7 @@ detekt = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version

# Project deps
gradleProbe = { module = "io.github.gw-kit:gradle-probe", version.ref = "gradleProbeVer" }
jfrConverter = { module = "tools.profiler:jfr-converter", version.ref = "jfrConverterVer" }
coverJetPlugin = { module = "io.github.gw-kit.cover-jet:io.github.gw-kit.cover-jet.gradle.plugin", version.ref = "coverJetVer" }
intellijCoverage = { module = "org.jetbrains.intellij.deps:intellij-coverage-reporter", version.ref = "intellijCoverageVer" }
intellijCoverageAgent = { module = "org.jetbrains.intellij.deps:intellij-coverage-agent", version.ref = "intellijCoverageVer" }
Expand All @@ -46,6 +49,7 @@ logback = { module = "ch.qos.logback:logback-classic", version.ref = "logbackVer

# Testing
junitApi = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junitVer" }
junitPlatformLauncher = { module = "org.junit.platform:junit-platform-launcher", version.ref = "junitPlatformVer" }
mockk = { module = "io.mockk:mockk", version.ref = "mockkVer" }
kotestAssertions = { module = "io.kotest:kotest-assertions-core-jvm", version.ref = "kotestVer" }
jimFs = { module = "com.google.jimfs:jimfs", version.ref = "jimfsVer" }
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include(
"delta-coverage-cli",
"delta-coverage-core",
"delta-coverage-gradle",
"test-impact-gradle",
)

dependencyResolutionManagement {
Expand Down
33 changes: 33 additions & 0 deletions test-impact-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
`gradle-plugin-conventions`
}

gradlePlugin {
website.set("https://gw-kit.github.io/delta-coverage-plugin")
vcsUrl.set("https://github.com/gw-kit/delta-coverage-plugin.git")
plugins {
create("testImpactPlugin") {
id = "io.github.gw-kit.test-impact"
displayName = "Test Impact Analysis"
description = "Sampling-based test-to-code mapping and impact analysis"
implementationClass = "io.github.gwkit.testimpact.gradle.TestImpactPlugin"
tags.set(listOf("test", "impact", "mapping", "jfr", "sampling", "performance"))
}
}
}

dependencies {
// Jackson for JSON report output
implementation(deps.jackson)
implementation(deps.jacksonKotlin)

// async-profiler JFR-to-flamegraph converter
implementation(deps.jfrConverter)

// Unit tests
testImplementation(testFixtures(project(":delta-coverage-gradle")))

// Functional tests
functionalTestImplementation(deps.jacksonKotlin)
functionalTestImplementation(deps.gradleProbe)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package io.github.gwkit.testimpact.gradle

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import io.github.gwkit.gradleprobe.RestorableFile
import io.github.gwkit.gradleprobe.gradlerunner.runTask
import io.github.gwkit.gradleprobe.junit.GradlePluginTest
import io.github.gwkit.gradleprobe.junit.GradleRunnerInstance
import io.github.gwkit.gradleprobe.junit.ProjectFile
import io.github.gwkit.gradleprobe.junit.RootProjectDir
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.collections.shouldNotBeEmpty
import io.kotest.matchers.file.shouldBeAFile
import io.kotest.matchers.ints.shouldBeGreaterThan
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldContain
import org.gradle.testkit.runner.GradleRunner
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import java.io.File

@Suppress("UNCHECKED_CAST")
@GradlePluginTest("single-module-test-project")
class TestMappingFunctionalTest {

@RootProjectDir
lateinit var rootProjectDir: File

@ProjectFile("build.gradle.kts")
lateinit var buildFile: RestorableFile

@GradleRunnerInstance
lateinit var gradleRunner: GradleRunner

@BeforeEach
fun beforeEach() {
buildFile.restoreOriginContent()
}

@Test
fun `flamegraph should be created when enabled`() {
// GIVEN
buildFile.file.appendText(
"""
testImpact {
enabled = true
includePackages.add("com.java.test")
reports {
html.set(true)
flamegraph.set(true)
}
}
""".trimIndent()
)

// WHEN
gradleRunner.runTask("test", "analyzeTestMapping")
.apply {
println(output)
}

// THEN
val reportDir = rootProjectDir.resolve("build/reports/test-impact")

// TODO
// reportDir.resolve("test-mapping.html").shouldBeAFile()

val flamegraphFile = reportDir.resolve("flamegraph.html")
flamegraphFile.shouldBeAFile()
assertSoftly(flamegraphFile.readText()) {
shouldContain("canvas")
shouldContain("async-profiler")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import org.gradle.api.tasks.testing.logging.TestLogEvent

plugins {
java
kotlin("jvm") version "2.3.0"
id("io.github.gw-kit.test-impact")
}

repositories {
mavenCentral()
}

tasks.withType<Test> {
useJUnitPlatform()

testLogging {
events(TestLogEvent.SKIPPED, TestLogEvent.FAILED, TestLogEvent.PASSED)
showStandardStreams = true
}
}

dependencies {
testImplementation(platform("org.junit:junit-bom:6.0.2"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.java.test;

public class Class1 {

public int covered(boolean arg) {
for (int i = 0; i < 1000; i++) {
System.out.println(i);
}
if (arg) {
return 1;
}
return 0;
}

public int partialCovered(boolean arg) {
int result;
if (arg) {
result = 1;
} else {
result = 0;
}
return result;
}

public int notCovered(boolean arg) {
return arg ? 1 : 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.java.test;
public class UnchagedClass {
public void method() {
System.out.println(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.java.test;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

public class Class1Test {

private Class1 class1 = new Class1();

@Test
public void coveredShouldReturn1() {
int covered = class1.covered(true);
assertEquals(1, covered);
}

@Test
public void coveredShouldReturn0() {
int covered = class1.covered(false);
assertEquals(0, covered);
}

@Test
public void partialCoveredShouldReturn1() {
int covered = class1.partialCovered(true);
assertEquals(1, covered);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Index: src/main/java/com/java/test/Class1.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/com/java/test/Class1.java (date 1563021950000)
+++ src/main/java/com/java/test/Class1.java (date 1563021990000)
@@ -3,15 +3,23 @@
public class Class1 {

public int covered(boolean arg) {
+ if(arg) {
+ return 1;
+ }
return 0;
}

public int partialCovered(boolean arg) {
- int result = 0;
+ int result;
+ if (arg) {
+ result = 1;
+ } else {
+ result = 0;
+ }
return result;
}

public int notCovered(boolean arg) {
- return 0;
+ return arg ? 1 : 0;
}
}
Loading
Loading