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

Exclude companion object #328

Open
gvolpe opened this issue Nov 14, 2017 · 3 comments
Open

Exclude companion object #328

gvolpe opened this issue Nov 14, 2017 · 3 comments

Comments

@gvolpe
Copy link

gvolpe commented Nov 14, 2017

Hi, I'm wondering whether it is possible to exclude a companion object?

Given:

object Animal {
  def apply: Animal = ???
}

class Animal {
  ???
}

Is it possible just to exclude the object Animal and not the class? I can't make it work with the exclusion rules.

@gvolpe
Copy link
Author

gvolpe commented Nov 14, 2017

Also, if I have something like this:

object Animal {
  def apply: Animal = ???
}

class Animal extends AbstractAnimal {
  ???
}

class AbstractAnimal {
  ???
}

And I just want to exclude both object and class Animal I can't make it work. Adding coverageExcludedPackages := ".*Animal*" excludes everything.

@Facsimiler
Copy link

Facsimiler commented Nov 14, 2017

Caveat, I haven't tried this, but...

Would using an exclusion string of "^.*\.Animal\$$" filter out just the Animal object? The names of generated object types will have a $ suffix, so the object is actually named Animal$; the $ needs to be escaped by a backslash so that it is treated literally. The second $ is the regular expression match for the end of the line, so that it can't be followed by anything else.

(BTW, I'm assuming that these elements are part of a package. If not, try a regex of just "^Animal\$$" so that it doesn't look for a period (.) at the start of the name.)

If that doesn't work, you can also use the comment exclusion approach:

// $COVERAGE-OFF$Don't include companion object in coverage analysis.
object Animal {
  def apply: Animal = ???
}
// $COVERAGE-ON$

class Animal {
  ???
}

// etc.

Let me know if that does the trick...

(EDIT: More on Java regular expressions.)

@gvolpe
Copy link
Author

gvolpe commented Nov 14, 2017

Hi @MichaelJAllen, thanks but unfortunately doesn't do the trick, I just tried...

I was aware about the comment exclusion approach but I don't like it. I'd rather keep my code clean than have a "non-real" higher test coverage.

@ckipp01 ckipp01 transferred this issue from scoverage/sbt-scoverage May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants