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
Enable defining and running tests inside same Scala file #1093
Comments
I like this idea. Implementation-wise, I think we would likely compile everything together (main scope + tests), then split things in a second time. So we would have to:
|
@antholeole if you're indeed interested in implementing this, let me know if you need any help with setting up. |
I'll break ground on this when I get free time - if it's blocking anyone I can try to prioritize this and / or relinquish |
Sat down to get started on this today and it seems the request is actually working more or less without any modification? //> using dep "org.scalameta::munit::0.7.29"
object NumAPI:
def foo(): Int = 4
@main
def main() = print(foo())
class NumAPISpec extends munit.FunSuite:
test("check foo returns 3") {
assertEquals(NumAPI.foo(), 3)
}
EDIT: I found some places where enchancement is needed. I'm still going to take a look |
Are you fine with test dependencies polluting the classpath? |
Is your feature request related to a problem? Please describe.
Languages such as Rust enable you to define tests (usually unit tests) together with the code one is testing. This is useful and a productivity booster:
All in all, the following
a.scala
source should be valid:Describe the solution you'd like
scala-cli
could enable us to define and run tests in the same source code. This would involve makingscala-cli test a.scala
compile and run the tests defined ina.scala
, regardless of whether//> using target.scope "test"
has been defined or not.Additional context
Here's a few design considerations to take into account just from the user and semantics POV (not discussing implementation details).
Should test code defined in
a.scala
be available/importable (when #948 is implemented)? I don't think it should. Tests defined with the tested code should be treated as private. The benefit of this is that we can also drop the test dependencies from being depended on.What should we do with test dependencies? The unit tests might need to import additional test dependencies aside from the test framework. We should have a way that these test dependencies are not leaked to the classpath of other modules depending on the source.
The text was updated successfully, but these errors were encountered: