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

Global resource tests not running on Mill #113

Closed
RobinJDCox opened this issue Oct 26, 2020 · 3 comments
Closed

Global resource tests not running on Mill #113

RobinJDCox opened this issue Oct 26, 2020 · 3 comments

Comments

@RobinJDCox
Copy link
Contributor

I'm having some trouble using global resource tests and I'm using Mill. This problem occurs with the latest version of Weaver (0.5.0).

If I define the following tests then neither of the two examples get run. I'm using ZIO, but have included both examples as I originally thought I'd done the Cats/ZIO interop wrong in the first example!

When running my tests, the test output prints the following which indicates that the BasicGlobalInit gets run but not the actual tests that are using it.

It feels like this might be a problem specifically when running on Mill, but I've not confirmed that.

Thanks

Test Output

Shared resource create
done?

Example

import cats.effect.{IO => CatsIO, Resource}
import weaver._
import weaver.ziocompat._
import zio._
import zio.interop.catz._

object BasicGlobalInit extends GlobalResourcesInit {

  def sharedResources(store: GlobalResources.Write[CatsIO]): Resource[CatsIO, Unit] = {
    println("Shared resource create")
    for {
      foo <- Resource.pure[CatsIO, String]("hello world!")
      _   <- store.putR(foo)
    } yield println("done?")
  }
}

class ZIOGlobalExample(globalResources: GlobalResources) extends ZIOSuite[Has[String]] {

  println("ZIO")

  override val sharedLayer: ZLayer[ZEnv, Throwable, Has[String]] =
    ZLayer.fromManaged {
      globalResources.in[CatsIO].getOrFailR[String]().toManaged
    }

  test("example") {
    ZIO.access[Has[String]](_.get).map { s =>
      expect(s == "hello world!")
    }
  }
}

class CatsGlobalExample(globalResources: GlobalResources) extends IOSuite {

  println("Cats")

  type Res = String
  override def sharedResource: Resource[CatsIO, Res] =
    globalResources.in[CatsIO].getOrFailR[String]()

  test("example") { s =>
    CatsIO { expect(s == "hello world!") }
  }
}
lefou pushed a commit to com-lihaoyi/mill that referenced this issue Oct 27, 2020
This PR removes a filter from the test discovery that ignores classes that have parameters in their constructor. I think this is problematic as it is perfectly valid for tests to have constructor parameters depending on the test framework, and so this should be a decision made by the testing framework rather than the build tool.

Here's an example where I encountered this issue recently: disneystreaming/weaver-test#113. After running these tests again with the changes made in this PR the example tests shown in that issue now pass.

I've attempted to verify that these changes are compatible with other test frameworks. With some fairly basic examples uTest and Scalatest both seem to continue to work as expected. I'd be happy to verify the changes against other test frameworks if you have any further suggestions.

Commits:

* Add VS Code to gitignore

* Remove constraint for parameter count

Pull request: #982
@keynmol
Copy link
Collaborator

keynmol commented Oct 28, 2020

@RobinJDCox did this end up being a Mill issue or still a weaver issue? Looking at the wording of your PR in Mill it seems like this should resolve with next release of Mill?

@Baccata
Copy link
Contributor

Baccata commented Oct 28, 2020

@keynmol this is a mill issue. We can close this.

@Baccata Baccata closed this as completed Oct 28, 2020
@RobinJDCox
Copy link
Contributor Author

Yep, the Mill PR got merged which resolved my issue. Just waiting for the next release! 🙂

Thanks guys

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

No branches or pull requests

3 participants