-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #54: test for compile-time vs. runtime log level consistency
Naive exact code matching since it's hard to write a cram test.
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |