-
Notifications
You must be signed in to change notification settings - Fork 10
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
Print runnable scenario in case of test failure #204
Print runnable scenario in case of test failure #204
Conversation
0d75a32
to
efddee7
Compare
Nice work Nicolas 😃🎉 I particularly liked the (aligned) I suppose we could save a few characters (the shorter output the better IMO) by using
As a runnable program, the example seems to place itself between two chairs.
Short-circuit booleans means the underlying QCheck property always stops at the first model-mismatch.
These are just my immediate thoughts, YMMV. 🤷 |
Sorry if this didn't come across clearly above: |
a39c209
to
25a80af
Compare
Thank you for your comments :-) I've modified the PR so that it includes an Regarding the use of an That simply means that we can't guarantee to the user that we output a failing scenario for a failing test. |
25a80af
to
b7af91c
Compare
7503aed
to
b59417f
Compare
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 must say this took quite some time to review, maybe some comments could help.
I wrote my comments on specific lines except for:
- commit “Print cmds with their sut argument”: the message could mention that it also adds
open X
at the beginning of the generated log - commit “Collect term containing a computation of the returned value”: I must admit I had to read the code to understand the commit message; I would suggest adding a small comment to the function
returned_value
(maybe it would be better namedreturned_value_specification
?)
plugins/qcheck-stm/src/stm_of_ir.ml
Outdated
match (ty.ptyp_desc, args) with | ||
| Ptyp_arrow (_, l, r), xs when Cfg.is_sut config l -> | ||
let* fmt, pps = aux r xs in | ||
ok ("%s" :: fmt, estring "sut" :: pps) |
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.
If fmt
directly contained sut
instead of %s
, we could keep pp_args
unchanged.
On the other hand, maybe your proposition is an altogether better approach, to build fmt
and pp_args
at the same time.
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.
We can indeed spare the %s
and estring "sut"
| _, [] -> ok ([], []) | ||
| _, _ -> | ||
failwith | ||
"shouldn't happen (list of arguments should be consistent with \ |
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 wonder if we shouldn’t create an error value ShouldNotHappen
(in a separate PR if at all), as it appears in many already monadic contexts.
plugins/qcheck-stm/src/stm_of_ir.ml
Outdated
in | ||
let ty_show = to_option @@ exp_of_core_type value.inst ty_ret in | ||
match (ty_show, ret_val) with | ||
| Some ty_show, Some ret_values -> |
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.
ret_values
: this is not a list, shouldn't this be singular?
ok @@ esome dummy | ||
| Some e -> ok @@ esome e | ||
in | ||
let wrap_check ?(normal = false) t e = |
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.
What does normal
really mean here? I see it set to true
for (normal) postconditions and invariants, but anyway, I don’t have a clear understanding of the impact of setting it to 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.
I've added some comments to explain.
Thanks!
This allow to output a runnable scenario in case of test failure. The runnable scenario will be of the form: ```ocaml open Module_under_test let sut = init_sut ... ```
These descriptions will be used to print the expected behaviour when possible. Functions returning tuples are still not supported, but in the same way that we've prepared the way by storing a list a returned values, we store a list of list of computation of returned value.
bb5ccb9
to
38e396c
Compare
Also adapt the runtime so that the commit build. When a returned value can't be computed based on the information contained in the Gospel specification, a warning is displayed to the user at generation and a dummy one is placed to inform the message printer that the expected returned value is unknown.
38e396c
to
3c1d638
Compare
Green light to merge has been given in another chat. |
This PR is the continuation of, and is based on, #202.
Please consider only the six last commits.
This PR makes the failure message print a runnable scenario with information about returned and expected values.
It uses the same mechanism as introduced in #202 for communicating with
Qcheck.fail_reportf
.For printing the commands with their
sut
argument in the right place, only the generatedshow_cmd
has been modified.Printing the user-provided value for
init_sut
is quite straightforward, we just have to pass the information to the runtime.Printing the expected value is a bit more complicated.
First, we look at the Gospel specifications to see if there is enough information to compute the expected returned value (some functions may be specified in a way that their contract doesn't include a computation of the returned value).
If there is, we wrap this value in a
STM.res
type and send it to the runtime throughortac_postond
along all the other information.It there is not, we send a
dummy
value, to inform the printer that the expected returned value is unknown.A warning will be displayed to the user in the second case, but this will not affect whether the function is tested or not.
This PR only deals with normal behaviour, meaning that the excpetional branches in
ortac_postond
don't send an expected returned value to the runtime for now.I believe that handling exceptional behaviour can be done in another PR (this is me trying to keep PRs short).
The
ortac_runtime
now handle this extra information to print a runnable scenario to the user in case of test failure.For now, I've made the choice to print the function calls in an
ignore
and to print the returned value and the optional expected returned value in comments.We've discussed elsewhere about placing the function calls in an
assert
, but we don't always have an expected returned valueIf we introduce a bug in
plugins/qcheck-stm/test/array.ml
, we have now: