From f4cd30a274f267365eaf04fa6f2f9fc58b5d3209 Mon Sep 17 00:00:00 2001
From: Virgile Prevosto <virgile.prevosto@m4x.org>
Date: Tue, 31 Mar 2020 11:43:00 +0200
Subject: [PATCH] [ptests] output content of oracle/log file when log/oracle
 does not exist

---
 ptests/ptests.ml | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/ptests/ptests.ml b/ptests/ptests.ml
index 4db22c91fe2..64401651909 100644
--- a/ptests/ptests.ml
+++ b/ptests/ptests.ml
@@ -1473,6 +1473,19 @@ let worker_thread () =
         unlock ();
   done
 
+let diff_check_exist old_file new_file =
+  if Sys.file_exists old_file then begin
+    if Sys.file_exists new_file then begin
+      !do_diffs ^ " " ^ old_file ^ " " ^ new_file
+    end else begin
+      "echo \"" ^ new_file ^ " does not exist. Showing " ^ old_file ^ "\";" ^
+      " cat " ^ old_file
+    end
+  end else begin
+      "echo \"" ^ old_file ^ " does not exist. Showing " ^ new_file ^ "\";" ^
+      " cat " ^ new_file
+  end
+
 let do_diff = function
     | Command_error (diff, kind) ->
       let log_prefix = log_prefix diff in
@@ -1487,7 +1500,7 @@ let do_diff = function
         let oracle_file =
           Filename.sanitize (oracle_prefix ^ log_ext ^ ".oracle")
         in
-        let diff_string = !do_diffs ^ " " ^ oracle_file ^ " " ^ log_file in
+        let diff_string = diff_check_exist oracle_file log_file in
         ignore (launch diff_string)
   | Target_error execnow ->
     lock_printf "Custom command failed: %s@\n" execnow.ex_cmd;
@@ -1515,9 +1528,7 @@ let do_diff = function
         let oracle_file =
           Filename.sanitize (SubDir.make_oracle_file dir file)
         in
-        let diff_string =
-          !do_diffs ^ " " ^  oracle_file ^ " " ^ result_file
-        in
+        let diff_string = diff_check_exist oracle_file result_file in
         ignore (launch diff_string)
 
 
-- 
GitLab