Просмотр исходного кода

Propagate test status back to make.

Andreas Stenius 11 лет назад
Родитель
Сommit
e3da1bdfd7

+ 8 - 5
Makefile

@@ -18,11 +18,14 @@ compile_test:
 
 test: compile compile_test
 	$(ERL) -noshell -pa ebin -pa ebintest \
-		-s erlydtl_functional_tests run_tests \
-		-s erlydtl_dateformat_tests run_tests \
-		-s erlydtl_unittests run_tests \
-		-s sources_parser_unittests run_tests \
-		-s init stop
+		-eval \
+		"try \
+			erlydtl_functional_tests:run_tests(), \
+			erlydtl_dateformat_tests:run_tests(), \
+			erlydtl_unittests:run_tests(), \
+			sources_parser_unittests:run_tests(), \
+			halt(0) \
+		catch throw:failed -> halt(1) end"
 
 clean:
 	@$(REBAR) clean

+ 6 - 3
tests/src/erlydtl_dateformat_tests.erl

@@ -214,9 +214,12 @@ run_tests() ->
       { "Ordinal suffix 22", {1984,1,121}, [{"S", "st"}] }
    ]),
 
-   io:format("Date format failures: ~p~n~n", [Failures]),
-
-   ok.
+    if Failures == 0 ->
+            io:format("All Date format tests PASS~n~n");
+       true ->
+            io:format("Date format failures: ~p~n~n", [Failures]),
+            throw(failed)
+    end.
 
 test_group_runner([]) -> 0;
 test_group_runner([{Info, DateParam, Tests} | Rest]) ->

+ 2 - 2
tests/src/erlydtl_functional_tests.erl

@@ -206,11 +206,11 @@ run_tests() ->
                       [length(Errs), N]),
                     [io:format("  ~s [~s] ~s~n", [Name, Error, Reason])
                      || {Name, Error, Reason} <- Errs],
-                    failed
+                    throw(failed)
             end;
         Err ->
             [io:format("Ensure dir failed: ~p~n~n", [Reason]) || {error, Reason} <- Err],
-            failed
+            throw(failed)
     end.
 
 

+ 3 - 2
tests/src/erlydtl_unittests.erl

@@ -1221,14 +1221,15 @@ run_tests() ->
                  end, [], tests()),
 
     case length(Failures) of
-        0 -> io:format("~nAll unit tests PASS~n");
+        0 -> io:format("~nAll unit tests PASS~n~n");
         Length ->
             io:format("~n### FAILED groups: ~b ####~n", [Length]),
             [begin
                  io:format("  Group: ~s (~b failures)~n", [Group, length(Failed)]),
                  [io:format("    Test: ~s~n~s~n", [Name, Error])
                   || {Name, Error} <- lists:reverse(Failed)]
-             end || {Group, Failed} <- lists:reverse(Failures)]
+             end || {Group, Failed} <- lists:reverse(Failures)],
+            throw(failed)
     end.
 
 format_error(Name, Class, Error, Acc) ->

+ 9 - 3
tests/src/sources_parser_unittests.erl

@@ -20,7 +20,7 @@ tests() ->
     ].
 
 run_tests() ->
-    io:format("Running unit tests...~n"),
+    io:format("Running source parser unit tests...~n"),
     Failures = lists:foldl(
         fun({Group, Assertions}, GroupAcc) ->
                 io:format(" Test group ~p...~n", [Group]),
@@ -28,8 +28,14 @@ run_tests() ->
 				process_unit_test(Content, Output, Acc, Group, Name)                              
                             end, GroupAcc, Assertions)
         end, [], tests()),
-    
-    io:format("Unit test failures: ~p~n", [Failures]).
+
+    case Failures of
+        [] ->
+            io:format("All tests PASS~n~n");
+        _ ->
+            io:format("Unit test failures: ~p~n", [Failures]),
+            throw(failed)
+    end.
 
 process_unit_test(Content, Output,Acc, Group, Name) ->
 	Tokens = sources_parser:process_content("dummy_path", Content),