-
Notifications
You must be signed in to change notification settings - Fork 71
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
Disabled Extensions #1
Comments
👍 In case you're not aware of it, Spring 5 milestones already support |
Thanks for the hint (links: Regarding generalizations, I was exploring ideas to get the compiler to check conditions. But I'll start with the simple cases... |
You're welcome.
Sure. I wasn't implying that you should re-implement or copy them. Rather, I meant for them to serve as possible inspiration. Although supporting an expression language of any sort in core JUnit would naturally require the EL implementation to be an optional dependency. Anyway, just food for thought.
Can you expound on that? |
Spawned #2 and added as a task to the issue description. |
Spawned #3 to continue discussion about generalized conditions there. |
A |
Good point about the Java version, I added an item to the checkbox list in the issue description. |
My knowledge of annotations is pretty limited, so I've no idea if what I'm going to suggest is even feasible, but here goes! How about a |
@jbduncan: I considered something like that and was halfway done implementing it when I realized that annotations can only use constants as fields. Now I'm toying with the though to name a static field that us a |
@smoyer64 [wrote]:
That is excellent! As you can see above (particularly here) I started on the specific end but planned to go that very direction. I did some experiments and also tried to support predicates. I failed to find a way around the fact that you can not define a lambda as an annotation argument and found no other solution I immediately liked. I'm curious to see which way you went. |
Just had this idea: An enabled/disabled extension with which you can form Boolean formulas over existing extensions: |
You can't put the code for a lambda in an annotation but you can put the
name of a class that implements predicate ... your example is a bit harder
as a repeatable annotation would effectively be an or (but you're still
using classes to specify the predicates.
On Jul 2, 2017 10:04 AM, "Nicolai Parlog" <notifications@github.com> wrote:
Just had this idea: An enabled/disabled extension with which you can form
Boolean formulas over existing extensions:
@DisabledIf(and(EnabledOnLinux.class,
DisabledOnJava9.class)).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAUCje20kzybW6W1lGSni8Sxqdeojn8Vks5sJ6NcgaJpZM4K3Xjs>
.
|
@nicolaiparlog I've committed the POC code I had for |
Hi @smoyer64 As @sbrannen mentioned, spring already uses So, just IMO for junit-pioneer, naming |
I'm afraid that multiple projects in this world will come up with an annotation named TBH, I tried to come up with a better name for Spring, but in the end I figured So I think the conflicts are unavoidable. In any case, it's definitely something to keep in mind. |
@nicolaiparlog, FYI: there's been a very simplistic PoC for a system property condition here for quite some time. That also serves as a PoC for an environment variable condition. Of course, I'd come up with a better name than |
@ttddyy - I think the name is apropos of its function and don't mind that it collides. There's a large population of JUnit users that doesn't use Spring and some words are just right - even early versions of the JDK had java.util.Date and java.sql.Date. I've also got a set of temporal conditions that are tentatively using Unfortunately, naming is hard - I do like the fact that the Spring version accepts EL and that was something I was considering after Java 9 (we should be able to |
Yep.... that will be the real challenge! Because... with SpEL support in Spring's @EnabledIf(expression = "#{systemProperties['os.name'].toLowerCase().contains('mac')}", reason = "Enabled on Mac OS") |
I wonder if something similar to how Incomplete code below, but would allow for the solution up above (I think) as well as other possible implementations (System property, environment variable, etc.): public class DisabledIfConditionalExecution implements ExecutionCondition {
@Override
ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
// ...
}
}
public @interface DisabledIf {
}
public @interface DisabledIfSource {
Class<? extends DisabledIfProvider> value();
}
public interface DisabledIfProvider {
boolean isDisabled(ExtensionContext context);
}
@DisabledIfSource(DisabledIfSpelProvider.class)
@interface DisabledIfSpel {
String expression();
String reason();
}
class DisabledIfSpelProvider implements DisabledIfProvider {
boolean isDisabled(ExtensionContext context) {
// ...
}
}
class MyTest {
@DisabledIfSpel(expression = "#{systemProperties['os.name'].toLowerCase().contains('mac')}", reason = "Enabled on Mac OS")
void myTest() {
}
} |
Related to junit-team/junit5#219 as well. |
For the record and some-what related to this initial pioneer issue: there's a new label for "pioneer" ideas at https://github.com/junit-team/junit5/issues?q=is%3Aissue+is%3Aopen+label%3A%223rd-party%3A+pioneer%22 -- tagging issues that may be interesting for @junit-pioneer |
@sormuras Can you take a look at my initial bullet point list and tell us which ideas Jupiter already |
I'm not @sormuras, but I'll update this issue's description to check off what's already covered. 😉 |
done |
@DisabledOnOs was superseeded my more extensive @disabled... support in Jupiter. It can hence be removed from Pioneer.
@DisabledOnOs was superseeded my more extensive @disabled... support in Jupiter. It can hence be removed from Pioneer.
@nicolaiparlog The conditional disabling of tests was something we were both working in before joining forces - there's a @DisableRest in the portion of selesy/junit-extension I had asked you to review a while ago (https://github.com/selesy/junit5-extensions/tree/develop/junit5-extensions-disable-rest-extension/src/main/java/com/selesy/testing/junit5/extensions/disable/rest). Will this satisfy the "disable all but one" criteria? It's a bit more than that because if you annotate (e.g.) two of ten tests they'll both run. I should also note that I don't really like the name - Rest is not REST but Roy Fielding has effectively defined the meaning of that word for developers. Perhaps @DisableOthers? |
In the Javascript frameworks I‘ve used that‘s usually called |
Opened #71 for |
At least the last two items from the opening post still sound interesting to me. If anybody else shares that, PRs are welcome. :) |
@mkobit I never replied to your proposal above. I liked the idea a lot and was about to create an issue for it when I was pointed at Jupiter's custom conditions, which provide all the features your proposal does. Main difference: Jupiter's solution is a bit simpler, but yours is type safe and survives refactorings. I don't think that's enough to warrant our own implementation, so I won't create that issue. |
As I see it, we've covered all ideas in this issue, so we can finally close it. 🥳 |
There are many possible ideas floating around the
@Disabled
annotation:@EnabledIf
and@DisabledIf
in Jupiter 5.1@EnabledOnOs
and@DisabledOnOs
in Jupiter 5.1@EnabledOnJre
and@DisabledOnJre
in Jupiter 5.1@EnabledIfSystemProperty
and@DisabledIfSystemProperty
in Jupiter 5.1@EnabledIfEnvironmentVariable
and@DisabledIfEnvironmentVariable
in Jupiter 5.1@DisabledUntil
(comment in #219) ~> Create @DisabledUntil #366It is conceivable to create a universal
@DisabledIf
annotation that covers all of these cases but instead of going there from the outset, it might make more sense to tackle individual use cases first and look for room for generalization later.The text was updated successfully, but these errors were encountered: