Skip to content

Commit

Permalink
Fixes #54: test for compile-time vs. runtime log level consistency
Browse files Browse the repository at this point in the history
Naive exact code matching since it's hard to write a cram test.
  • Loading branch information
lukstafi committed Aug 21, 2024
1 parent 1d53009 commit e86e31e
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@
(action
(run ./%{pp} --impl %{input} -o %{targets})))

(rule
(targets test_debug_log_level_consistency.actual.ml)
(deps
(:pp pp.exe)
(:input test_debug_log_level_consistency.ml))
(action
(setenv
PPX_MINIDEBUG_TEST_LOG_LEVEL_CONSISTENCY
everything
(run ./%{pp} --impl %{input} -o %{targets}))))

(rule
(alias runtest)
(action
Expand Down Expand Up @@ -114,6 +125,13 @@
test_debug_show_error_this.expected.ml
test_debug_show_error_this.actual.ml)))

(rule
(alias runtest)
(action
(diff
test_debug_log_level_consistency.expected.ml
test_debug_log_level_consistency.actual.ml)))

(executable
(name test_debug_sexp)
(modules test_debug_sexp)
Expand Down
58 changes: 58 additions & 0 deletions test/test_debug_log_level_consistency.expected.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
module Debug_runtime = (val
Minidebug_runtime.debug_flushing ~filename:"debugger_show_flushing" ())
;;try
let runtime_log_level =
Stdlib.String.lowercase_ascii @@
(Stdlib.Sys.getenv "PPX_MINIDEBUG_TEST_LOG_LEVEL_CONSISTENCY") in
if
(not (Stdlib.String.equal "" runtime_log_level)) &&
(not (Stdlib.String.equal "everything" runtime_log_level))
then
failwith
("ppx_minidebug: compile-time vs. runtime log level mismatch, found '"
^
("everything" ^
("' at compile time, '" ^ (runtime_log_level ^ "' at runtime"))))
with | Stdlib.Not_found -> ()
let foo (x : int) =
(let __entry_id = Debug_runtime.get_entry_id () in
();
(Debug_runtime.open_log ~fname:"test_debug_log_level_consistency.ml"
~start_lnum:7 ~start_colnum:19 ~end_lnum:9 ~end_colnum:17
~message:"foo" ~entry_id:__entry_id;
Debug_runtime.log_value_show ?descr:(Some "x") ~entry_id:__entry_id
~is_result:false (([%show : int]) x));
(match let y : int =
let __entry_id = Debug_runtime.get_entry_id () in
();
Debug_runtime.open_log
~fname:"test_debug_log_level_consistency.ml" ~start_lnum:8
~start_colnum:6 ~end_lnum:8 ~end_colnum:7 ~message:"y"
~entry_id:__entry_id;
(match x + 1 with
| y as __res ->
((();
Debug_runtime.log_value_show ?descr:(Some "y")
~entry_id:__entry_id ~is_result:true (([%show : int]) y));
Debug_runtime.close_log
~fname:"test_debug_log_level_consistency.ml"
~start_lnum:8 ~entry_id:__entry_id;
__res)
| exception e ->
(Debug_runtime.close_log
~fname:"test_debug_log_level_consistency.ml"
~start_lnum:8 ~entry_id:__entry_id;
raise e)) in
[x; y; 2 * y]
with
| __res ->
(Debug_runtime.log_value_show ?descr:(Some "foo")
~entry_id:__entry_id ~is_result:true (([%show : int list]) __res);
Debug_runtime.close_log ~fname:"test_debug_log_level_consistency.ml"
~start_lnum:7 ~entry_id:__entry_id;
__res)
| exception e ->
(Debug_runtime.close_log ~fname:"test_debug_log_level_consistency.ml"
~start_lnum:7 ~entry_id:__entry_id;
raise e)) : int list)
let () = ignore @@ (List.hd @@ (foo 7))
11 changes: 11 additions & 0 deletions test/test_debug_log_level_consistency.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Debug_runtime =
(val Minidebug_runtime.debug_flushing ~filename:"debugger_show_flushing" ())

[%%global_debug_log_level_from_env_var "PPX_MINIDEBUG_TEST_LOG_LEVEL_CONSISTENCY"]


let%debug_show foo (x : int) : int list =
let y : int = x + 1 in
[ x; y; 2 * y ]

let () = ignore @@ List.hd @@ foo 7

0 comments on commit e86e31e

Please sign in to comment.