Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/ecCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,22 @@ let check_opname_validity (scope : EcScope.scope) (x : string) =
let process_print scope p =
process_pr Format.std_formatter scope p

(* -------------------------------------------------------------------- *)
let process_expect scope (expected, p) =
let buf = Buffer.create 256 in
let fmt = Format.formatter_of_buffer buf in
process_pr fmt scope p;
Format.pp_print_flush fmt ();
let actual = Buffer.contents buf in
if String.trim actual <> String.trim (unloc expected) then
EcScope.hierror ~loc:(loc expected)
"expect: output mismatch@\n\
--- expected ---@\n\
%s@\n\
--- actual ---@\n\
%s"
(unloc expected) actual

(* -------------------------------------------------------------------- *)
exception Pragma of [`Reset | `Restart]

Expand Down Expand Up @@ -782,6 +798,7 @@ and process ?(src : string option) (ld : Loader.loader) (scope : EcScope.scope)
| GsctOpen name -> `Fct (fun scope -> process_sct_open scope name)
| GsctClose name -> `Fct (fun scope -> process_sct_close scope name)
| Gprint p -> `Fct (fun scope -> process_print scope p; scope)
| Gexpect x -> `Fct (fun scope -> process_expect scope x; scope)
| Gsearch qs -> `Fct (fun scope -> process_search scope qs; scope)
| Glocate x -> `Fct (fun scope -> process_locate scope x; scope)
| Gtactics t -> `Fct (fun scope -> process_tactics ?src scope t)
Expand Down
2 changes: 2 additions & 0 deletions src/ecParser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -3950,6 +3950,8 @@ global_action:
| hint { Ghint $1 }
| x=loc(proofend) { Gsave x }
| PRINT p=print { Gprint p }
| EXPECT s=loc(STRING) BY PRINT p=print
Comment thread
strub marked this conversation as resolved.
{ Gexpect (s, p) }
| SEARCH x=search+ { Gsearch x }
| LOCATE x=qident { Glocate x }
| WHY3 x=STRING { GdumpWhy3 x }
Expand Down
1 change: 1 addition & 0 deletions src/ecParsetree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,7 @@ type global_action =
| Greduction of puserred
| Ghint of phint
| Gprint of pprint
| Gexpect of (string located * pprint)
| Gsearch of pformula list
| Glocate of pqsymbol
| GthOpen of (is_local * bool * psymbol)
Expand Down
30 changes: 30 additions & 0 deletions tests/expect.ec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(* Unit tests for the `expect "..." by print ...` command. *)

require import Int.

type point = { x : int; y : int; }.

op foo : int = 1.
op bar (n : int) : int = n + 1.

axiom foo_pos : 0 < foo.

(* nullary op *)
expect "op foo : int = 1." by print op foo.

(* op with arguments *)
expect "op bar (n : int) : int = n + 1." by print op bar.

(* record type *)
expect "type point = { x: int; y: int; }." by print type point.

(* axiom *)
expect "axiom foo_pos: 0 < foo." by print axiom foo_pos.

(* multi-line string literal with leading/trailing whitespace is
tolerated (String.trim-based comparison) *)
expect "

op foo : int = 1.

" by print op foo.
Loading