zio / zio-intellij

A companion IntelliJ IDEA plugin for the ZIO library ecosystem.
Apache License 2.0
212 stars 40 forks source link

Plugin unable to find the spec class names to run tests when there is more than one applicable eligible object #247

Open lmserrano opened 3 years ago

lmserrano commented 3 years ago

Problem

When there is more than one object in the project/module's test/scala sources, when using IntelliJ to run the unit tests, the operation will fail with the plugin claiming that it is Unable to find the spec class name in the command-line args..

Steps to reproduce:

  1. Create a new project with the ZIO IntelliJ Plugin (using zioVersion = 1.0.4-2).
  2. Add "dev.zio" %% "zio-test-sbt" % zioVersion % Test to the list of default generated libraryDependencies.
  3. Add an object similar with one of the suggested examples in the ZIO webpage - How to - Running Tests, as follows:

    import zio.test._
    import zio.clock.nanoTime
    import Assertion._
    
    object DemoZioTestSuite extends DefaultRunnableSpec {
      val suite1 = suite("suite1") (
        testM("s1.t1") {assertM(nanoTime)(isGreaterThanEqualTo(0L))},
        testM("s1.t2") {assertM(nanoTime)(isGreaterThanEqualTo(0L))}
      )
    
      val suite2 = suite("suite2") (
        testM("s2.t1") {assertM(nanoTime)(isGreaterThanEqualTo(0L))},
        testM("s2.t2") {assertM(nanoTime)(isGreaterThanEqualTo(0L))},
        testM("s2.t3") {assertM(nanoTime)(isGreaterThanEqualTo(0L))}
      )
    
      val suite3 = suite("suite3") (
        testM("s3.t1") {assertM(nanoTime)(isGreaterThanEqualTo(0L))}
      )
    
      def spec = suite("All tests")(suite1, suite2, suite3)
    }
  4. In IntelliJ, right-click the project (or project module) and click Run ZIO tests in <project/module-name> to run all its tests. It will work.
  5. Add another test object, similar with the previous one, just with a different name.
  6. Repeat step 3. and attempt to run all the tests. The operation will fail because it is not capable of identifying which tests to run. The error message is as follows:

    Testing started at 23:31 ...
    Unable to find the spec class name in the command-line args.
    Make sure at least one fully-qualified class name was passed with the -s [fqn] parameter.
    If you believe this is a bug, please report it to the ZIO IntelliJ plugin maintainers.
    
    Process finished with exit code -1

Versions

lmserrano commented 3 years ago

Still facing this problem with current latest versions (ZIO 1.0.9, Scala 2.13.6, Java 16, IntelliJ 2021.1.2)

Current example:

import HelloWorld._
import zio._
import zio.console._
import zio.test.Assertion._
import zio.test.TestAspect.ignore
import zio.test._
import zio.test.environment._

import java.io.IOException

object HelloWorld {
  def sayHello: ZIO[Console, IOException, Unit] =
    console.putStrLn("Hello, World!")
  def sayGoodbye: ZIO[Console, IOException, Unit] =
    console.putStrLn("Goodbye, World!")
}

object HelloWorldSpec extends DefaultRunnableSpec {
  def spec = suite("HelloWorldSpec")(
    testM("sayHello correctly displays output") {
      for {
        _      <- sayHello
        output <- TestConsole.output
      } yield assert(output)(equalTo(Vector("Hello, World!\n")))
    },
    testM("sayGoodbye correctly displays output") {
      for {
        _      <- sayGoodbye
        output <- TestConsole.output
      } yield assert(output)(equalTo(Vector("Goodbye, World!\n")))
    }
  )
}

object HelloWorld2Spec extends DefaultRunnableSpec {
  def spec = suite("HelloWorldSpec2")(
    testM("sayHello correctly displays output") {
      for {
        _      <- sayHello
        output <- TestConsole.output
      } yield assert(output)(equalTo(Vector("Hello, FAILS World!\n")))
    },
    testM("sayGoodbye correctly displays output") {
      for {
        _      <- sayGoodbye
        output <- TestConsole.output
      } yield assert(output)(equalTo(Vector("Goodbye, World!\n")))
    } @@ ignore
  )
}

If I right click the project root and select the option to run all tests, it will return the same error message in the issue's description.

hmemcpy commented 3 years ago

Thanks for the report. I'll try to figure it out soon.... sorry for the trouble!