#!/usr/bin/env escript
-module(compare_lines).

-mode(compile).

-compile([export_all]).

main(Dir) ->
    Files = filelib:wildcard(Dir ++ "/**.merged") ++ filelib:wildcard(Dir ++ "/**/**.merged"),
    io:format("Results for ~p~n", [Dir]),
    case lists:usort([ process_file(File) || File <- Files ]) of
        [ok] ->
            io:format("All passed~n");
        _ ->
            io:format("Failed~n")
    end,
    ok.


process_file(File) ->
    Ruby = File ++ ".xml.ruby.lines",
    Erlang = File ++ ".xml.erlang.lines",
    DiffCmd = "diff -u " ++ Erlang ++ " " ++ Ruby,
    Ans = os:cmd(DiffCmd),
    case Ans of
        [] ->
            ok;
        _ ->
            error
    end.
