typelevel / typelevel/weaver-test

Initialization bug with helpers over `test`

Open
#82 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
85
Forks
15
PR merge metrics
No merged PRs in 30d

Description

This issue was copied over from: https://github.com/disneystreaming/weaver-test/issues/705
It was opened by: BalmungSan


I found a strange issue with weaver around initialization... or at least that is what I think.
It is a bit involved but hopefully, I can provide enough info for someone to take a look.

// First, we need a base Suite with a bunch of helpers:
trait FooBaseSuite extends IOSuite:
  override final val maxParallelism: Int = 1
  override final type Res = FooRes
  override final val sharedResource: Resource[IO, Res] = ???

  // Define helper method to reduce boilerplate:
  protected def fooTest(name: String)(check: Foo => Expectations): Unit =
    test(name) { foo =>
      IO(check(foo))
    }

// Then we need an object that extends such base Suite:
object FooSpec extends FooBaseSuite:
  // And use the helper method:
  fooTest(name = "Testing foo") { foo =>
    expect(...)
  }

The tests will fail because Foo is already closed (or so I think).

There are a couple of ways to fix the issue:

  1. Don't have a trait + object but just a single object
  2. Remove the fooTest helper and replicate the boilerplate in each test
  3. Make FooSpec a class which accepts an (unused) GlobalRead

Things that didn't work:

  • Using abstract class rather than trait
  • Moving fooTest from the trait (FooBaseSuite) to the object (FooSpec)

More info:

  • Scala 3.3.1
  • weaver: 0.8.3
  • cats-effect: 3.5.1
  • sbt: 1.9.6
  • Java: GraalVM CE 17.0.8
  • OS: Mac 14.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named; start by reproducing the FooBaseSuite/FooSpec example with Scala 3.3.1, weaver 0.8.3, and cats-effect 3.5.1. Trace IOSuite initialization and resource lifetime around helper-registered tests, then verify that Foo remains usable and add a regression test for the trait/object case.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.