Commits

ccorrodi  committed e1b9680

fix diff function when test fails

  • Participants
  • Parent commits 534d75d
  • Branches develop

Comments (0)

Files changed (4)

 let s_to_command (s : string) : command =
   s
 
+let s_of_command (c : command) : string =
+  c
+
 (** Origin strings as they may appear in the make database. *)
 let s_origin_default = "default"
 let s_origin_env = "environment"
     r_terminal = terminal;
     r_in_use = in_use;
   }
+
+let pp_commands (a : ast) : string =
+  L.fold_right (fun cmd s -> (s_of_command cmd) ^ s) a.a_commands ""
   in_use : bool ->
   rule
 
+(** {2 Output / Pretty Printing} *)
+(** Return a string of the command section. The returned string is in valid
+    make data base format. *)
+val pp_commands : ast -> string
+
 (** {2 Utility Functions} *)
 
 (** Convert a given command string to command type. *)

File src/ocamlmake.ml

    *)
 
 module A = Ast
+module S = Str
 
 (** Convert input token list to "Lexing.lexbuf -> Parser.token", as this is
     the type we need as first argument to Parser.input.
     end
 
 let pretty_print_lines (a : A.ast) : string list =
-  []
+  let s = A.pp_commands a in
+  S.split (S.regexp "\n") s

File test/unitTests.ml

   | [], [] ->
       true
   | [], ys ->
-      has_non_comments ys
+      not (has_non_comments ys)
   | xs, [] ->
-      has_non_comments xs
+      not (has_non_comments xs)
 
 (** Compare the given databases (values) and print to the given formatter info
     about where the data did not match. *)
   let orig_line = ref 1 in
   let rec helper (values : 'a * 'a) : unit =
     match values with
+    | x :: xs, ys when (iscomment x) ->
+        incr orig_line;
+        helper (xs, ys)
+    | xs, y :: ys when (iscomment y) ->
+        incr ocamlmake_line;
+        helper (xs, ys)
     | x :: xs, y :: ys ->
-        if (iscomment x) then begin
-          incr orig_line;
-          Printf.printf "orig line now: %d\n" !orig_line;
-          helper (xs, y :: ys)
-        end
-        else if (iscomment y) then begin
-          incr ocamlmake_line;
-          helper (x :: xs, ys)
-        end
-        else if x <> y then begin
+        if x <> y then begin
           Format.fprintf fmt
             "Error on output line %d (original db file line %d)\n"
             !ocamlmake_line !orig_line;
           incr orig_line;
           helper (xs, ys)
         end
+    | x :: xs, [] ->
+        Format.fprintf fmt
+          "Error on output line %d (original db file line %d)\n"
+          !ocamlmake_line !orig_line;
+        Format.fprintf fmt "Output file reached EOF, expected:\n%s" x;
+    | [], y :: ys ->
+        Format.fprintf fmt
+          "Error on output line %d (original db file line %d)\n"
+          !ocamlmake_line !orig_line;
+        Format.fprintf fmt "Input file reached EOF, expected:\n%s" y;
     | _, _ ->
         ()
   in