Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dkarlinsky
Copy link
Contributor

@dkarlinsky dkarlinsky commented Sep 26, 2019

New method Spec.only(), that when applied on a suite will ignore all tests that don't have the given substring in their label.
Requires evidence that L to be String and the Spec is ZSpec

Example:

import zio.test.TestOnly._
suite("suite")(
    test("test1") {
      assert(1, equalTo(1))
    },
    test("test2") {
      assert(1, equalTo(1))
    }
  ).only("test2") 

This requires an outer suite to be marked with @@ thisOnlySupport.
Or TeatAspects.runOnlySupport needs to be added to default aspects.

To make this work I had to add a notion of tags to TestCase

@adamgfraser WDYT?

@jdegoes
Copy link
Member

jdegoes commented Sep 26, 2019

I understand this is a useful scenario to support, I think we should reflect on how we can do this (and if we can, in the right way now), since in this design we cannot enforce the "outer suite" requirement.

@adamgfraser
Copy link
Contributor

adamgfraser commented Sep 26, 2019

One idea I had is once we get effectual suites in perhaps we can have a function like:

def testOnly[R, E, L, T](f: TestAspectPoly => Spec[R, E, L, T]): Spec[R, E, L, T] = {
  val specs = for {
    ref <- Ref.make[Vector[Spec[R, E, L, T]]
    only = new TestAspectPoly { ... }  // TestAspect that adds any tests it is called on to the ref
    _ <- f(only)
    specs <- ref.get
  } yield specs
  Spec.suite("Only", specs, None)

Then you could use it like:

testOnly { only =>
  suite("MySuite")(
    test1,
    test2 @@ only,
    test3
  )
}

@jdegoes
Copy link
Member

jdegoes commented Sep 28, 2019

@adamgfraser Yes, that's a much better API! It should work for now, and we can think about whether to do this with annotations later.

@adamgfraser
Copy link
Contributor

@dkarlinsky We just merged #1664 which makes suites effectual so I think now we really have the tools to implement your idea. Do you want to rework this PR along the lines I suggested? Would be great to get some feedback on working with the new effectual suites functionality and I think this would be a nice feature to have.

@dkarlinsky
Copy link
Contributor Author

dkarlinsky commented Oct 4, 2019 via email

@adamgfraser
Copy link
Contributor

@dkarlinsky Sounds good. No rush. Enjoy your vacation!

@dkarlinsky
Copy link
Contributor Author

dkarlinsky commented Oct 4, 2019 via email

@jdegoes
Copy link
Member

jdegoes commented Oct 25, 2019

I will close this, @dkarlinsky, feel free to re-open when you have time to add this great feature!

@jdegoes jdegoes closed this Oct 25, 2019
@dkarlinsky
Copy link
Contributor Author

@jdegoes Back from vacation (landed yesterday) and now ready to give this another shot :)
Looks like I don't have permissions to reopen the PR, though...

@jdegoes jdegoes reopened this Oct 26, 2019
@jdegoes
Copy link
Member

jdegoes commented Oct 26, 2019

Done!

@dkarlinsky
Copy link
Contributor Author

dkarlinsky commented Oct 27, 2019 via email

@dkarlinsky dkarlinsky changed the title #1790 - A test annotated with @@ thisOnly, will be the only one that runs #1790 - A suite annotated with .only('some-label), will ignore all non matching labels Nov 3, 2019
@dkarlinsky dkarlinsky changed the title #1790 - A suite annotated with .only('some-label), will ignore all non matching labels #1790 - A suite annotated with .only("some-label"), will ignore all non matching labels Nov 3, 2019
Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice progress on this. I left some comments below. I think we can both improve the ergonomics of this and simplify the implementation a lot by using filterLabels and either calling toString on the labels or requiring evidence that they are already strings so we can do a substring search on them. This will also make the API consistent with what we are doing in the SBT test runner for "only".

@dkarlinsky dkarlinsky force-pushed the 1790-only branch 2 times, most recently from a126bd8 to fb0c0cc Compare November 8, 2019 18:53
Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor comments. Excited to get this in!

@adamgfraser
Copy link
Contributor

@dkarlinsky We merged #2192 which created the same test file and is creating a merge conflict. Should be easy to drop your tests in.

Now `.only(labelFilter)` can be added to a suite.
If no matching labels are found, the test fails with exception.
* `.only()` will only work on ZSpec with L <: String.
* Using `filterLabel()`.
* Moved `only()` method into Spec (no longer an extension method)
Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@adamgfraser adamgfraser merged commit a2ac67f into zio:master Nov 12, 2019
@dkarlinsky dkarlinsky deleted the 1790-only branch November 12, 2019 18:52
Twizty pushed a commit to Twizty/zio that referenced this pull request Nov 13, 2019
…all non matching labels (zio#1838)

* Rewrote the whole thing.
Now `.only(labelFilter)` can be added to a suite.
If no matching labels are found, the test fails with exception.

* Fixing method overloading issue in dotty, by renaming the offending method

* added scala docs

* Simplified implementation.
* `.only()` will only work on ZSpec with L <: String.
* Using `filterLabel()`.
* Moved `only()` method into Spec (no longer an extension method)

* Moved test to the newly created `SpecSpec`

* adapting to ZSpec changes

* scalafmt

* minor fixes, based on PR comments

* some more minor fixes, based on PR comments
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

Successfully merging this pull request may close these issues.

3 participants