Permalink
Browse files

Started transferring Ports to [{port,[option]}]

  • Loading branch information...
1 parent 7798e70 commit 1f0d2bc9802b6ad4a20c8bfe2bb97c33fe89fa29 Gianfranco committed Jul 1, 2011
Showing with 21 additions and 4 deletions.
  1. +18 −2 src/frame_axiom.erl
  2. +3 −2 test/frame_axiom_tests.erl
View
@@ -57,6 +57,9 @@ snapshot(Ets,{ets,all}) ->
snapshot(Ets,{ets,Options}) when is_list(Options) ->
lists:foldl(fun(Option,EtsAcc) -> snapshot(EtsAcc,ets,Option)
end,Ets,Options);
+snapshot(Ets,{port,Options}) when is_list(Options) ->
+ lists:foldl(fun(Option,EtsAcc) -> snapshot(EtsAcc,port,Option)
+ end,Ets,Options);
snapshot(Ets,ets) ->
Existing = ets:all(),
@@ -130,6 +133,10 @@ snapshot(Ets,ets,creation) ->
snapshot(Ets,ets,deletion) ->
Existing = ets:all(),
ets:insert(Ets,{{ets,deletion},Existing}),
+ Ets;
+snapshot(Ets,port,opened) ->
+ Ports = erlang:ports(),
+ ets:insert(Ets,{{port,opened},Ports}),
Ets.
@@ -153,7 +160,10 @@ diff(Ets,{ets,all}) ->
diff(Ets,{ets,all(ets)});
diff(Ets,{ets,Options}) when is_list(Options) ->
lists:foldl(fun(Option,Res) -> Res++diff(Ets,ets,Option)
- end,[],Options);
+ end,[],Options);
+diff(Ets,{port,Options}) when is_list(Options) ->
+ lists:foldl(fun(Option,Res) -> Res++diff(Ets,port,Option)
+ end,[],Options);
diff(Ets,ets) ->
Current = ets:all(),
@@ -265,7 +275,13 @@ diff(Ets,ets,deletion) ->
Current = ets:all(),
Key = {ets,deletion},
[{Key,Recorded}] = ets:lookup(Ets,Key),
- [{deleted,E}||E<-Recorded,not lists:member(E,Current)].
+ [{deleted,E}||E<-Recorded,not lists:member(E,Current)];
+diff(Ets,port,opened) ->
+ Current = erlang:ports(),
+ Key = {port,opened},
+ [{Key,Recorded}] = ets:lookup(Ets,Key),
+ [{opened,P}||P<-Current,not lists:member(P,Recorded)].
+
@@ -220,9 +220,10 @@ ets_all_change_test() ->
%% port
%% ---------------------------------------------------------
ports_creation_diff_test() ->
- Ref = frame_axiom:snapshot(port),
+ Options = [opened],
+ Ref = frame_axiom:snapshot([{port,Options}]),
P = erlang:open_port({spawn,"cd"},[stream]),
- ?assertEqual([{opened,P}],frame_axiom:diff(Ref,port)),
+ ?assertEqual([{opened,P}],frame_axiom:diff(Ref,[{port,Options}])),
erlang:port_close(P).
ports_closing_diff_test() ->

0 comments on commit 1f0d2bc

Please sign in to comment.