-
Notifications
You must be signed in to change notification settings - Fork 167
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
Add shrinking indication parameter #232
base: master
Are you sure you want to change the base?
Conversation
Thanks for your PR. However, I do not understand what it does, at least on its own. If this is a stand-alone PR, please supply some test cases that show its intended use and/or functionality (perhaps in conjunction with the On the other hand, if this supposed to be just supporting functionality for #230, then please add the changes there. |
It introduces a parameter (as in
This PR can be viewed as part for #230, but for that specific cases mentioned there, it would be sufficeable to just use the
It is a fact, that I intend to use this in PropCheck (Elixir wrapper library for PropEr) to suppress output while in shrinking stage, as mentioned in commit message as an example. But unfortunately, even though EUnit captures test's output, I couldn't find any way to match on it. And there isn't any other test that tests |
Yes, I could see that. My question was asking for an example that shows how/where this new functionality would be used. I.e., some evidence why would one want that in PropEr.
First of all, PropEr has a But it seems that you do not want that -- if I understand correctly, you want to suppress printing just while shrinking. The -module(on_out).
-export([test/1, print_magenta/2, print_not_during_shrinking/2]).
-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").
test(Fun) ->
proper:quickcheck(prop_me_up_scotty(), [{on_output, Fun}]).
print_magenta(S, L) ->
io:format("\033[1;35m"++S++"\033[0m", L).
-define(WHATEVER_YOU_DESIRE, no_printing_during_shrinking_please).
print_not_during_shrinking(S, L) ->
case get(?WHATEVER_YOU_DESIRE) of
undefined ->
case string:find(S, "Shrinking") of
nomatch -> io:format(S, L);
_ -> put(?WHATEVER_YOU_DESIRE, in_shrinking_phase)
end;
in_shrinking_phase ->
case string:find(S, "time(s)") of
nomatch -> ok; % no printing during shrinking
_ -> erase(?WHATEVER_YOU_DESIRE) % shrinking just ended
end
end.
prop_me_up_scotty() ->
?FORALL(I, integer(), I < 42). Here is what I get when using it -- colors are not shown properly here: Eshell V10.3.4 (abort with ^G)
1> on_out:test(fun on_out:print_magenta/2).
..............................................................!
Failed: After 63 test(s).
47
Shrinking .(1 time(s))
42
false
2> on_out:test(fun on_out:print_not_during_shrinking/2).
.............................................................!
Failed: After 62 test(s).
114
42
false If you want something other/more than the above, please supply an example. |
Nope 😁 While this would work for some cases, it wouldn't work for all. It fails if for example, while shrinking, a more complex test would return a non boolean, or a Also, it isn't an optimal solution to depend on quasi-syntax of output for semantics and inferring the internal state of PropEr. Not a one I would feel comfortable to put in a PropCheck library. |
I do not understand how telling PropEr to not do any shrinking at all can result in failing during shrinking... Unless of course you are replying in another part of the above message. |
Let me rephrase that. I didn't wanto to quote the code example. |
Can you please not edit / change the messages you have written, thus making the discussion here unreadable for future readers? More importantly, can you please provide some example of what you really want to do and show me/us why you cannot achieve that with the machinery ( Adding stuff to the process dictionary, besides being ugly, may complicate other PropEr efforts that are currently going on. For example, the parallelization work. |
So usecase is to reduce noisy printing in PropCheck by stop PorpEr from printing while shrinking. This can't be done with This can't be done with
Do note, that I'm not introducing any new process dictionary keys, but reusing the existing one, which is set by |
Set's a `shrinking` parameter to `true` when property is being executed during a shrinking phase. Also sets it to `done` after the shrinking is done. Useful for adjusting generators during shrinking phase or for `on_output` printers.
67faa71
to
ca41234
Compare
Codecov Report
@@ Coverage Diff @@
## master #232 +/- ##
==========================================
+ Coverage 82.24% 83.04% +0.79%
==========================================
Files 13 13
Lines 3166 3167 +1
==========================================
+ Hits 2604 2630 +26
+ Misses 562 537 -25
Continue to review full report at Codecov.
|
I've given the issue some more thought and I am still not convinced that this is the PropEr(TM) solution to this particular use case. To control the amount of printing that users see, PropEr currently provides options My suggestion would be to extend the options with something along the lines of -type phase() :: testing | shrinking.
-type phase_output() :: {phase(), quiet | laconic | verbose | output_fun()}. which also allows users to supply their own output functions for the two different phases, if they so wish. For the Comments? |
I like your proposal! I like the idea of exposing phase instead of just |
NOTE: I've slightly edited the above comment and moved a part which is related to a different issue (#246) so that it can be discussed on its own. |
I came here to discuss slightly different use case but at the end I think it's very much related. In my property test I'm constructing huge terms which produce a lot of noise when printed out by PropEr on assertion failure. So I would like to disable printing of these generated terms while keeping the other PropEr output. I can imagine that there could be some new formatting option similar to existing
where
In my case I would then pattern match on test_input to ignore it while printing everything else. What do you think? Is my way somehow aligned with the use case of @x4lldux ? |
Set's a
shrinking
parameter totrue
when property is being executedduring a shrinking phase. Then sets it to
done
after the shrinking isfinished. Useful for adjusting generators during shrinking phase or for
on_output
printers, for example, so they can suppress printing.