Jacek Laskowski
Jacek Laskowski

Reputation: 74779

Per-configuration classpath dependencies doesn't work with test->test in SBT?

I've got a multi-project build with scalania main project as well as exercises and answers (sub)projects.

The scalania project is hosted on GitHub.

I'm trying to set up a SBT project configuration where the test classes are part of the exercises project while the answers project provides the solutions.

I read Per-configuration classpath dependencies in the official documentation of SBT and ended up with the following configuration in the scalania main project:

lazy val exercises = project

lazy val answers = project.dependsOn(exercises % "test->test")

It doesn't seem to work and upon test execution I used to get:

> project answers
[info] Set current project to scalania-answers (in build file:/Users/jacek/oss/scalania/)
> test
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] No tests to run for answers/test:test
[success] Total time: 1 s, completed Oct 27, 2013 1:06:51 AM

It was until I changed answers/build.sbt to the following:

scalaSource in Test := (scalaSource in LocalProject("exercises") in Test).value

It works fine now.

> reload
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Loading project definition from /Users/jacek/oss/scalania/project
[info] Set current project to scalania-answers (in build file:/Users/jacek/oss/scalania/)
> project answers
[info] Set current project to scalania-answers (in build file:/Users/jacek/oss/scalania/)
> testOnly *s99.P01*
[info] Formatting 19 Scala sources {file:/Users/jacek/oss/scalania/}answers(test) ...
[info] Compiling 19 Scala sources to /Users/jacek/oss/scalania/answers/target/scala-2.10/test-classes...
[info] P01Spec
[info]
[info] P01 solution should
[info] + Find the last element of a list
[info]
[info]
[info] Total for specification P01Spec
[info] Finished in 151 ms
[info] 1 example, 0 failure, 0 error
[info] Passed: Total 1, Failed 0, Errors 0, Passed 1
[success] Total time: 74 s, completed Oct 27, 2013 1:09:07 AM

What's wrong with using project.dependsOn(exercises % "test->test") only? Am I missing something in the build configuration?

Upvotes: 2

Views: 398

Answers (1)

Mark Harrah
Mark Harrah

Reputation: 7019

Declaring a dependency on tests in another project just makes the classpath available. Running its tests doesn't happen by default because otherwise tests would run multiple times in the common situation of just reusing code.

To run tests in another project, add the discovered tests from the other project to those for the current project:

definedTests in Test := 
   (definedTests in Test).value ++
   (definedTests in exercises in Test).value

Upvotes: 2

Related Questions