Skip to content

Commit

Permalink
Add an assert for exceptional behaviour in scenario
Browse files Browse the repository at this point in the history
Collect the name of the exception when checking an exceptional
postcondition (not the arguments as they are not always specified).
  • Loading branch information
n-osborne committed Mar 14, 2024
1 parent 828e11f commit 5f0d547
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 124 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

- Improve test-failure message
[\#202](https://github.com/ocaml-gospel/ortac/pull/202) and
[\#204](https://github.com/ocaml-gospel/ortac/pull/204)
[\#204](https://github.com/ocaml-gospel/ortac/pull/204) and
[\#206](https://github.com/ocaml-gospel/ortac/pull/206)
- Add a comment warning that the file is generated
[\#198](https://github.com/ocaml-gospel/ortac/pull/198)
- Add support for type invariants
Expand Down
20 changes: 10 additions & 10 deletions examples/lwt_dllist_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ let ortac_postcond cmd__005_ state__006_ res__007_ =
else
Some
(Ortac_runtime.report "Lwt_dllist_spec" "create ()"
(Some (Res (Ortac_runtime.dummy, ()))) "is_empty"
(Either.right (Res (Ortac_runtime.dummy, ()))) "is_empty"
[("b <-> s.contents = Sequence.empty",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -386,7 +386,7 @@ let ortac_postcond cmd__005_ state__006_ res__007_ =
else
Some
(Ortac_runtime.report "Lwt_dllist_spec" "create ()"
(Some (Res (Ortac_runtime.dummy, ()))) "length"
(Either.right (Res (Ortac_runtime.dummy, ()))) "length"
[("l = Sequence.length s.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -444,7 +444,7 @@ let ortac_postcond cmd__005_ state__006_ res__007_ =
else
Some
(Ortac_runtime.report "Lwt_dllist_spec" "create ()"
(Some (Res (Ortac_runtime.dummy, ()))) "take_l"
(Either.right (Res (Ortac_runtime.dummy, ()))) "take_l"
[("if old s.contents = Sequence.empty\n then false\n else a = Sequence.hd (old s.contents)",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -496,8 +496,8 @@ let ortac_postcond cmd__005_ state__006_ res__007_ =
then None
else
Some
(Ortac_runtime.report "Lwt_dllist_spec" "create ()" None
"take_l"
(Ortac_runtime.report "Lwt_dllist_spec" "create ()"
(Either.left "Empty") "take_l"
[("old s.contents = Sequence.empty = s.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -558,7 +558,7 @@ let ortac_postcond cmd__005_ state__006_ res__007_ =
else
Some
(Ortac_runtime.report "Lwt_dllist_spec" "create ()"
(Some (Res (Ortac_runtime.dummy, ()))) "take_r"
(Either.right (Res (Ortac_runtime.dummy, ()))) "take_r"
[("if old s.contents = Sequence.empty\n then false\n else a = (old s.contents)[Sequence.length (old s.contents) - 1]",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -610,8 +610,8 @@ let ortac_postcond cmd__005_ state__006_ res__007_ =
then None
else
Some
(Ortac_runtime.report "Lwt_dllist_spec" "create ()" None
"take_r"
(Ortac_runtime.report "Lwt_dllist_spec" "create ()"
(Either.left "Empty") "take_r"
[("old s.contents = Sequence.empty = s.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -664,7 +664,7 @@ let ortac_postcond cmd__005_ state__006_ res__007_ =
else
Some
(Ortac_runtime.report "Lwt_dllist_spec" "create ()"
(Some (Res (Ortac_runtime.dummy, ()))) "take_opt_l"
(Either.right (Res (Ortac_runtime.dummy, ()))) "take_opt_l"
[("old s.contents = match o with\n | None -> Sequence.empty\n | Some a -> Sequence.cons a s.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -716,7 +716,7 @@ let ortac_postcond cmd__005_ state__006_ res__007_ =
else
Some
(Ortac_runtime.report "Lwt_dllist_spec" "create ()"
(Some (Res (Ortac_runtime.dummy, ()))) "take_opt_r"
(Either.right (Res (Ortac_runtime.dummy, ()))) "take_opt_r"
[("old s.contents = match o with\n | None -> Sequence.empty\n | Some a -> Sequence.snoc s.contents a",
{
Ortac_runtime.start =
Expand Down
56 changes: 35 additions & 21 deletions examples/varray_circular_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec" "make 42 'a'"
(Some (Res (Ortac_runtime.dummy, ()))) "pop_back"
(Either.right (Res (Ortac_runtime.dummy, ())))
"pop_back"
[("if old t.contents = Sequence.empty\n then false\n else proj x = (old t.contents)[Sequence.length (old t.contents) - 1]",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -818,7 +819,7 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec" "make 42 'a'"
None "pop_back"
(Either.left "Not_found") "pop_back"
[("t.contents = old t.contents = Sequence.empty",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -876,7 +877,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec" "make 42 'a'"
(Some (Res (Ortac_runtime.dummy, ()))) "pop_front"
(Either.right (Res (Ortac_runtime.dummy, ())))
"pop_front"
[("if old t.contents = Sequence.empty\n then false\n else proj x = Sequence.hd (old t.contents)",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -929,7 +931,7 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec" "make 42 'a'"
None "pop_front"
(Either.left "Not_found") "pop_front"
[("t.contents = old t.contents = Sequence.empty",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -986,7 +988,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" None "insert_at"
"make 42 'a'" (Either.left "Invalid_argument")
"insert_at"
[("0 <= i <= Sequence.length t.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1049,7 +1052,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" None "insert_at"
"make 42 'a'" (Either.left "Invalid_argument")
"insert_at"
[("0 <= i <= Sequence.length t.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1098,7 +1102,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" None "pop_at"
"make 42 'a'" (Either.left "Invalid_argument")
"pop_at"
[("inside i t.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1154,7 +1159,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'"
(Some (Res (Ortac_runtime.dummy, ()))) "pop_at"
(Either.right (Res (Ortac_runtime.dummy, ())))
"pop_at"
[("(proj x) = old t.contents[i]",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1210,7 +1216,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" None "pop_at"
"make 42 'a'" (Either.left "Invalid_argument")
"pop_at"
[("inside i t.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1259,7 +1266,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" None "delete_at"
"make 42 'a'" (Either.left "Invalid_argument")
"delete_at"
[("inside i t.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1317,7 +1325,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" (Some (Res (unit, ()))) "delete_at"
"make 42 'a'" (Either.right (Res (unit, ())))
"delete_at"
[("Sequence.length t.contents = Sequence.length (old t.contents) - 1",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1373,7 +1382,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" None "delete_at"
"make 42 'a'" (Either.left "Invalid_argument")
"delete_at"
[("inside i t.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1422,7 +1432,7 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" None "get"
"make 42 'a'" (Either.left "Invalid_argument") "get"
[("inside i t.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1478,7 +1488,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'"
(Some (Res (Ortac_runtime.dummy, ()))) "get"
(Either.right (Res (Ortac_runtime.dummy, ())))
"get"
[("(proj x) = t.contents[i]",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1534,7 +1545,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" None "get"
"make 42 'a'" (Either.left "Invalid_argument")
"get"
[("inside i t.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1583,7 +1595,7 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" None "set"
"make 42 'a'" (Either.left "Invalid_argument") "set"
[("inside i t.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1640,7 +1652,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" None "set"
"make 42 'a'" (Either.left "Invalid_argument")
"set"
[("inside i t.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1689,7 +1702,7 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec" "make 42 'a'"
(Some (Res (Ortac_runtime.dummy, ()))) "length"
(Either.right (Res (Ortac_runtime.dummy, ()))) "length"
[("l = Sequence.length t.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1738,7 +1751,7 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec" "make 42 'a'"
(Some (Res (Ortac_runtime.dummy, ()))) "is_empty"
(Either.right (Res (Ortac_runtime.dummy, ()))) "is_empty"
[("b <-> t.contents = Sequence.empty",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1802,7 +1815,7 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" None "fill"
"make 42 'a'" (Either.left "Invalid_argument") "fill"
[("0 <= pos /\\ 0 <= len /\\ pos + len < Sequence.length t.contents",
{
Ortac_runtime.start =
Expand Down Expand Up @@ -1875,7 +1888,8 @@ let ortac_postcond cmd__016_ state__017_ res__018_ =
else
Some
(Ortac_runtime.report "Varray_circular_spec"
"make 42 'a'" None "fill"
"make 42 'a'" (Either.left "Invalid_argument")
"fill"
[("0 <= pos /\\ 0 <= len /\\ pos + len < Sequence.length t.contents",
{
Ortac_runtime.start =
Expand Down
Loading

0 comments on commit 5f0d547

Please sign in to comment.