Skip to content
Draft
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
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ jobs:
cache: gradle

- name: Run Unit Tests Coverage
run: ./gradlew koverXmlReportDebug
run: ./gradlew koverXmlReportDebug -Dkover.path.normalization=relative

- name: Normalize paths in coverage report
run: |
# Create a backup of the original report
cp library/build/reports/kover/reportDebug.xml library/build/reports/kover/reportDebug.xml.bak

# Replace absolute paths with relative ones
# This matches any paths starting with /Users/ and replaces them with relative paths
sed -i 's|/Users/[^/]*/Code/paypal-messages-android/|./|g' library/build/reports/kover/reportDebug.xml

- name: Show Coverage Report XML
run: cat library/build/reports/kover/reportDebug.xml
Expand Down
59 changes: 58 additions & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'kotlin-android'
id 'org.jetbrains.kotlin.android'
id 'de.mannodermaus.android-junit5' version "1.9.3.0"
id 'org.jetbrains.kotlinx.kover' version '0.7.6'
id 'org.jetbrains.kotlinx.kover' version '0.9.1'
}

android {
Expand Down Expand Up @@ -113,6 +113,11 @@ tasks.withType(Test).configureEach {
// Example filter: excludeTestsMatching "com.paypal.messages.PayPalModalActivityTest"
}

// Configure all Kover tasks to use relative paths
tasks.withType(org.jetbrains.kotlinx.kover.gradle.plugin.tasks.KoverXmlReportTask).configureEach {
systemProperty 'kover.path.normalization', 'relative'
}

// Optimized approach for handling problematic tests
android {
testOptions {
Expand Down Expand Up @@ -170,6 +175,44 @@ tasks.register('testMemoryIntensiveClasses') {
description = "Runs memory-intensive tests in isolated JVM processes"
}

// Add a task to test the coverage report paths
tasks.register('testKoverPaths') {
dependsOn 'koverXmlReportDebug'

doLast {
println "\n\n===== Testing Kover paths in coverage report =====\n"

def reportFile = file("${buildDir}/reports/kover/reportDebug.xml")
if (!reportFile.exists()) {
throw new GradleException("Coverage report file not found at: ${reportFile.absolutePath}")
}

println "Checking coverage report for absolute paths..."

def reportContent = reportFile.text
def absolutePathPattern = "/Users/"
def hasAbsolutePaths = reportContent.contains(absolutePathPattern)

if (hasAbsolutePaths) {
println "WARNING: Found absolute paths in the coverage report!"
println "Creating normalized version..."

// Create a backup of the original report
def backupFile = file("${buildDir}/reports/kover/reportDebug.xml.bak")
backupFile.text = reportContent

// Replace absolute paths with relative ones
def normalizedContent = reportContent.replaceAll("/Users/[^/]*/Code/paypal-messages-android/", "./")
reportFile.text = normalizedContent

println "Normalized coverage report saved to: ${reportFile.absolutePath}"
} else {
println "SUCCESS: No absolute paths found in the coverage report."
}
}
description = "Tests and fixes paths in Kover coverage reports"
}

koverReport {
androidReports('debug') {
filters {
Expand Down Expand Up @@ -206,6 +249,20 @@ koverReport {
)
}
}

// Add explicit XML report configuration with relative paths
xml {
// Set report file to a location relative to the project
reportFile.set(layout.buildDirectory.file("reports/kover/reportDebug.xml"))
}

// Define sources using project-relative paths
sources {
sourceDirectories.from(
file("src/main/kotlin"),
file("src/main/java")
)
}
}
}

Expand Down
Loading