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

Run tests in the corresponding -test target if you're not in a test target. #320

Open
sbushmanov opened this issue Dec 22, 2022 · 5 comments
Labels

Comments

@sbushmanov
Copy link

sbushmanov commented Dec 22, 2022

I'm trying to run "Test Target" in nvim's dap and getting error message:

LSP[metals] no tests could be found in build target

I've got directory tree like this:

src/main
└── scala
    └── com
        └── example
            ├── package.scala
            └── scalaProject
                ├── Functions.scala
                └── Main.scala
src/test
└── scala
    └── com
        └── example
            └── scalaProject
                └── FunctionsTest.scala

and my FunctionsTest.scala looks like this:

package com.example.scalaProject


import Functions._
import org.scalatest.funspec.AnyFunSpec

class FunctionsTest extends AnyFunSpec {

  describe("toUpper") {

    it("returns true if toUpper works and false otherwise") {

      assert("HELLO" == "hello".toUpper)

    }
  }
}

And my Metals Doctor output looks like this:

## Metals Info
  - Metals Server version: 0.11.9
  - Build server currently being used is Bloop v1.5.4.
  - Metals Java: 11.0.16 from GraalVM Community located at /usr/lib/jvm/java-11-graalvm

These are the installed build targets for this workspace. One build target corresponds to one classpath. For example, normally one sbt project maps to two build targets: main and test.

## Build Targets

### scalaproject
  - target type: Scala 2.13.9
  - compilation: ✅ 
  - diagnostics: ✅ 
  - interactive: ✅ 
  - semanticdb: ✅ 
  - debugging: ✅ 
  - java: ✅ 

### scalaproject-test
  - target type: Scala 2.13.9
  - compilation: ✅ 
  - diagnostics: ✅ 
  - interactive: ✅ 
  - semanticdb: ✅ 
  - debugging: ✅ 
  - java: ✅ 

### scalaproject-build
  - target type: sbt 1.8.0
  - compilation: ✅ 
  - diagnostics: ⚠️ 
  - interactive: ✅ 
  - semanticdb: ✅ 
  - debugging: ❌
  - java: ✅ 
  - recommendation: Diagnostics and debugging for sbt are not supported currently.

### scalaproject-build-build
  - target type: sbt 1.8.0
  - compilation: ✅ 
  - diagnostics: ⚠️ 
  - interactive: ✅ 
  - semanticdb: ✅ 
  - debugging: ❌
  - java: ✅ 
  - recommendation: Diagnostics and debugging for sbt are not supported currently.

### scalaproject-build-build-build
  - target type: sbt 1.8.0
  - compilation: ✅ 
  - diagnostics: ⚠️ 
  - interactive: ✅ 
  - semanticdb: ✅ 
  - debugging: ❌
  - java: ✅ 
  - recommendation: Diagnostics and debugging for sbt are not supported currently.

## Explanations

### Compilation status:
✅  - code is compiling

### Diagnostics:
✅  - diagnostics correctly being reported by the build server
⚠️  - only syntactic errors being reported

### Interactive features (completions, hover):
✅  - supported Scala version

### Semanticdb features (references, renames, go to implementation):
✅  - build tool automatically creating needed semanticdb files

### Debugging (run/test, breakpoints, evaluation):
✅  - users can run or test their code with debugging capabilities
❌ - the tool does not support debugging in this target

### Java Support:
✅  - working non-interactive features (references, rename etc.)

When I run "Test Target" on Main.scala I do expect to see output of test results like this:

FunctionsTest:
toUpper
- returns true if toUpper works and false otherwise (34 milliseconds)
Execution took 34ms
1 tests, 1 passed
All tests in com.example.scalaProject.FunctionsTest passed

however I'm getting an error message instead.

Are my expectations wrong?

@ckipp01
Copy link
Member

ckipp01 commented Dec 23, 2022

Hey @sbushmanov thanks for the questions. I think the issue here is that Test Target is testing the current build target that you're in, not the test target that corresponds to the target you're in. For example if you trigger Test Target in nvim when you're in Mains.scala you're in the scalaproject target, not the scalaproject-test target. The latter is the one that actually holds the tests. So you'd need to navigate to any file that belongs to that target (FunctionsTest.scala in your example), and then trigger it. You should then see what you expect.

@ckipp01
Copy link
Member

ckipp01 commented Dec 23, 2022

However, this does bring up a good question of should we do this. I sort of think it might make sense in your scenario to run the tests in the corresponding test target.

@ckipp01 ckipp01 added the debug label Dec 23, 2022
@sbushmanov
Copy link
Author

Well, when I run FunctionsTest.scala I do receive the above message that tests completed successfully. Thanks for clearing that up!

@tgodzik
Copy link
Contributor

tgodzik commented Dec 24, 2022

I think this can be a feature request then. To run tests from the test module accompanying the current module, what do you think?

@ckipp01 ckipp01 transferred this issue from scalameta/metals Dec 24, 2022
@ckipp01 ckipp01 changed the title LSP[metals] no tests could be found in build target Run tests in the corresponding -test target if you're not in a test target. Dec 24, 2022
@ckipp01
Copy link
Member

ckipp01 commented Dec 24, 2022

I think this can be a feature request then. To run tests from the test module accompanying the current module, what do you think?

Yea sure, I'll move it to the feature request repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants