Commits

Tamas Nagy  committed f92e075 Merge

merged changes from main branch

  • Participants
  • Parent commits 65c5b79, 3c9c8e1

Comments (0)

Files changed (6)

 
 ebin/{*.beam,lhttpc.app}
 test/*.beam
+util/*.beam
+test/*.log
 doc/{edoc-info,*.{png,css,html}}
 cover_report/*
 
 $(APPLICATION): $(BEAMS) $(APP_FILE)
 
 test: $(APPLICATION) $(TEST_BEAMS)
+	@erlc -o util/ util/run_test.erl
 	@echo Running tests
-	@erl -pa ebin/ -pa test/ -noinput -eval 'run_test:run()' -s erlang halt
+	@erl -pa util/ -pa ebin/ -pa test/ -noinput -s run_test run
 
 test_shell: $(APPLICATION) $(TEST_BEAMS)
 	@echo Starting a shell with test paths included
 	@dialyzer --src -r src/
 
 doc/edoc-info: doc/overview.edoc $(SOURCES) 
+	@erlc -o util/ util/make_doc.erl
 	@echo Generating documentation from edoc
-	@erl -noinput -eval 'edoc:application(lhttpc, "./", [{doc, "doc/"}])' -s erlang halt
+	@erl -pa util/ -noinput -s make_doc edoc
 
 clean:
 	@echo Cleaning
 	@rm -f ebin/*.{beam,app} test/*.beam doc/*.{html,css,png} doc/edoc-info
 	@rm -r cover_report
+
+release: clean all test dialyzer
+	@util/releaser $(APPLICATION) $(VSN)

File test/run_test.erl

-%%% ----------------------------------------------------------------------------
-%%% Copyright (c) 2009, Erlang Training and Consulting Ltd.
-%%% All rights reserved.
-%%% 
-%%% Redistribution and use in source and binary forms, with or without
-%%% modification, are permitted provided that the following conditions are met:
-%%%    * Redistributions of source code must retain the above copyright
-%%%      notice, this list of conditions and the following disclaimer.
-%%%    * Redistributions in binary form must reproduce the above copyright
-%%%      notice, this list of conditions and the following disclaimer in the
-%%%      documentation and/or other materials provided with the distribution.
-%%%    * Neither the name of Erlang Training and Consulting Ltd. nor the
-%%%      names of its contributors may be used to endorse or promote products
-%%%      derived from this software without specific prior written permission.
-%%% 
-%%% THIS SOFTWARE IS PROVIDED BY Erlang Training and Consulting Ltd. ''AS IS''
-%%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-%%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-%%% ARE DISCLAIMED. IN NO EVENT SHALL Erlang Training and Consulting Ltd. BE
-%%% LIABLE SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-%%% BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-%%% WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-%%% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-%%% ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-%%% ----------------------------------------------------------------------------
-
-%%% @author Oscar Hellström <oscar@erlang-consulting.com>
--module(run_test).
--export([run/0]).
-
--include_lib("eunit/include/eunit.hrl").
-
--define(FILE_NAME(MODULE),
-    "cover_report/" ++ atom_to_list(MODULE) ++ ".html").
-
-run() ->
-    Modules = get_modules(),
-    ok = cover_compile(Modules),
-    eunit:test(?MODULE),
-    filelib:ensure_dir("cover_report/index.html"),
-    html_report(Modules),
-    write_report(Modules),
-    io:format("Cover report in cover_report/index.html~n").
-
-html_report([Module | Modules]) ->
-    cover:analyse_to_file(Module, ?FILE_NAME(Module), [html]),
-    html_report(Modules);
-html_report([]) ->
-    ok.
-
-write_report(Modules) ->
-    {TotalPercentage, ModulesPersentage} = percentage(Modules, 0, 0, []),
-    file:write_file("cover_report/index.html",
-        [
-            "<html>\n<head><title>Cover report index</title></head>\n"
-            "<body>\n"
-            "<h1>Cover report for lhttpc</h1>"
-            "Total coverage: ", integer_to_list(TotalPercentage), "%"
-            "<h2>Cover for individual modules</h2>\n"
-            "<ul>\n\t",
-            lists:foldl(fun({Module, Percentage}, Acc) ->
-                        Name = atom_to_list(Module),
-                        [
-                            "<li>"
-                            "<a href=\"", Name ++ ".html" "\">",
-                            Name,
-                            "</a> ", integer_to_list(Percentage), "%"
-                            "</li>\n\t" |
-                            Acc
-                        ]
-                end, [], ModulesPersentage),
-            "</ul></body></html>"
-        ]).
-
-percentage([Module | Modules], TotCovered, TotLines, Percentages) ->
-    {ok, Analasys} = cover:analyse(Module, coverage, line),
-    {Covered, Lines} = lists:foldl(fun({_, {C, _}}, {Covered, Lines}) ->
-                {C + Covered, Lines + 1}
-        end, {0, 0}, Analasys),
-    Percent = (Covered * 100) div Lines,
-    NewPercentages = [{Module, Percent} | Percentages],
-    percentage(Modules, Covered + TotCovered, Lines + TotLines, NewPercentages);
-percentage([], Covered, Lines, Percentages) ->
-    {(Covered * 100) div Lines, Percentages}.
-
-get_modules() ->
-    application:load(lhttpc),
-    {ok, Modules} = application:get_key(lhttpc, modules),
-    Modules.
-
-cover_compile([Module | Modules]) ->
-    {ok, Module} = cover:compile_beam(Module),
-    cover_compile(Modules);
-cover_compile([]) ->
-    ok.
-
-%%% Eunit functions
-application_test_() ->
-    {application, lhttpc}.

File util/make_doc.erl

+%%% ----------------------------------------------------------------------------
+%%% Copyright (c) 2009, Erlang Training and Consulting Ltd.
+%%% All rights reserved.
+%%% 
+%%% Redistribution and use in source and binary forms, with or without
+%%% modification, are permitted provided that the following conditions are met:
+%%%    * Redistributions of source code must retain the above copyright
+%%%      notice, this list of conditions and the following disclaimer.
+%%%    * Redistributions in binary form must reproduce the above copyright
+%%%      notice, this list of conditions and the following disclaimer in the
+%%%      documentation and/or other materials provided with the distribution.
+%%%    * Neither the name of Erlang Training and Consulting Ltd. nor the
+%%%      names of its contributors may be used to endorse or promote products
+%%%      derived from this software without specific prior written permission.
+%%% 
+%%% THIS SOFTWARE IS PROVIDED BY Erlang Training and Consulting Ltd. ''AS IS''
+%%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+%%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+%%% ARE DISCLAIMED. IN NO EVENT SHALL Erlang Training and Consulting Ltd. BE
+%%% LIABLE SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+%%% BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+%%% WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+%%% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+%%% ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+%%% ----------------------------------------------------------------------------
+
+%%% @author Oscar Hellström <oscar@erlang-consulting.com>
+-module(make_doc).
+-export([edoc/0]).
+
+edoc() ->
+    try
+        edoc:application(lhttpc, "./", [{doc, "doc/"}])
+    catch _:_ ->
+        halt(1)
+    end,
+    halt(0).

File util/releaser

+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Copyright (c) 2009, Erlang Training and Consulting Ltd.
+# All rights reserved.
+# 
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#    * Redistributions of source code must retain the above copyright
+#      notice, this list of conditions and the following disclaimer.
+#    * Redistributions in binary form must reproduce the above copyright
+#      notice, this list of conditions and the following disclaimer in the
+#      documentation and/or other materials provided with the distribution.
+#    * Neither the name of Erlang Training and Consulting Ltd. nor the
+#      names of its contributors may be used to endorse or promote products
+#      derived from this software without specific prior written permission.
+# 
+# THIS SOFTWARE IS PROVIDED BY Erlang Training and Consulting Ltd. ''AS IS''
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL Erlang Training and Consulting Ltd. BE
+# LIABLE SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+# ----------------------------------------------------------------------------
+# Script for making a release of lhttpc. Or any program in hg really. Check
+# the Makefile target release for how to use it.
+
+NAME=$1
+VSN=$2
+
+yesno() {
+    prompt=$1
+    while true; do
+        read -p "$1 [Y/n] " answer
+        case "x$answer" in
+            "x")
+            return 0
+            ;;
+            "xY")
+            return 0
+            ;;
+            "xy")
+            return 0
+            ;;
+            "xN")
+            return 1
+            ;;
+            "xn")
+            return 1
+            ;;
+            *)
+            ;;
+        esac
+    done
+}
+
+get_version() {
+    while true; do
+        read -p "What is the version of the release? [$VSN] " release_vsn
+
+        if [ "$release_vsn" = "" ]; then
+            release_vsn=$VSN
+        fi
+
+        if $(echo "$TAGS" | grep -q "^$release_vsn\$"); then
+            if yesno "A tag exists for version $release_vsn, is this correct?"; then
+                break
+            fi
+        else
+            if yesno "A tag doesn't exist for version $release_vsn, should one be created?"; then
+                hg tag $release_vsn
+            fi
+            break
+        fi
+    done
+    echo $release_vsn
+}
+
+if ! hg identify 1>/dev/null 2>&1; then
+    echo "No hg repository here..."
+    exit 1
+fi
+
+if ! [ "$(hg identify | awk '{print $2};')" = "tip" ]; then
+    if ! yesno "Repository is not at tip, do you want to continue?"; then
+        exit 1
+    fi
+fi
+
+if ! yesno "Did the compilation run without warnings?"; then
+    "Try again..."
+    exit 1
+fi
+
+if ! yesno "Is the changelog up to date?"; then
+    "Try again..."
+    exit 1
+fi
+
+if ! yesno "Did dialyzer run without warnings?"; then
+    "Try again..."
+    exit 1
+fi
+
+TAGS=$(hg tags | awk '{print $1 };' | grep -v "^tip$")
+LATEST_TAG=$(echo "$TAGS" | head -n 1)
+
+RELEASE_VSN=$(get_version)
+echo "Creating a release for $NAME-$RELEASE_VSN now."
+archive="./$NAME-$RELEASE_VSN.tar.gz"
+if [ -e $archive ]; then
+    echo "$archive exists, giving up."
+    exit 1
+fi
+hg archive -t tgz -X ".hg*" $archive

File util/run_test.erl

+%%% ----------------------------------------------------------------------------
+%%% Copyright (c) 2009, Erlang Training and Consulting Ltd.
+%%% All rights reserved.
+%%% 
+%%% Redistribution and use in source and binary forms, with or without
+%%% modification, are permitted provided that the following conditions are met:
+%%%    * Redistributions of source code must retain the above copyright
+%%%      notice, this list of conditions and the following disclaimer.
+%%%    * Redistributions in binary form must reproduce the above copyright
+%%%      notice, this list of conditions and the following disclaimer in the
+%%%      documentation and/or other materials provided with the distribution.
+%%%    * Neither the name of Erlang Training and Consulting Ltd. nor the
+%%%      names of its contributors may be used to endorse or promote products
+%%%      derived from this software without specific prior written permission.
+%%% 
+%%% THIS SOFTWARE IS PROVIDED BY Erlang Training and Consulting Ltd. ''AS IS''
+%%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+%%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+%%% ARE DISCLAIMED. IN NO EVENT SHALL Erlang Training and Consulting Ltd. BE
+%%% LIABLE SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+%%% BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+%%% WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+%%% OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+%%% ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+%%% ----------------------------------------------------------------------------
+
+%%% @author Oscar Hellström <oscar@erlang-consulting.com>
+-module(run_test).
+-export([run/0]).
+
+-include_lib("eunit/include/eunit.hrl").
+-include_lib("stdlib/include/ms_transform.hrl").
+
+-define(TEST_LOG, "test/error_logger.log").
+-define(SASL_LOG, "test/sasl.log").
+-define(FILE_NAME(MODULE),
+    "cover_report/" ++ atom_to_list(MODULE) ++ ".html").
+
+run() ->
+    Modules = get_modules(),
+    ok = cover_compile(Modules),
+    start_logging(),
+    Result = eunit:test(?MODULE, [verbose]),
+    filelib:ensure_dir("cover_report/index.html"),
+    html_report(Modules),
+    write_report(Modules),
+    stop_logging(),
+    io:format("Cover report in cover_report/index.html~n"),
+    io:format("Test logs in ~s and ~s~n", [?TEST_LOG, ?SASL_LOG]),
+    if
+        Result =:= ok -> halt(0);
+        Result =/= ok -> halt(1)
+    end.
+
+start_logging() ->
+    application:load(sasl),
+    application:set_env(sasl, sasl_error_logger, {file, ?SASL_LOG}),
+    file:delete(?TEST_LOG),
+    file:delete(?SASL_LOG),
+    error_logger:tty(false),
+    error_logger:logfile({open, ?TEST_LOG}),
+    application:start(sasl).
+
+stop_logging() ->
+    error_logger:logfile(close),
+    application:stop(sasl).
+
+html_report([Module | Modules]) ->
+    cover:analyse_to_file(Module, ?FILE_NAME(Module), [html]),
+    html_report(Modules);
+html_report([]) ->
+    ok.
+
+write_report(Modules) ->
+    {TotalPercentage, ModulesPersentage} = percentage(Modules, 0, 0, []),
+    file:write_file("cover_report/index.html",
+        [
+            "<html>\n<head><title>Cover report index</title></head>\n"
+            "<body>\n"
+            "<h1>Cover report for lhttpc</h1>"
+            "Total coverage: ", integer_to_list(TotalPercentage), "%"
+            "<h2>Cover for individual modules</h2>\n"
+            "<ul>\n\t",
+            lists:foldl(fun({Module, Percentage}, Acc) ->
+                        Name = atom_to_list(Module),
+                        [
+                            "<li>"
+                            "<a href=\"", Name ++ ".html" "\">",
+                            Name,
+                            "</a> ", integer_to_list(Percentage), "%"
+                            "</li>\n\t" |
+                            Acc
+                        ]
+                end, [], ModulesPersentage),
+            "</ul></body></html>"
+        ]).
+
+percentage([Module | Modules], TotCovered, TotLines, Percentages) ->
+    {ok, Analasys} = cover:analyse(Module, coverage, line),
+    {Covered, Lines} = lists:foldl(fun({_, {C, _}}, {Covered, Lines}) ->
+                {C + Covered, Lines + 1}
+        end, {0, 0}, Analasys),
+    Percent = (Covered * 100) div Lines,
+    NewPercentages = [{Module, Percent} | Percentages],
+    percentage(Modules, Covered + TotCovered, Lines + TotLines, NewPercentages);
+percentage([], Covered, Lines, Percentages) ->
+    {(Covered * 100) div Lines, Percentages}.
+
+get_modules() ->
+    application:load(lhttpc),
+    {ok, Modules} = application:get_key(lhttpc, modules),
+    Modules.
+
+cover_compile([Module | Modules]) ->
+    {ok, Module} = cover:compile_beam(Module),
+    cover_compile(Modules);
+cover_compile([]) ->
+    ok.
+
+%%% Eunit functions
+application_test_() ->
+    {application, lhttpc}.