Skip to content

Commit

Permalink
Fixes #47: don't output %log_entry when log_level=Nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukstafi committed Aug 4, 2024
1 parent bc45506 commit ab29f63
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
17 changes: 10 additions & 7 deletions ppx_minidebug.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1178,13 +1178,16 @@ let traverse_expression =
[%str
[%e? message];
[%e? entry]] ) ->
let log_count_before = !global_log_count in
let preamble = open_log_no_source ~message ~loc () in
let result = A.ppat_var ~loc { loc; txt = "__res" } in
let entry = callback { context with toplevel_opt_arg = Nested } entry in
let log_result = [%expr ()] in
entry_with_interrupts context ~loc ~message ~log_count_before ~preamble ~entry
~result ~log_result ()
if context.log_level = Nothing then
callback { context with toplevel_opt_arg = Nested } entry
else
let log_count_before = !global_log_count in
let preamble = open_log_no_source ~message ~loc () in
let result = A.ppat_var ~loc { loc; txt = "__res" } in
let entry = callback { context with toplevel_opt_arg = Nested } entry in
let log_result = [%expr ()] in
entry_with_interrupts context ~loc ~message ~log_count_before ~preamble
~entry ~result ~log_result ()
| Pexp_extension ({ loc = _; txt = "log_entry" }, PStr [%str [%e? _entry]]) ->
A.pexp_extension ~loc
@@ Location.error_extensionf ~loc
Expand Down
28 changes: 18 additions & 10 deletions test/test_expect_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3784,9 +3784,10 @@ let%expect_test "%track_l_show procedure runtime passing" =
let () = () in
[%log "inside foo"]
in
let%track_this_l_show bar = function () ->
let () = () in
[%log "inside bar"]
let%track_this_l_show bar = function
| () ->
let () = () in
[%log "inside bar"]
in
while !i < 5 do
incr i;
Expand All @@ -3801,7 +3802,7 @@ let%expect_test "%track_l_show procedure runtime passing" =
foo-1 foo end

BEGIN DEBUG SESSION foo-1
foo-1 <function -- branch 0> () begin "test/test_expect_test.ml":3788:4:
foo-1 <function -- branch 0> () begin "test/test_expect_test.ml":3789:8:
"inside bar"
foo-1 <function -- branch 0> () end

Expand All @@ -3811,7 +3812,7 @@ let%expect_test "%track_l_show procedure runtime passing" =
foo-2 foo end

BEGIN DEBUG SESSION foo-2
foo-2 <function -- branch 0> () begin "test/test_expect_test.ml":3788:4:
foo-2 <function -- branch 0> () begin "test/test_expect_test.ml":3789:8:
"inside bar"
foo-2 <function -- branch 0> () end

Expand All @@ -3821,7 +3822,7 @@ let%expect_test "%track_l_show procedure runtime passing" =
foo-3 foo end

BEGIN DEBUG SESSION foo-3
foo-3 <function -- branch 0> () begin "test/test_expect_test.ml":3788:4:
foo-3 <function -- branch 0> () begin "test/test_expect_test.ml":3789:8:
"inside bar"
foo-3 <function -- branch 0> () end

Expand All @@ -3831,7 +3832,7 @@ let%expect_test "%track_l_show procedure runtime passing" =
foo-4 foo end

BEGIN DEBUG SESSION foo-4
foo-4 <function -- branch 0> () begin "test/test_expect_test.ml":3788:4:
foo-4 <function -- branch 0> () begin "test/test_expect_test.ml":3789:8:
"inside bar"
foo-4 <function -- branch 0> () end

Expand All @@ -3841,7 +3842,7 @@ let%expect_test "%track_l_show procedure runtime passing" =
foo-5 foo end

BEGIN DEBUG SESSION foo-5
foo-5 <function -- branch 0> () begin "test/test_expect_test.ml":3788:4:
foo-5 <function -- branch 0> () begin "test/test_expect_test.ml":3789:8:
"inside bar"
foo-5 <function -- branch 0> () end
|}]
Expand All @@ -3857,7 +3858,13 @@ let%expect_test "%track_rt_show expression runtime passing" =
"test B";
[%log "line B"]]]
(Minidebug_runtime.debug_flushing ~global_prefix:"t2" ());
[%expect {|
[%track_rtb_show
[%log_entry
"test C";
[%log "line C"]]]
(Minidebug_runtime.debug ~global_prefix:"t3" ~log_level:Nothing ());
[%expect
{|
BEGIN DEBUG SESSION t1
t1 test A begin
"line A"
Expand All @@ -3866,5 +3873,6 @@ let%expect_test "%track_rt_show expression runtime passing" =
BEGIN DEBUG SESSION t2
t2 test B begin
"line B"
t2 test B end |}]
t2 test B end

BEGIN DEBUG SESSION t3 |}]

0 comments on commit ab29f63

Please sign in to comment.