@@ -329,6 +329,31 @@ let match_file ~log file adjust reference =
329329 | _ -> false
330330 end
331331
332+ let match_json_file ~log file adjust reference =
333+ let file = adjust file in
334+ let dig1 = Digest. to_hex (Digest. file file) in
335+ let dig2 = Digest. (to_hex (file reference)) in
336+ if dig1 = dig2 then begin
337+ Util. write log (Printf. sprintf " Digest of %s and %s is %s\n " file reference dig2);
338+ true
339+ end else
340+ let yreference = Yojson.Safe. from_file reference in
341+ let yfile = Yojson.Safe. from_file file in
342+ Yojson.Safe. equal yreference yfile ||
343+ begin
344+ Util. write log (Printf. sprintf " Diffing %s against %s\n " file reference);
345+ match
346+ Util. exec ~timeout: 5.0 ~env: (Unix. environment () )
347+ ~log ~close_output: false
348+ ~executable: " diff" ~args: [" -u" ;" --strip-trailing-cr" ;reference;file] ()
349+ with
350+ | Util. Exit (0 ,_ ,_ ) -> true
351+ | Util. Exit (n ,_ ,_ ) ->
352+ Util. write log (Printf. sprintf " Exit code: %d\n " n);
353+ Util. write log (Printf. sprintf " Promotion: cp %s %s\n " file reference);
354+ false
355+ | _ -> false
356+ end
332357
333358module Elpi = struct
334359
@@ -486,7 +511,7 @@ module ElpiTraceElab = struct
486511 match outcome, outcomey, test.Test. expectation with
487512 | Util. Exit (0 ,walltime ,mem ), Some (Util. Exit(0 ,_ ,_ )), Test. SuccessOutputTxt f when f (Util. read_lines (snd log)) ->
488513 Runner. Success { walltime; typechecking; execution; mem }
489- | Util. Exit (0 ,walltime ,mem ), Some (Util. Exit(0 ,_ ,_ )), Test. SuccessOutputFile { sample; adjust; reference } when match_file ~log sample adjust (sources^ " /" ^ reference) ->
514+ | Util. Exit (0 ,walltime ,mem ), Some (Util. Exit(0 ,_ ,_ )), Test. SuccessOutputFile { sample; adjust; reference } when match_json_file ~log sample adjust (sources^ " /" ^ reference) ->
490515 Runner. Success { walltime; typechecking; execution; mem }
491516 | Util. Exit (0 ,walltime ,mem ), Some (Util. Exit(0 ,_ ,_ )), Test. SuccessOutputFile { sample; adjust; reference } when promote ->
492517 FileUtil. cp [adjust sample] (sources^ " /" ^ reference);
0 commit comments