Source file make_corrected_file.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
open! Base
open! Import
let chop_if_exists ~ancestor ~from:path =
String.chop_prefix_if_exists path ~prefix:(ancestor ^ "/")
;;
let f
?(use_dot_patdiff = false)
?corrected_path
?(use_color = false)
?diff_command
?diff_path_prefix
~next_contents
~path
()
=
let prev_contents =
if Stdlib.Sys.file_exists path
then Stdio.In_channel.with_file path ~f:Stdio.In_channel.input_all
else ""
in
match String.( = ) prev_contents next_contents with
| true ->
Ok ()
| false ->
let default_corrected_path = path ^ ".corrected" in
let corrected_path = Option.value corrected_path ~default:default_corrected_path in
Stdio.Out_channel.write_all corrected_path ~data:next_contents;
let =
let default_configs =
match use_dot_patdiff && Option.is_none (Sys.getenv "TESTING_FRAMEWORK") with
| true -> []
| false -> [ "-default" ]
in
let cwd = Stdlib.Sys.getcwd () in
let prefix =
match diff_path_prefix with
| Some prefix -> String.rstrip ~drop:(Char.equal '/') prefix ^ "/"
| None -> ""
in
let alt_old = [ "-alt-old"; prefix ^ chop_if_exists ~ancestor:cwd ~from:path ] in
let alt_new =
[ "-alt-new"; prefix ^ chop_if_exists ~ancestor:cwd ~from:default_corrected_path ]
in
[ default_configs; alt_old; alt_new ] |> List.concat
in
Ppxlib_print_diff.print
?diff_command
~use_color
~extra_patdiff_args
~file1:path
~file2:corrected_path
();
Error (Error.of_string "Changes found.")
;;