summaryrefslogtreecommitdiff
path: root/tools/erlang_app_equal
diff options
context:
space:
mode:
Diffstat (limited to 'tools/erlang_app_equal')
-rwxr-xr-xtools/erlang_app_equal68
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/erlang_app_equal b/tools/erlang_app_equal
new file mode 100755
index 0000000000..ba3a4bef28
--- /dev/null
+++ b/tools/erlang_app_equal
@@ -0,0 +1,68 @@
+#!/usr/bin/env escript
+%% -*- erlang -*-
+%%! -nocookie
+
+-mode(compile).
+
+main([Left, Right]) ->
+ {ok, LeftMetadata} = file:consult(Left),
+ {ok, RightMetadata} = file:consult(Right),
+ compare(LeftMetadata, RightMetadata),
+ halt();
+main(_) ->
+ halt(1).
+
+compare(LeftMetadata, RightMetadata) ->
+ [{application, LeftApp, LeftProps}] = LeftMetadata,
+ [{application, RightApp, RightProps}] = RightMetadata,
+
+ assert_equal(LeftApp, RightApp, "application name"),
+
+ LeftId = proplists:get_value(id, LeftProps),
+ RightId = proplists:get_value(id, RightProps),
+ case LeftId of
+ RightId ->
+ ok;
+ _ ->
+ io:format(standard_error,
+ "Warning:\t 'id' does not match (~p != ~p)~n", [LeftId, RightId])
+ end,
+
+ LeftPropsMap = proplists:to_map(proplists:delete(id, LeftProps)),
+ RightPropsMap = proplists:to_map(proplists:delete(id, RightProps)),
+ assert_equal(
+ lists:sort(maps:keys(LeftPropsMap)),
+ lists:sort(maps:keys(RightPropsMap)),
+ "app property keys"
+ ),
+ [case K of
+ K when K =:= applications orelse K =:= modules ->
+ assert_equal(
+ lists:sort(maps:get(K, LeftPropsMap)),
+ lists:sort(maps:get(K, RightPropsMap)),
+ K
+ );
+ env ->
+ assert_equal(
+ proplists:to_map(maps:get(K, LeftPropsMap)),
+ proplists:to_map(maps:get(K, RightPropsMap)),
+ K
+ );
+ _ ->
+ assert_equal(
+ maps:get(K, LeftPropsMap),
+ maps:get(K, RightPropsMap),
+ K
+ )
+ end || K <- lists:sort(maps:keys(LeftPropsMap))],
+ ok.
+
+assert_equal(Expected, Actual, Context) ->
+ case Actual of
+ Expected ->
+ ok;
+ _ ->
+ io:format(standard_error,
+ "Expected:\t~p~n But got:\t~p~n For:\t~p~n", [Expected, Actual, Context]),
+ erlang:error(assertion_failed)
+ end.