summaryrefslogtreecommitdiff
path: root/deps/mochiweb/support
diff options
context:
space:
mode:
authorMicah Anderson <micah@leap.se>2014-01-15 18:13:16 +0000
committerdrebs <drebs@leap.se>2014-01-17 08:48:11 -0200
commit510c6d763fba74f95ae8f894408c3658bcef4f83 (patch)
treed4dd0930b902cb1e5d46bea621ec83f801ea8ed6 /deps/mochiweb/support
parent8bd863936ead4243f58fb99e11d1221e1af0a71e (diff)
embed dependencies that were previously pulled in by git during rebar build
Diffstat (limited to 'deps/mochiweb/support')
-rw-r--r--deps/mochiweb/support/include.mk41
-rwxr-xr-xdeps/mochiweb/support/make_app.escript86
-rwxr-xr-xdeps/mochiweb/support/run_tests.escript94
-rw-r--r--deps/mochiweb/support/test-materials/test_ssl_cert.pem19
-rw-r--r--deps/mochiweb/support/test-materials/test_ssl_key.pem27
5 files changed, 267 insertions, 0 deletions
diff --git a/deps/mochiweb/support/include.mk b/deps/mochiweb/support/include.mk
new file mode 100644
index 00000000..bdfdd840
--- /dev/null
+++ b/deps/mochiweb/support/include.mk
@@ -0,0 +1,41 @@
+## -*- makefile -*-
+
+######################################################################
+## Erlang
+
+ERL := erl
+ERLC := $(ERL)c
+
+INCLUDE_DIRS := ../include $(wildcard ../deps/*/include)
+EBIN_DIRS := $(wildcard ../deps/*/ebin)
+ERLC_FLAGS := -W $(INCLUDE_DIRS:../%=-I ../%) $(EBIN_DIRS:%=-pa %)
+
+ifndef no_debug_info
+ ERLC_FLAGS += +debug_info
+endif
+
+ifdef debug
+ ERLC_FLAGS += -Ddebug
+endif
+
+EBIN_DIR := ../ebin
+TEST_DIR := ../_test
+EMULATOR := beam
+
+ERL_SOURCES := $(wildcard *.erl)
+ERL_HEADERS := $(wildcard *.hrl) $(wildcard ../include/*.hrl)
+ERL_OBJECTS := $(ERL_SOURCES:%.erl=$(EBIN_DIR)/%.$(EMULATOR))
+ERL_OBJECTS_LOCAL := $(ERL_SOURCES:%.erl=./%.$(EMULATOR))
+APP_FILES := $(wildcard *.app.src)
+EBIN_FILES = $(ERL_OBJECTS) $(APP_FILES:%.app.src=../ebin/%.app)
+MODULES = $(ERL_SOURCES:%.erl=%)
+
+../ebin/%.app: %.app.src
+ ../support/make_app.escript $< $@ "" "$(MODULES)"
+
+
+$(EBIN_DIR)/%.$(EMULATOR): %.erl
+ $(ERLC) $(ERLC_FLAGS) -o $(EBIN_DIR) $<
+
+./%.$(EMULATOR): %.erl
+ $(ERLC) $(ERLC_FLAGS) -o . $<
diff --git a/deps/mochiweb/support/make_app.escript b/deps/mochiweb/support/make_app.escript
new file mode 100755
index 00000000..0d0b84b3
--- /dev/null
+++ b/deps/mochiweb/support/make_app.escript
@@ -0,0 +1,86 @@
+#!/usr/bin/env escript
+%% -*- erlang -*-
+
+main(Args) ->
+ [AppSrc,AppF,Vsn,Modules] = Args,
+ {Comments, L, App} = parse_appsrc(AppSrc),
+ {application, A, Attrs} = App,
+ Attrs1 = [vsn(Vsn, Attrs),
+ descr(Attrs),
+ {modules, lists:sort([list_to_atom(M) || M <- string:tokens(Modules," ")])} |
+ [Attr || {K,_} = Attr <- Attrs,
+ not lists:member(K, [vsn, modules, description])]],
+ write_app(AppF, Comments, L, {application, A, Attrs1}).
+
+write_app(F, Comments, TermL, App) ->
+ case file:open(F, [write]) of
+ {ok, Fd} ->
+ try L = write_comments(Comments, Fd),
+ write_term(App, L, TermL, Fd)
+ after
+ file:close(Fd)
+ end;
+ Error ->
+ error(Error)
+ end.
+
+parse_appsrc(F) ->
+ case file:read_file(F) of
+ {ok, B} ->
+ case erl_scan:string(binary_to_list(B), 1, [return_comments]) of
+ {ok, Toks, _} ->
+ Comments = lists:takewhile(
+ fun({comment,_,_}) -> true;
+ (_) -> false
+ end, Toks),
+ TermToks = [T || T <- Toks, element(1,T) =/= comment],
+ TermL = element(2, hd(TermToks)),
+ case erl_parse:parse_term(TermToks) of
+ {ok, {application, _A, _Attrs} = App} ->
+ {Comments, TermL, App};
+ Error ->
+ error(Error)
+ end;
+ ScanErr ->
+ error(ScanErr)
+ end;
+ ReadErr ->
+ error(ReadErr)
+ end.
+
+write_comments(Comments, Fd) ->
+ lists:foldl(
+ fun({comment, L, C}, L0) ->
+ S = ["\n" || _ <- lists:seq(1,L-L0)] ++ C,
+ io:put_chars(Fd, S),
+ L
+ end, 1, Comments).
+
+write_term(T, L0, TermL, Fd) ->
+ case ["\n" || _ <- lists:seq(1,TermL-L0)] of
+ [] -> ok;
+ S -> io:put_chars(Fd, S)
+ end,
+ io:fwrite(Fd, "~p.~n", [T]).
+
+vsn(Vsn, Attrs) when Vsn =:= '' orelse Vsn =:= "" ->
+ case lists:keyfind(vsn, 1, Attrs) of
+ false ->
+ {vsn, "0.00"};
+ V ->
+ V
+ end;
+vsn(Vsn, _Attrs) ->
+ {vsn, Vsn}.
+
+descr(Attrs) ->
+ case lists:keyfind(description, 1, Attrs) of
+ false ->
+ {description, "auto_generated .app file"};
+ D ->
+ D
+ end.
+
+error(E) ->
+ io:fwrite("*** ~p~n", [E]),
+ halt(1).
diff --git a/deps/mochiweb/support/run_tests.escript b/deps/mochiweb/support/run_tests.escript
new file mode 100755
index 00000000..ff49c064
--- /dev/null
+++ b/deps/mochiweb/support/run_tests.escript
@@ -0,0 +1,94 @@
+#!/usr/bin/env escript
+%% -*- erlang -*-
+%%! -name mochiweb__test@127.0.0.1
+main([Ebin]) ->
+ code:add_path(Ebin),
+ code:add_paths(filelib:wildcard("../deps/*/ebin", Ebin)),
+ code:add_paths(filelib:wildcard("../deps/*/deps/*/ebin", Ebin)),
+
+ ModuleNames = [hd(string:tokens(M, "."))
+ || "../src/" ++ M <- filelib:wildcard("../src/*.erl")],
+
+ {ok, NonTestRe} = re:compile("_tests$"),
+ Modules = [list_to_atom(M) ||
+ M <- lists:filter(
+ fun(M) ->
+ nomatch == re:run(M, NonTestRe)
+ end,
+ ModuleNames)],
+
+
+ crypto:start(),
+ start_cover(Modules),
+ eunit:test(Modules, [verbose,{report,{eunit_surefire,[{dir,"../_test"}]}}]),
+ analyze_cover(Modules);
+main(_) ->
+ io:format("usage: run_tests.escript EBIN_DIR~n"),
+ halt(1).
+
+start_cover(Modules) ->
+ {ok, _Cover} = cover:start(),
+ io:format("Cover compiling...~n"),
+ Compiled = [ M || {ok, M} <- [ cover:compile(
+ M,
+ [{i, "include"}
+ ])
+ || M <- Modules ] ],
+ case length(Modules) == length(Compiled) of
+ true -> ok;
+ false ->
+ io:format("Warning: the following modules were not"
+ " cover-compiled:~n ~p~n", [Compiled])
+ end.
+
+analyze_cover(Modules) ->
+ io:format("Analyzing cover...~n"),
+ CoverBase = filename:join(["..", "_test", "cover"]),
+ ok = filelib:ensure_dir(filename:join([CoverBase, "fake"])),
+ Coverages = lists:foldl(
+ fun(M, Acc) ->
+ [analyze_module(CoverBase, M)|Acc]
+ end,
+ [], Modules),
+ IndexFilename = filename:join([CoverBase, "index.html"]),
+ {ok, Index} = file:open(IndexFilename, [write]),
+ {LineTotal, CoverTotal} =
+ lists:foldl(fun({_,_,Lines,Covered}, {LineAcc, CovAcc}) ->
+ {LineAcc+Lines, CovAcc+Covered}
+ end, {0,0}, Coverages),
+ file:write(Index,
+ "<html><head><title>Coverage</title></head>\n"
+ "<body><h1>Coverage</h1><ul>\n"),
+ file:write(Index,
+ io_lib:format("<h2>Total: ~.2f%</h2>\n",
+ [percentage(CoverTotal, LineTotal)])),
+ [ file:write(Index,
+ io_lib:format(
+ "<li><a href=\"~s\">~p</a>: ~.2f%</li>~n",
+ [Filename, Module, percentage(Covered, Lines)]))
+ || {Filename, Module, Lines, Covered} <- Coverages ],
+ file:write(Index,"</ul></body></html>"),
+ file:close(Index),
+ io:format("Cover analysis in ~s~n", [IndexFilename]).
+
+analyze_module(CoverBase, Module) ->
+ {ok, Filename} =
+ cover:analyze_to_file(
+ Module,
+ filename:join(CoverBase, atom_to_list(Module)++".COVER.html"),
+ [html]),
+ Lines = count_lines(Filename, "[[:digit:]]\.\.|"),
+ Covered = count_lines(Filename, "[[:space:]]0\.\.|"),
+ {filename:basename(Filename), Module, Lines, Lines-Covered}.
+
+count_lines(Filename, Pattern) ->
+ {ok, [Lines],_} = io_lib:fread(
+ "~d",
+ os:cmd(io_lib:format("grep -e \"~s\" ~s | wc -l",
+ [Pattern, Filename]))),
+ Lines.
+
+percentage(_, 0) -> 1000.0;
+percentage(Part, Total) ->
+ (Part/Total)*100.
+
diff --git a/deps/mochiweb/support/test-materials/test_ssl_cert.pem b/deps/mochiweb/support/test-materials/test_ssl_cert.pem
new file mode 100644
index 00000000..f84ccca7
--- /dev/null
+++ b/deps/mochiweb/support/test-materials/test_ssl_cert.pem
@@ -0,0 +1,19 @@
+-----BEGIN CERTIFICATE-----
+MIIDIDCCAgigAwIBAgIJAJLkNZzERPIUMA0GCSqGSIb3DQEBBQUAMBQxEjAQBgNV
+BAMTCWxvY2FsaG9zdDAeFw0xMDAzMTgxOTM5MThaFw0yMDAzMTUxOTM5MThaMBQx
+EjAQBgNVBAMTCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
+ggEBAJeUCOZxbmtngF4S5lXckjSDLc+8C+XjMBYBPyy5eKdJY20AQ1s9/hhp3ulI
+8pAvl+xVo4wQ+iBSvOzcy248Q+Xi6+zjceF7UNRgoYPgtJjKhdwcHV3mvFFrS/fp
+9ggoAChaJQWDO1OCfUgTWXImhkw+vcDR11OVMAJ/h73dqzJPI9mfq44PTTHfYtgr
+v4LAQAOlhXIAa2B+a6PlF6sqDqJaW5jLTcERjsBwnRhUGi7JevQzkejujX/vdA+N
+jRBjKH/KLU5h3Q7wUchvIez0PXWVTCnZjpA9aR4m7YV05nKQfxtGd71czYDYk+j8
+hd005jetT4ir7JkAWValBybJVksCAwEAAaN1MHMwHQYDVR0OBBYEFJl9s51SnjJt
+V/wgKWqV5Q6jnv1ZMEQGA1UdIwQ9MDuAFJl9s51SnjJtV/wgKWqV5Q6jnv1ZoRik
+FjAUMRIwEAYDVQQDEwlsb2NhbGhvc3SCCQCS5DWcxETyFDAMBgNVHRMEBTADAQH/
+MA0GCSqGSIb3DQEBBQUAA4IBAQB2ldLeLCc+lxK5i0EZquLamMBJwDIjGpT0JMP9
+b4XQOK2JABIu54BQIZhwcjk3FDJz/uOW5vm8k1kYni8FCjNZAaRZzCUfiUYTbTKL
+Rq9LuIAODyP2dnTqyKaQOOJHvrx9MRZ3XVecXPS0Tib4aO57vCaAbIkmhtYpTWmw
+e3t8CAIDVtgvjR6Se0a1JA4LktR7hBu22tDImvCSJn1nVAaHpani6iPBPPdMuMsP
+TBoeQfj8VpqBUjCStqJGa8ytjDFX73YaxV2mgrtGwPNme1x3YNRR11yTu7tksyMO
+GrmgxNriqYRchBhNEf72AKF0LR1ByKwfbDB9rIsV00HtCgOp
+-----END CERTIFICATE-----
diff --git a/deps/mochiweb/support/test-materials/test_ssl_key.pem b/deps/mochiweb/support/test-materials/test_ssl_key.pem
new file mode 100644
index 00000000..69bbf823
--- /dev/null
+++ b/deps/mochiweb/support/test-materials/test_ssl_key.pem
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEpAIBAAKCAQEAl5QI5nFua2eAXhLmVdySNIMtz7wL5eMwFgE/LLl4p0ljbQBD
+Wz3+GGne6UjykC+X7FWjjBD6IFK87NzLbjxD5eLr7ONx4XtQ1GChg+C0mMqF3Bwd
+Xea8UWtL9+n2CCgAKFolBYM7U4J9SBNZciaGTD69wNHXU5UwAn+Hvd2rMk8j2Z+r
+jg9NMd9i2Cu/gsBAA6WFcgBrYH5ro+UXqyoOolpbmMtNwRGOwHCdGFQaLsl69DOR
+6O6Nf+90D42NEGMof8otTmHdDvBRyG8h7PQ9dZVMKdmOkD1pHibthXTmcpB/G0Z3
+vVzNgNiT6PyF3TTmN61PiKvsmQBZVqUHJslWSwIDAQABAoIBACI8Ky5xHDFh9RpK
+Rn/KC7OUlTpADKflgizWJ0Cgu2F9L9mkn5HyFHvLHa+u7CootbWJOiEejH/UcBtH
+WyMQtX0snYCpdkUpJv5wvMoebGu+AjHOn8tf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