Skip to content

Commit

Permalink
Fixes #43: highlight <returns> and <values>
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Aug 4, 2024
1 parent ab29f63 commit 0f47fdd
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 2 deletions.
13 changes: 11 additions & 2 deletions minidebug_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ module PrintBox (Log_to : Shared_config) = struct
type subentry = {
result_id : int;
is_result : bool;
highlighted : bool;
elapsed_start : Mtime.span;
elapsed_end : Mtime.span;
subtree : B.t;
Expand Down Expand Up @@ -642,6 +643,7 @@ module PrintBox (Log_to : Shared_config) = struct
(fun { result_id; is_result; _ } -> is_result && result_id = entry_id)
body
in
let results_hl = List.exists (fun { highlighted; _ } -> highlighted) results in
let results = unpack ~f:(fun { subtree; _ } -> subtree) results
and body = unpack ~f:(fun { subtree; _ } -> subtree) body in
match results with
Expand All @@ -657,7 +659,8 @@ module PrintBox (Log_to : Shared_config) = struct
(apply_highlight highlight value_header)
(b_path
:: B.tree
(B.line @@ if body = [] then "<values>" else "<returns>")
(apply_highlight results_hl @@ B.line
@@ if body = [] then "<values>" else "<returns>")
(Array.to_list result_body)
:: opt_message
@ body) )
Expand All @@ -674,7 +677,10 @@ module PrintBox (Log_to : Shared_config) = struct
( header,
B.tree hl_header
@@ b_path
:: B.tree (B.line @@ if body = [] then "<values>" else "<returns>") results
:: B.tree
(apply_highlight results_hl @@ B.line
@@ if body = [] then "<values>" else "<returns>")
results
:: body )
else
let hl_header =
Expand Down Expand Up @@ -904,6 +910,7 @@ module PrintBox (Log_to : Shared_config) = struct
{
result_id;
is_result = false;
highlighted = hl;
elapsed_start;
elapsed_end = elapsed_on_close;
subtree;
Expand Down Expand Up @@ -1007,6 +1014,7 @@ module PrintBox (Log_to : Shared_config) = struct
{
result_id = entry_id;
is_result;
highlighted = hl;
elapsed_start = elapsed;
elapsed_end = elapsed;
subtree = b;
Expand All @@ -1024,6 +1032,7 @@ module PrintBox (Log_to : Shared_config) = struct
{
result_id = entry_id;
is_result;
highlighted = hl;
elapsed_start = elapsed;
elapsed_end = elapsed;
subtree = b;
Expand Down
75 changes: 75 additions & 0 deletions test/test_expect_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3876,3 +3876,78 @@ let%expect_test "%track_rt_show expression runtime passing" =
t2 test B end

BEGIN DEBUG SESSION t3 |}]

let%expect_test "%debug_show tuples values_first_mode highlighted" =
let module Debug_runtime =
(val Minidebug_runtime.debug
~highlight_terms:Re.(alt [ str "339"; str "8" ])
~values_first_mode:true ())
in
let%debug_show bar ((first : int), (second : int)) : int =
let y : int = first + 1 in
second * y
in
let () = print_endline @@ Int.to_string @@ bar (7, 42) in
let baz ((first, second) : int * int) : int * int =
let (y, z) : int * int = (first + 1, 3) in
let (a : int), (b : int) = (first + 1, second + 3) in
((second * y) + z, (a * a) + b)
in
let r1, r2 = (baz (7, 42) : int * int) in
let () = print_endline @@ Int.to_string r1 in
let () = print_endline @@ Int.to_string r2 in
[%expect
{|
BEGIN DEBUG SESSION
┌─────────┐
│bar = 336
├─────────┘
├─"test/test_expect_test.ml":3886:21
├─first = 7
├─second = 42
└─┬─────┐
│y = 8
├─────┘
└─"test/test_expect_test.ml":3887:8
336
┌────────┐
│(r1, r2)│
├────────┘
├─"test/test_expect_test.ml":3896:6
├─┬─────────┐
│ │<returns>
│ ├─────────┘
│ ├─┬────────┐
│ │ │r1 = 339
│ │ └────────┘
│ └─r2 = 109
└─┬────────────────┐
│baz = (339, 109)│
├────────────────┘
├─"test/test_expect_test.ml":3891:10
├─first = 7
├─second = 42
├─┬──────┐
│ │(y, z)│
│ ├──────┘
│ ├─"test/test_expect_test.ml":3892:8
│ └─┬────────┐
│ │<values>
│ ├────────┘
│ ├─┬─────┐
│ │ │y = 8
│ │ └─────┘
│ └─z = 3
└─┬──────┐
│(a, b)│
├──────┘
├─"test/test_expect_test.ml":3893:8
└─┬────────┐
<values>
├────────┘
├─┬─────┐
│ │a = 8
│ └─────┘
└─b = 45
339
109 |}]

0 comments on commit 0f47fdd

Please sign in to comment.