-
Couldn't load subscription status.
- Fork 1.4k
MutableRunnableSpec #4523
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
MutableRunnableSpec #4523
Conversation
|
I removed type parameters from the Because it needed me to do casting and existential types. And even if someone would like to provide some R he would need to do casting himself, so no typesafety. To have If you know of any better approach let me know. Another safe option would be to have add type params to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. As you say, the biggest issue is providing the environment. Since suite, test, and testM now perform the side effect of adding to the spec we need whatever we are adding to have the right environment type at the time we add it, which means it is difficult for us to implement operators that provide the environment.
| def label: String | ||
| } | ||
|
|
||
| case class SuiteBuilder(label: String) extends SpecBuilder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final or at least sealed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made them just sealed. It is fine to have them inside MutableRunnableSpec not to pollute zio.test package and I can also use type parameters from MutableRunnableSpec and do not need to add them to *Builder classes. If I make them final, I get this compilation error The outer reference in this type test cannot be checked at run time.
| * } | ||
| * }}} | ||
| */ | ||
| class MutableRunnableSpec[R <: Has[_]](layer: ZLayer[TestEnvironment, Throwable, R]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some overlap here with what Balasz is doing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I will speak with him. Maybe renaming would be good to call this
DefaultMutableRunnableSpec -> MutableRunnableSpec
DefaultMutableRunnableSpec -> CustomMutableRunnableSpec
to have it consistent. What do you think? @jdegoes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe so.
| } | ||
|
|
||
| final override def spec: ZSpec[Environment, Failure] = { | ||
| testRunning = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not quite correct. When spec is called, the effect is constructed, but it may not be run then (or ever). What you could do is attach a @@ before annotation to the spec which sets testRunning = true inside there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right 👍 The effect is not run but is already constructed. For me it is enough so I just renamed the variable to specBuilt. After that point no test method should be called to prevent test in test errors. I can not test it with stact because assertion to test is call by name final def test(label: String)(assertion: => TestResult): TestBuilder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am good to merge if @adamgfraser is good. Thanks for your work on this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Fixing issue #4518
I was trying to do it without so many
instanceOfbut couldn't find a way.If we have the same parameter types on the methods in
SpecBuilderas inSpecwill have type safety in subsequent calls on theSpecBuilder. Is it enough?Should I add also proving of environments? And do we want to have typesafety there (that all tests have environment which is supertype of the suite's environment)?