Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make some sailcov asserts into warnings #507

Merged
merged 1 commit into from
Apr 25, 2024
Merged
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
36 changes: 28 additions & 8 deletions sailcov/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ let opt_bad_color = ref { hue = 0; saturation = 85 }
let opt_good_color = ref { hue = 120; saturation = 85 }
let opt_darken = ref 5

let opt_werror = ref false

let clamp_degree n = max 0 (min n 360)
let clamp_percent n = max 0 (min n 100)

Expand Down Expand Up @@ -94,8 +96,26 @@ let options =
Arg.Set opt_colour_count,
" colour by number of files a span appears in (instead of nesting depth)"
);
("--werror", Arg.Set opt_werror, " turn warnings into errors");
]

let warn message =
if !opt_werror then (
prerr_endline ("Error: " ^ message);
exit 1
)
else prerr_endline ("Warning: " ^ message)

let warn_assert where b =
if b then (
let message = "assertion failed at " ^ where in
if !opt_werror then (
prerr_endline ("Error: " ^ message);
exit 1
)
else prerr_endline ("Warning: " ^ message)
)

type span = { l1 : int; c1 : int; l2 : int; c2 : int }

let string_of_span file span = Printf.sprintf "\"%s\" %d:%d - %d:%d" file span.l1 span.c1 span.l2 span.c2
Expand Down Expand Up @@ -219,7 +239,7 @@ let file_info file all taken =
| Some _, Some _ -> None
| Some n, None -> Some n
| None, Some _ -> begin
Printf.eprintf "Warning: span not in all branches file: %s\n" (string_of_span file span);
Printf.ksprintf warn "span not in all branches file: %s\n" (string_of_span file span);
None
end
| None, None -> None
Expand Down Expand Up @@ -362,7 +382,7 @@ let get_file_spans filename all taken =
let all =
match StringMap.find_opt file all with
| None ->
Printf.eprintf "Warning: %s not found in coverage files\n" file;
Printf.ksprintf warn "%s not found in coverage files\n" file;
SpanMap.empty
| Some s -> s
in
Expand Down Expand Up @@ -514,31 +534,31 @@ let main () =
done
)
else if loc.goodness < 0 then (
assert (loc.badness >= 0);
warn_assert __LOC__ (loc.badness >= 0);
output_html_char chan loc.char;
current_goodness := !current_goodness + loc.goodness;
for _ = 1 to abs loc.goodness do
output_string chan (Printf.sprintf "</span>")
done
)
else if loc.badness < 0 then (
assert (loc.goodness >= 0);
warn_assert __LOC__ (loc.goodness >= 0);
output_html_char chan loc.char;
current_badness := !current_badness + loc.badness;
for _ = 1 to abs loc.badness do
output_string chan (Printf.sprintf "</span>")
done
)
else if loc.badness > 0 then (
assert (loc.goodness <= 0);
warn_assert __LOC__ (loc.goodness <= 0);
current_badness := !current_badness + loc.badness;
for _ = 1 to loc.badness do
output_string chan (Printf.sprintf "<span style=\"background-color: %s\">" (bad_color ()))
done;
output_html_char chan loc.char
)
else if loc.goodness > 0 then (
assert (!current_badness == 0);
warn_assert __LOC__ (!current_badness <= 0);
current_goodness := !current_goodness + loc.goodness;
for _ = 1 to loc.goodness do
output_string chan (Printf.sprintf "<span style=\"background-color: %s\">" (good_color ()))
Expand All @@ -553,8 +573,8 @@ let main () =
output_string chan "</span>"
);

assert (!current_goodness >= 0);
assert (!current_badness >= 0)
warn_assert __LOC__ (!current_goodness >= 0);
warn_assert __LOC__ (!current_badness >= 0)
)
line;
output_string chan "<br>\n"
Expand Down
Loading