sqality / scct

Scala Code Coverage Tool
Apache License 2.0
67 stars 7 forks source link

Resource directories are dropped on scct:test #21

Closed jimschubert closed 11 years ago

jimschubert commented 11 years ago

I've encountered an issue related to mtkopone/scct#50 in which resource directories are not included in the instrumentation of tests.

My problem occurs when using Typesafe config with settings modified for test under /src/test/resources/application.conf. Tests pass with ./sbt test but fail with ./sbt scct:test. Fair warning, I'm fairly new to Scala development in general so I may be missing some unspoken best practice here.

I've created a sample project to demonstrate: https://github.com/jimschubert/scct-resources-issue

The fix is simple:

val scctSettings = ScctPlugin.instrumentSettings ++ Seq(
  // resourceDirectory in ScctPlugin.ScctTest <<= (resourceDirectory in Test), // this setting is optional
  unmanagedResources in ScctPlugin.ScctTest <<= (unmanagedResources in Test)
)

Then, instead of settings(ScctPlugin.instrumentSettings: _*), use settings(scctSettings:_*):

/**
 * ISSUE: Toggle the last two settings lines below and run ./sbt scct:test
 */
lazy val scctResourcesIssue = Project("scct-resources-issue", file("."))
  .settings(Project.defaultSettings:_*)
  .settings(appSettings:_*)
  // .settings(ScctPlugin.instrumentSettings: _*) // Does not work with test resources
  .settings(scctSettings:_*) // works with test resources

I'm not sure whether this is a feature request or a documentation request, but as in the linked issue I consider it unexpected behavior to run tests instrumented for code coverage with different results than non-instrumented tests.

Thanks!

jimschubert commented 11 years ago

Closing this, because it was merged into the proper project (SCCT/sbt-scct).