Anonymous avatar Anonymous committed ab26344

Getting 'rebar eunit' working

Comments (0)

Files changed (8)

 	./rebar clean
 
 test: all
-	@mkdir -p tests_ebin
-	@cd tests;erl -make
-	@erl -noshell -boot start_sasl -pa ebin -pa tests_ebin -s luke -eval 'test_suite:test().' -s init stop
-	@rm -f ebin/test_* ebin/*_tests.erl
-
+	./rebar eunit
 #docs: all
 #	@mkdir -p docs
 #	@./build_docs.sh

Binary file modified.

src/luke_flow_cache.erl

+-module(luke_flow_cache).
+
+-behaviour(gen_server).
+
+%% API
+-export([start_link/0,
+         cache_value/3,
+         check_cache/2,
+         delete_value/2]).
+
+%% gen_server callbacks
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+         terminate/2, code_change/3]).
+
+-record(state, {cache=dict:new()}).
+
+start_link() ->
+    gen_server:start_link(?MODULE, [], []).
+
+cache_value(Pid, Key, Value) ->
+    gen_server:call(Pid, {cache_value, Key, Value}).
+
+check_cache(Pid, Key) ->
+    gen_server:call(Pid, {check_cache, Key}).
+
+delete_value(Pid, Key) ->
+    gen_server:call(Pid, {delete_value, Key}).
+
+init([]) ->
+    {ok, #state{}}.
+
+handle_call({cache_value, Key, Value}, _From, #state{cache=Cache0}=State) ->
+    Cache = dict:store(Key, Value, Cache0),
+    {reply, ok, State#state{cache=Cache}};
+handle_call({check_cache, Key}, _From, #state{cache=Cache}=State) ->
+    Reply = case dict:is_key(Key, Cache) of
+                false ->
+                    not_found;
+                true ->
+                    dict:fetch(Key, Cache)
+            end,
+    {reply, Reply, State};
+handle_call({delete_value, Key}, _From, #state{cache=Cache0}=State) ->
+    Cache = dict:erase(Key, Cache0),
+    {reply, ok, State#state{cache=Cache}};
+handle_call(_Request, _From, State) ->
+    {reply, ignore, State}.
+
+handle_cast(_Msg, State) ->
+    {noreply, State}.
+
+handle_info(_Info, State) ->
+    {noreply, State}.
+
+terminate(_Reason, _State) ->
+    ok.
+
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.

test/cache_tests.erl

+-module(cache_tests).
+
+-include_lib("eunit/include/eunit.hrl").
+
+read_write_test_() ->
+    [fun() ->
+             {ok, Pid} = luke_flow_cache:start_link(),
+             Key = "hello",
+             Value = "world",
+             luke_flow_cache:cache_value(Pid, Key, Value),
+             ?assertMatch(Value, luke_flow_cache:check_cache(Pid, Key)),
+             ?assertMatch(not_found, luke_flow_cache:check_cache(Pid, "world")),
+             luke_flow_cache:delete_value(Pid, Key),
+             ?assertMatch(not_found, luke_flow_cache:check_cache(Pid, Key)) end].

test/lifecycle_tests.erl

-%% This file is provided to you under the Apache License,
-%% Version 2.0 (the "License"); you may not use this file
-%% except in compliance with the License.  You may obtain
-%% a copy of the License at
-
-%%   http://www.apache.org/licenses/LICENSE-2.0
-
-%% Unless required by applicable law or agreed to in writing,
-%% software distributed under the License is distributed on an
-%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-%% KIND, either express or implied.  See the License for the
-%% specific language governing permissions and limitations
-%% under the License.
-
--module(lifecycle_tests).
-
--include_lib("eunit/include/eunit.hrl").
--include("tests.hrl").
-
-setup_teardown_test_() ->
-    [fun() ->
-             %% Startup/teardown, no input
-             {ok, Pid} = luke:new_flow(make_ref(), ?TWO_PHASE_FLOW),
-             Phases = test_util:verify_phases(Pid, 2),
-             exit(Pid, kill),
-             timer:sleep(10),
-             test_util:assertDead([Pid|Phases]) end,
-     fun() ->
-             %% Startup/teardown, infinity timeout, no input
-             {ok, Pid} = luke:new_flow(self(), make_ref(), ?TWO_PHASE_FLOW, infinity),
-             Phases = test_util:verify_phases(Pid, 2),
-             exit(Pid, kill),
-             timer:sleep(10),
-             test_util:assertDead([Pid|Phases]) end,
-     fun() ->
-             %% Startup/teardown, input w/no end
-             {ok, Pid} = luke:new_flow(make_ref(), ?TWO_PHASE_FLOW),
-             Phases = test_util:verify_phases(Pid, 2),
-             luke_flow:add_inputs(Pid, [100]),
-             exit(Pid, kill),
-             timer:sleep(10),
-             test_util:assertDead([Pid|Phases]) end,
-     fun() ->
-             %% Startup/teardown, input w/finish
-             {ok, Pid} = luke:new_flow(make_ref(), ?TWO_PHASE_FLOW),
-             Phases = test_util:verify_phases(Pid, 2),
-             luke_flow:add_inputs(Pid, [100]),
-             luke_flow:add_inputs(Pid, [200]),
-             luke_flow:finish_inputs(Pid),
-             exit(Pid, kill),
-             timer:sleep(10),
-             test_util:assertDead([Pid|Phases]) end].

test/luke_suite.erl

 %% specific language governing permissions and limitations
 %% under the License.
 
--module(test_suite).
+-module(luke_suite).
 
 -include_lib("eunit/include/eunit.hrl").
 
 all_test_() ->
-    [{module, lifecycle_tests},
-     {module, results_tests},
+    [{module, results_tests},
      {module, cache_tests}].

test/test_util.erl

 -export([start_flow/1, verify_phases/2, verify_results/2, assertDead/1]).
 
 start_flow(FlowDesc) ->
+    start_deps([sasl, luke]),
     FlowId = make_ref(),
     {ok, Pid} = luke:new_flow(FlowId, FlowDesc),
     Phases = test_util:verify_phases(Pid, length(FlowDesc)),
 assertDead0([H|T]) when is_pid(H) ->
     ?assertMatch(false, erlang:is_process_alive(H)),
     assertDead0(T).
+
+start_deps([]) ->
+    ok;
+start_deps([H|T]) ->
+    case application:start(H) of
+        ok ->
+            timer:sleep(50),
+            start_deps(T);
+        {error, {already_started, H}} ->
+            start_deps(T);
+        Error ->
+            throw(Error)
+    end.

tests/cache_tests.erl

+-module(cache_tests).
+
+-include_lib("eunit/include/eunit.hrl").
+
+read_write_test_() ->
+    [fun() ->
+             {ok, Pid} = luke_flow_cache:start_link(),
+             Key = "hello",
+             Value = "world",
+             luke_flow_cache:cache_value(Pid, Key, Value),
+             ?assertMatch(Value, luke_flow_cache:check_cache(Pid, Key)),
+             ?assertMatch(not_found, luke_flow_cache:check_cache(Pid, "world")),
+             luke_flow_cache:delete_value(Pid, Key),
+             ?assertMatch(not_found, luke_flow_cache:check_cache(Pid, Key)) end].
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.