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

Cannot get rich filtering capabilities example working #62

Closed
MrPowers opened this issue Mar 7, 2020 · 7 comments
Closed

Cannot get rich filtering capabilities example working #62

MrPowers opened this issue Mar 7, 2020 · 7 comments

Comments

@MrPowers
Copy link

MrPowers commented Mar 7, 2020

I am really excited about the rich filtering capabilities!

Here's the example on the website that I cannot get working:

import scala.util.Properties
import munit._
object Windows213 extends Tag("Windows213")
class MySuite extends FunSuite {
  // reminder: type Test = GenericTest[Any]
  override def munitNewTest(test: Test): Test = {
    val isIgnored =
      options.tags(Windows213) && !(
        Properties.isWin &&
        Properties.versionNumberString.startsWith("2.13")
      )
    if (isIgnored) test.withBody(() => Ignore)
    else test
  }

  test("windows-213".tag(Windows213)) {
    // Only runs when operating system is Windows and Scala version is 2.13
  }
  test("normal test") {
    // Always runs like a normal test.
  }
}

Changing from options.tags to test.tags solves one of the errors (please confirm this fix is correct).

The if (isIgnored) test.withBody(() => Ignore) line is still erroring out with this message:

[error] /Users/powers/Documents/code/my_apps/munit-example/src/test/scala/com/github/mrpowers/munit/example/RichFiltersSpec.scala:16:40: type mismatch;
[error] found : munit.Tag
[error] required: MySuite.this.TestValue
[error] (which expands to) scala.concurrent.Future[Any]
[error] if (isIgnored) test.withBody(() => Ignore)
[error] ^
[error] one error found
[error] (Test / compileIncremental) Compilation failed

Thanks for building this awesome library!

@olafurpg
Copy link
Member

olafurpg commented Mar 8, 2020

Thank you for reporting! The example from the blog post has stopped working since the v0.5 release when all internals became async. I opened #63 fixing the code example from the blog post and improved the UX around how the Ignore tag is handled. The filtering example with the next release is like this

  override def munitNewTest(test: Test): Test = {
    val isIgnored =
      test.tags(Windows213) && !(
        Properties.isWin &&
        Properties.versionNumberString.startsWith("2.13")
      )
    if (isIgnored) test.tag(Ignore)
    else test
  }

@olafurpg olafurpg closed this as completed Mar 8, 2020
@MrPowers
Copy link
Author

MrPowers commented Mar 8, 2020

@olafurpg - thanks for the response!

I tried out your code snippet and it's not working as expected. Here is the code I am running.

When I run testOnly com.github.mrpowers.munit.example.MySuite, I expect the windows-213 test to get skipped because I am using Scala 2.12 and macOS, but it looks like it is still getting run.

Screen Shot 2020-03-08 at 11 53 06 AM

Properties.isWin and Properties.versionNumberString.startsWith("2.13") are both false.

Is test.tag(Ignore) working or am I missing something? Sorry in advance if I am doing something silly here!

@olafurpg
Copy link
Member

olafurpg commented Mar 8, 2020

It's expected the code snippet doesn't work with the current version of Metals but it will work with the next version after the fixes in #63 are released

@olafurpg
Copy link
Member

olafurpg commented Mar 8, 2020

I'm preparing another change I would like to include in the next release as well

@MrPowers
Copy link
Author

MrPowers commented Mar 8, 2020

@olafurpg - awesome, thanks for clarifying (I should have seen that in your original message).

This rich filtering options is so awesome - keep up the great work!

@olafurpg
Copy link
Member

@MrPowers I opened #64 to (hopefully) simplify how to customize filtering and evaluation of tests. The code example from the blog post would become this instead

import scala.util.Properties
import munit._
object Windows213 extends Tag("Windows213")
class MySuite extends FunSuite {
  override def munitTestTransforms = super.munitTestTransforms ++ List(
    new TestTransform("Windows213", { test =>
      val isIgnored =
        test.tags(Windows213) && !(
          Properties.isWin &&
            Properties.versionNumberString.startsWith("2.13")
        )
      if (isIgnored) test.tag(Ignore)
      else test
    })
  )

  test("windows-213".tag(Windows213)) {
    // Only runs when operating system is Windows and Scala version is 2.13
  }
  test("normal test") {
    // Always runs like a normal test.
  }
}

A TestTransform is a Test => Test function that can for example add tags like Ignore. There is also SuiteTransform which is a List[Test] => List[Test] to filter tests from a suite.

I'm curious to hear your thoughts if this new API makes sense?

@MrPowers
Copy link
Author

@olafurpg - I updated my blog post to reflect the latest API.

I will email you so we can brainstorm how to market this feature! This functionality will be really useful for the Spark community!

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

2 participants