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

Merge nested classes for reports #498

Open
shanshin opened this issue Oct 27, 2023 · 4 comments
Open

Merge nested classes for reports #498

shanshin opened this issue Oct 27, 2023 · 4 comments
Assignees
Labels
Feature Feature request issue type S: postponed Status: work on the issue is not in the short term plans

Comments

@shanshin
Copy link
Collaborator

shanshin commented Oct 27, 2023

When generating HTML reports and during verification, any nested classes are analyzed and displayed separately.
From the point of view of Kotlin code, this is not entirely correct, because these class-files are features of the JVM compiler implementation and do not reflect the real coverage of the Kotlin class.

It is necessary to merge coverage for the following nested classes:

  • companion object
  • lambda
  • anonymous object
  • local class

Example:

class NestedExample {
    companion object {
        // companion
    }

    private fun functionHandler(f: () -> String) {
        println("result ${f()}")
    }

    fun handle() {
        // local class
        class LocalClass { }

        // lambda
        functionHandler {
            "function"
        }

        // anonymous object
        object: Function<String> {
            override fun toString(): String = "Hi"
        }
    }
}

the coverage is evaluated separately for all classes, e.g.:

NestedExample line coverage: ..%
NestedExample$Companion line coverage: ..%
NestedExample$handle$1 line coverage: ..%
NestedExample$handle$2 line coverage: ..%
NestedExample$handle$LocalClass line coverage: ..%

Expected:

NestedExample line coverage: ..%

Important!
At the same time, regular nested classes and inner classes should continue to be counted separately:

class Nested2Example {
    class Foo {
    }

    inner class Bar {
    }
}

should give

Nested2Example line coverage: ..%
Nested2Example$Bar line coverage: ..%
Nested2Example$Foo line coverage: ..%
@shanshin shanshin added Feature Feature request issue type S: untriaged Status: issue reported but unprocessed labels Oct 27, 2023
@shanshin shanshin self-assigned this Oct 27, 2023
@shanshin shanshin added S: postponed Status: work on the issue is not in the short term plans and removed S: untriaged Status: issue reported but unprocessed labels Oct 27, 2023
@zuevmaxim
Copy link

@shanshin Do you mean only HTML report?

@shanshin
Copy link
Collaborator Author

shanshin commented Jan 29, 2024

@zuevmaxim
No, HTML and verification.

@shanshin
Copy link
Collaborator Author

shanshin commented Apr 3, 2024

I. Lambda

fun a() {
    lambdaCall {
        sout("call")
    }
}
  1. remove lambda class from report
  2. remove separate lambda method from report
  3. move all line and instruction coverage to method a

*don't forget about nested lambdas

fun a() {
    lambdaCall {
        sout("call")
        lambdaCall {
            sout("call2")
        }
    }
}

Lambda always extends kotlin/jvm/internal/Lambda

@shanshin
Copy link
Collaborator Author

shanshin commented Apr 3, 2024

II. Companion
merge content of companion objects in containing class:
companion's methods renamed with companion_ prefix.

Example

class My {
  companion object {
    fun a() {
    }
  }

  fun a() {
  }
}

gives in XML

<class My>
  <method "companion_a">
  <method "a">
</>

It should be disabled by flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Feature request issue type S: postponed Status: work on the issue is not in the short term plans
Projects
None yet
Development

No branches or pull requests

2 participants