erlbox 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/LICENSE +19 -0
- data/README.txt +1 -0
- data/Rakefile +48 -0
- data/VERSION.yml +4 -0
- data/bin/erlbox +202 -0
- data/erlbox.gemspec +61 -0
- data/lib/erlbox/build.rb +99 -0
- data/lib/erlbox/dialyzer.rb +81 -0
- data/lib/erlbox/driver.rb +98 -0
- data/lib/erlbox/edoc.rb +43 -0
- data/lib/erlbox/eunit +152 -0
- data/lib/erlbox/eunit.rb +96 -0
- data/lib/erlbox/faxien.rb +65 -0
- data/lib/erlbox/install.rb +38 -0
- data/lib/erlbox/recurse.rb +44 -0
- data/lib/erlbox/release.rb +72 -0
- data/lib/erlbox/snmp.rb +55 -0
- data/lib/erlbox/test.rb +165 -0
- data/lib/erlbox/utils.rb +105 -0
- data/lib/erlbox.rb +43 -0
- metadata +85 -0
data/lib/erlbox/eunit
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
#!/usr/bin/env escript
|
2
|
+
%% Copyright (c) 2009 The Hive http://www.thehive.com/
|
3
|
+
%%
|
4
|
+
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
%% of this software and associated documentation files (the "Software"), to deal
|
6
|
+
%% in the Software without restriction, including without limitation the rights
|
7
|
+
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
%% copies of the Software, and to permit persons to whom the Software is
|
9
|
+
%% furnished to do so, subject to the following conditions:
|
10
|
+
%%
|
11
|
+
%% The above copyright notice and this permission notice shall be included in
|
12
|
+
%% all copies or substantial portions of the Software.
|
13
|
+
%%
|
14
|
+
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
%% THE SOFTWARE.
|
21
|
+
%%
|
22
|
+
|
23
|
+
main(Args) ->
|
24
|
+
Opts = parse_args(Args, dict:new()),
|
25
|
+
Files = find_test_files(Opts),
|
26
|
+
ok = init_logging(Opts),
|
27
|
+
maybe_cover_compile(Opts),
|
28
|
+
eunit:test(test_names(Files), test_flags(Opts)),
|
29
|
+
maybe_analyze_cover(Opts).
|
30
|
+
|
31
|
+
|
32
|
+
parse_args([], Opts) ->
|
33
|
+
Opts;
|
34
|
+
parse_args(["-v"|Rest], Opts) ->
|
35
|
+
parse_args(Rest, dict:store(verbose, true, Opts));
|
36
|
+
parse_args(["-cover"|Rest], Opts) ->
|
37
|
+
parse_args(Rest, dict:store(cover, true, Opts));
|
38
|
+
parse_args(["-o", Dir|Rest], Opts) ->
|
39
|
+
parse_args(Rest, dict:store(cover_dir, Dir, Opts));
|
40
|
+
parse_args(["-l", LogFile|Rest], Opts) ->
|
41
|
+
parse_args(Rest, dict:store(log_file, LogFile, Opts));
|
42
|
+
parse_args(["-b", Path|Rest], Opts) ->
|
43
|
+
true = code:add_path(Path),
|
44
|
+
parse_args(Rest, dict:store(bin_dir, Path, Opts));
|
45
|
+
parse_args(["-s", SuiteName|Rest], Opts) ->
|
46
|
+
Suite = list_to_atom(SuiteName),
|
47
|
+
F = fun(Suites) -> [Suite|Suites] end,
|
48
|
+
parse_args(Rest, dict:update(suites, F, [Suite], Opts));
|
49
|
+
parse_args([Dir|Rest], Opts) ->
|
50
|
+
true = code:add_patha(Dir),
|
51
|
+
parse_args(Rest, dict:store(test_dir, Dir, Opts)).
|
52
|
+
|
53
|
+
find_test_files(Opts) ->
|
54
|
+
case dict:find(suites, Opts) of
|
55
|
+
error ->
|
56
|
+
case dict:find(test_dir, Opts) of
|
57
|
+
error ->
|
58
|
+
io:fwrite("Error! Must provide test directory or suite names."),
|
59
|
+
[];
|
60
|
+
|
61
|
+
{ok, Dir} ->
|
62
|
+
case file:list_dir(Dir) of
|
63
|
+
{ok, Files} ->
|
64
|
+
F = fun(File, Acc0) ->
|
65
|
+
case lists:suffix("_tests.erl", File) of
|
66
|
+
true -> [File|Acc0];
|
67
|
+
false -> Acc0
|
68
|
+
end
|
69
|
+
end,
|
70
|
+
|
71
|
+
lists:foldl(F, [], Files);
|
72
|
+
|
73
|
+
_ ->
|
74
|
+
[]
|
75
|
+
end
|
76
|
+
end;
|
77
|
+
|
78
|
+
{ok, Suites} ->
|
79
|
+
Suites
|
80
|
+
end.
|
81
|
+
|
82
|
+
init_logging(Opts) ->
|
83
|
+
% Turn off logging to to tty
|
84
|
+
ok = error_logger:tty(false),
|
85
|
+
% send logging to a log file
|
86
|
+
case dict:find(log_file, Opts) of
|
87
|
+
error ->
|
88
|
+
ok; % logging disabled
|
89
|
+
{ok, LogFile} ->
|
90
|
+
error_logger:logfile({open, LogFile})
|
91
|
+
end.
|
92
|
+
|
93
|
+
test_names(Files) ->
|
94
|
+
[list_to_atom(filename:basename(F, ".erl")) || F <- Files].
|
95
|
+
|
96
|
+
test_flags(Opts) ->
|
97
|
+
case dict:find(verbose, Opts) of
|
98
|
+
{ok, true} -> [verbose];
|
99
|
+
{ok, false} -> [];
|
100
|
+
error -> []
|
101
|
+
end.
|
102
|
+
|
103
|
+
cover_enabled(Opts) ->
|
104
|
+
case dict:find(cover, Opts) of
|
105
|
+
{ok, true} -> true;
|
106
|
+
{ok, false} -> false;
|
107
|
+
error -> false
|
108
|
+
end.
|
109
|
+
|
110
|
+
maybe_cover_compile(Opts) ->
|
111
|
+
case cover_enabled(Opts) of
|
112
|
+
true ->
|
113
|
+
case dict:find(bin_dir, Opts) of
|
114
|
+
error -> BinDir = "./ebin";
|
115
|
+
{ok, BinDir} -> BinDir
|
116
|
+
end,
|
117
|
+
io:fwrite("Cover compiling modules in ~s~n", [BinDir]),
|
118
|
+
cover:compile_beam_directory(BinDir);
|
119
|
+
|
120
|
+
false ->
|
121
|
+
ok
|
122
|
+
end.
|
123
|
+
|
124
|
+
maybe_analyze_cover(Opts) ->
|
125
|
+
case cover_enabled(Opts) of
|
126
|
+
true ->
|
127
|
+
io:fwrite("Generating coverage report...~n"),
|
128
|
+
case dict:find(cover_dir, Opts) of
|
129
|
+
error -> CoverDir = "./coverage";
|
130
|
+
{ok, CoverDir} -> CoverDir
|
131
|
+
end,
|
132
|
+
ok = filelib:ensure_dir(filename:join(CoverDir, ".dummy")),
|
133
|
+
cover:export(filename:join(CoverDir, "all.coverdata")),
|
134
|
+
|
135
|
+
Modules = lists:reverse(cover:modules()),
|
136
|
+
F = fun(Mod, PctList) ->
|
137
|
+
{ok, {_, {Cov, NotCov}}} = cover:analyse(Mod, module),
|
138
|
+
Pct = (Cov / (Cov + NotCov)) * 100,
|
139
|
+
io:fwrite("~5B ~5B ~5.1f% ~p~n", [Cov, NotCov, Pct, Mod]),
|
140
|
+
|
141
|
+
OutFile = filename:join([CoverDir,
|
142
|
+
atom_to_list(Mod) ++ ".COVER.html"]),
|
143
|
+
cover:analyse_to_file(Mod, OutFile, [html]),
|
144
|
+
|
145
|
+
[Pct|PctList]
|
146
|
+
end,
|
147
|
+
PctList = lists:foldl(F, [], Modules),
|
148
|
+
io:fwrite("~17.1f% TOTAL", [lists:sum(PctList) / length(PctList)]);
|
149
|
+
|
150
|
+
false ->
|
151
|
+
ok
|
152
|
+
end.
|
data/lib/erlbox/eunit.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
## -------------------------------------------------------------------
|
2
|
+
##
|
3
|
+
## Erlang Toolbox: Included tasks for running eunit tests
|
4
|
+
## Copyright (c) 2009 The Hive http://www.thehive.com/
|
5
|
+
##
|
6
|
+
## Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
## of this software and associated documentation files (the "Software"), to deal
|
8
|
+
## in the Software without restriction, including without limitation the rights
|
9
|
+
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
## copies of the Software, and to permit persons to whom the Software is
|
11
|
+
## furnished to do so, subject to the following conditions:
|
12
|
+
##
|
13
|
+
## The above copyright notice and this permission notice shall be included in
|
14
|
+
## all copies or substantial portions of the Software.
|
15
|
+
##
|
16
|
+
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
## THE SOFTWARE.
|
23
|
+
##
|
24
|
+
## -------------------------------------------------------------------
|
25
|
+
|
26
|
+
## -------------------------------------------------------------------
|
27
|
+
## Constants
|
28
|
+
|
29
|
+
EUNIT_SRC = FileList['test/*.erl']
|
30
|
+
EUNIT_SRC.exclude('test/*_SUITE.erl') # exclude CT suites
|
31
|
+
|
32
|
+
EUNIT_BEAM = EUNIT_SRC.pathmap('%X.beam')
|
33
|
+
EUNIT_LOG_DIR = TEST_LOG_DIR
|
34
|
+
EUNIT_WORK_DIR = "#{EUNIT_LOG_DIR}/working"
|
35
|
+
|
36
|
+
CLOBBER.include 'coverage'
|
37
|
+
|
38
|
+
## -------------------------------------------------------------------
|
39
|
+
## Tasks
|
40
|
+
|
41
|
+
rule '.beam' => "%X.erl" do |t|
|
42
|
+
puts "compiling #{t.source}..."
|
43
|
+
dir = t.name.pathmap("%d")
|
44
|
+
sh "erlc #{print_flags(ERLC_FLAGS)} #{expand_path(ERL_PATH)} -o #{dir} #{t.source}"
|
45
|
+
end
|
46
|
+
|
47
|
+
directory EUNIT_LOG_DIR
|
48
|
+
directory EUNIT_WORK_DIR
|
49
|
+
|
50
|
+
namespace :eunit do
|
51
|
+
|
52
|
+
desc 'Eunit test preparation'
|
53
|
+
task :prepare => [EUNIT_LOG_DIR] do
|
54
|
+
# Remove the working directory to ensure there isn't stale data laying around
|
55
|
+
FileUtils.rm_rf EUNIT_WORK_DIR
|
56
|
+
# Always compile tests with debug info
|
57
|
+
puts 'Debugging is enabled for test builds.'
|
58
|
+
ERLC_FLAGS << '+debug_info'
|
59
|
+
end
|
60
|
+
|
61
|
+
desc 'Compile eunit test sources'
|
62
|
+
task :compile => ['prepare', 'build:compile'] + EUNIT_BEAM
|
63
|
+
|
64
|
+
desc 'Run eunit tests'
|
65
|
+
task :test => [:compile, EUNIT_WORK_DIR] do
|
66
|
+
run_eunit('test', ENV['cover'])
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
task :eunit => 'eunit:test'
|
72
|
+
|
73
|
+
## -------------------------------------------------------------------
|
74
|
+
## Helpers
|
75
|
+
|
76
|
+
def run_eunit(dir, cover = false, rest = '')
|
77
|
+
puts "running tests in #{dir}#{' with coverage' if cover}..."
|
78
|
+
|
79
|
+
log_dir = abspath(EUNIT_LOG_DIR)
|
80
|
+
|
81
|
+
cover_flags = cover ? "-cover -o #{log_dir}/coverage" : ''
|
82
|
+
|
83
|
+
suites = ENV['suites']
|
84
|
+
all_suites = ''
|
85
|
+
suites.each(' ') {|s| all_suites << "-s #{s.strip} "} if suites
|
86
|
+
|
87
|
+
script = __FILE__.sub('.rb', '')
|
88
|
+
|
89
|
+
cmd = "cd #{EUNIT_WORK_DIR} &&\
|
90
|
+
#{script} -b #{abspath('./ebin')} -l #{log_dir}/eunit.log\
|
91
|
+
#{cover_flags} #{all_suites} #{abspath(dir)}"
|
92
|
+
|
93
|
+
puts cmd.squeeze(' ') if verbose?
|
94
|
+
|
95
|
+
sh cmd
|
96
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
## -------------------------------------------------------------------
|
2
|
+
##
|
3
|
+
## Erlang Toolbox: Included tasks for packaging and publishing to Faxien
|
4
|
+
## Copyright (c) 2008 The Hive http://www.thehive.com/
|
5
|
+
##
|
6
|
+
## Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
## of this software and associated documentation files (the "Software"), to deal
|
8
|
+
## in the Software without restriction, including without limitation the rights
|
9
|
+
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
## copies of the Software, and to permit persons to whom the Software is
|
11
|
+
## furnished to do so, subject to the following conditions:
|
12
|
+
##
|
13
|
+
## The above copyright notice and this permission notice shall be included in
|
14
|
+
## all copies or substantial portions of the Software.
|
15
|
+
##
|
16
|
+
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
## THE SOFTWARE.
|
23
|
+
##
|
24
|
+
## -------------------------------------------------------------------
|
25
|
+
|
26
|
+
## -------------------------------------------------------------------
|
27
|
+
## Constants
|
28
|
+
|
29
|
+
PACKAGE_DIR="#{APP_NAME}-#{erl_app_version(APP_NAME)}"
|
30
|
+
|
31
|
+
CLOBBER.include PACKAGE_DIR
|
32
|
+
|
33
|
+
## -------------------------------------------------------------------
|
34
|
+
## Rules
|
35
|
+
|
36
|
+
directory PACKAGE_DIR
|
37
|
+
|
38
|
+
## -------------------------------------------------------------------
|
39
|
+
## Tasks
|
40
|
+
|
41
|
+
namespace :faxien do
|
42
|
+
|
43
|
+
desc "Prepare the application for packaging"
|
44
|
+
task :prepare do
|
45
|
+
FileUtils.rm_rf PACKAGE_DIR
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Package app for publication to a faxien repo"
|
49
|
+
task :package => [:prepare, PACKAGE_DIR] do
|
50
|
+
FileUtils.cp_r 'ebin', PACKAGE_DIR
|
51
|
+
FileUtils.cp_r 'src', PACKAGE_DIR
|
52
|
+
FileUtils.cp_r 'include', PACKAGE_DIR if File.exist?('include')
|
53
|
+
FileUtils.cp_r 'priv', PACKAGE_DIR if File.exist?('priv')
|
54
|
+
FileUtils.cp_r 'mibs', PACKAGE_DIR if File.exist?('mibs')
|
55
|
+
puts "Packaged to #{PACKAGE_DIR}"
|
56
|
+
end
|
57
|
+
|
58
|
+
desc "Publish a packaged application to a faxien repo"
|
59
|
+
task :publish do
|
60
|
+
sh "faxien publish #{PACKAGE_DIR}"
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
task :faxien => ['faxien:package', 'faxien:publish']
|
@@ -0,0 +1,38 @@
|
|
1
|
+
## -------------------------------------------------------------------
|
2
|
+
##
|
3
|
+
## Erlang Toolbox: Helper tasks for installing an app into erlang
|
4
|
+
## Copyright (c) 2009 The Hive http://www.thehive.com/
|
5
|
+
##
|
6
|
+
## Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
## of this software and associated documentation files (the "Software"), to deal
|
8
|
+
## in the Software without restriction, including without limitation the rights
|
9
|
+
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
## copies of the Software, and to permit persons to whom the Software is
|
11
|
+
## furnished to do so, subject to the following conditions:
|
12
|
+
##
|
13
|
+
## The above copyright notice and this permission notice shall be included in
|
14
|
+
## all copies or substantial portions of the Software.
|
15
|
+
##
|
16
|
+
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
## THE SOFTWARE.
|
23
|
+
##
|
24
|
+
## -------------------------------------------------------------------
|
25
|
+
|
26
|
+
namespace :install do
|
27
|
+
|
28
|
+
task :appid, [:root_dir] do |t, args|
|
29
|
+
puts "#{APP_NAME}-#{erl_app_version(APP_NAME, :erl_root => args.root_dir)}"
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Hook to allow bootstrapping a new repo during installation"
|
33
|
+
task :prepare
|
34
|
+
|
35
|
+
desc "Build the application for installation"
|
36
|
+
task :build => [:compile]
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
## -------------------------------------------------------------------
|
2
|
+
##
|
3
|
+
## Erlang Toolbox: Recursive task definitions
|
4
|
+
## Copyright (c) 2008 The Hive http://www.thehive.com/
|
5
|
+
##
|
6
|
+
## Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
## of this software and associated documentation files (the "Software"), to deal
|
8
|
+
## in the Software without restriction, including without limitation the rights
|
9
|
+
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
## copies of the Software, and to permit persons to whom the Software is
|
11
|
+
## furnished to do so, subject to the following conditions:
|
12
|
+
##
|
13
|
+
## The above copyright notice and this permission notice shall be included in
|
14
|
+
## all copies or substantial portions of the Software.
|
15
|
+
##
|
16
|
+
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
## THE SOFTWARE.
|
23
|
+
##
|
24
|
+
## -------------------------------------------------------------------
|
25
|
+
|
26
|
+
verbose false
|
27
|
+
|
28
|
+
DIRS = FileList.new
|
29
|
+
|
30
|
+
def recurse(task_name)
|
31
|
+
DIRS.each do |dir|
|
32
|
+
puts "===> Building #{dir}"
|
33
|
+
sh "(cd #{dir} && rake --silent #{task_name})"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def recursive_task(target)
|
38
|
+
task_name = target.kind_of?(Hash) ? target.keys.first : target
|
39
|
+
|
40
|
+
desc "Run #{task_name} in subdirs"
|
41
|
+
task target do
|
42
|
+
recurse task_name
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
## -------------------------------------------------------------------
|
2
|
+
##
|
3
|
+
## Erlang Toolbox: OTP release tasks
|
4
|
+
## Copyright (c) 2008 The Hive http://www.thehive.com/
|
5
|
+
##
|
6
|
+
## Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
## of this software and associated documentation files (the "Software"), to deal
|
8
|
+
## in the Software without restriction, including without limitation the rights
|
9
|
+
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
## copies of the Software, and to permit persons to whom the Software is
|
11
|
+
## furnished to do so, subject to the following conditions:
|
12
|
+
##
|
13
|
+
## The above copyright notice and this permission notice shall be included in
|
14
|
+
## all copies or substantial portions of the Software.
|
15
|
+
##
|
16
|
+
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
## THE SOFTWARE.
|
23
|
+
##
|
24
|
+
## -------------------------------------------------------------------
|
25
|
+
require 'rake/clean'
|
26
|
+
include FileUtils
|
27
|
+
|
28
|
+
if !defined?(REL_APPNAME)
|
29
|
+
fail "The variable REL_APPNAME must be defined"
|
30
|
+
end
|
31
|
+
|
32
|
+
verbose false
|
33
|
+
|
34
|
+
CLEAN.include FileList["#{REL_APPNAME}*"]
|
35
|
+
|
36
|
+
REL_APPS = %w( runtime_tools )
|
37
|
+
REL_VERSION = `cat vers/#{REL_APPNAME}.version`.strip
|
38
|
+
REL_FULLNAME = "#{REL_APPNAME}-#{REL_VERSION}"
|
39
|
+
|
40
|
+
ERTS_VSN = `scripts/get-erts-vsn`.strip
|
41
|
+
|
42
|
+
directory REL_APPNAME
|
43
|
+
|
44
|
+
|
45
|
+
task :build_app do
|
46
|
+
cd "../apps" do
|
47
|
+
sh "rake"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Run the make-rel script"
|
52
|
+
task :make_rel do
|
53
|
+
sh "scripts/make-rel #{REL_APPNAME} #{REL_VERSION} #{REL_APPS.join(' ')}"
|
54
|
+
end
|
55
|
+
|
56
|
+
task :prepare => [REL_APPNAME, :make_rel] do
|
57
|
+
sh "tar -xzf #{REL_FULLNAME}.tar.gz -C #{REL_APPNAME}"
|
58
|
+
rm "#{REL_FULLNAME}.tar.gz"
|
59
|
+
|
60
|
+
sh %Q(echo "#{ERTS_VSN} #{REL_VERSION}" > #{REL_APPNAME}/releases/start_erl.data)
|
61
|
+
cp_r Dir.glob("overlays/#{REL_APPNAME}/*"), REL_APPNAME
|
62
|
+
end
|
63
|
+
|
64
|
+
desc "Stage the application into a directory"
|
65
|
+
task :stage => [:clean, :build_app, :prepare]
|
66
|
+
|
67
|
+
desc "Create a tarball from the staged application"
|
68
|
+
task :release => :stage do
|
69
|
+
mv REL_APPNAME, REL_FULLNAME
|
70
|
+
sh "tar -cjf #{REL_FULLNAME}-#{RUBY_PLATFORM}.tar.bz2 #{REL_FULLNAME}"
|
71
|
+
rm_rf REL_FULLNAME
|
72
|
+
end
|
data/lib/erlbox/snmp.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
## -------------------------------------------------------------------
|
2
|
+
##
|
3
|
+
## Erlang Toolbox: Optional SNMP Tasks
|
4
|
+
## Copyright (c) 2008 The Hive http://www.thehive.com/
|
5
|
+
##
|
6
|
+
## Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
## of this software and associated documentation files (the "Software"), to deal
|
8
|
+
## in the Software without restriction, including without limitation the rights
|
9
|
+
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
## copies of the Software, and to permit persons to whom the Software is
|
11
|
+
## furnished to do so, subject to the following conditions:
|
12
|
+
##
|
13
|
+
## The above copyright notice and this permission notice shall be included in
|
14
|
+
## all copies or substantial portions of the Software.
|
15
|
+
##
|
16
|
+
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
## THE SOFTWARE.
|
23
|
+
##
|
24
|
+
## -------------------------------------------------------------------
|
25
|
+
|
26
|
+
if !defined?(APP_NAME)
|
27
|
+
fail "You must require 'erlbox' before requiring this file"
|
28
|
+
end
|
29
|
+
|
30
|
+
## -------------------------------------------------------------------
|
31
|
+
## Constants
|
32
|
+
|
33
|
+
MIBS_DIR = 'priv/mibs'
|
34
|
+
MIB_SRCS = FileList["mibs/*.mib"]
|
35
|
+
MIB_BINS = MIB_SRCS.pathmap("%{mibs,#{MIBS_DIR}}X.bin")
|
36
|
+
|
37
|
+
CLEAN.include MIBS_DIR
|
38
|
+
|
39
|
+
## -------------------------------------------------------------------
|
40
|
+
## Rules
|
41
|
+
|
42
|
+
directory MIBS_DIR
|
43
|
+
|
44
|
+
rule ".bin" => ["%{#{MIBS_DIR},mibs}X.mib"] do |t|
|
45
|
+
puts "compiling #{t.source}..."
|
46
|
+
sh "erlc -I #{MIBS_DIR} -o #{MIBS_DIR} #{t.source}"
|
47
|
+
end
|
48
|
+
|
49
|
+
## -------------------------------------------------------------------
|
50
|
+
## Tasks
|
51
|
+
|
52
|
+
desc "Compile SNMP MIBs"
|
53
|
+
task :snmp => [MIBS_DIR] + MIB_BINS
|
54
|
+
|
55
|
+
task :compile => :snmp
|
data/lib/erlbox/test.rb
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
## -------------------------------------------------------------------
|
2
|
+
##
|
3
|
+
## Erlang Toolbox: Included tasks for running tests
|
4
|
+
## Copyright (c) 2008 The Hive http://www.thehive.com/
|
5
|
+
##
|
6
|
+
## Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
## of this software and associated documentation files (the "Software"), to deal
|
8
|
+
## in the Software without restriction, including without limitation the rights
|
9
|
+
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
## copies of the Software, and to permit persons to whom the Software is
|
11
|
+
## furnished to do so, subject to the following conditions:
|
12
|
+
##
|
13
|
+
## The above copyright notice and this permission notice shall be included in
|
14
|
+
## all copies or substantial portions of the Software.
|
15
|
+
##
|
16
|
+
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
## THE SOFTWARE.
|
23
|
+
##
|
24
|
+
## -------------------------------------------------------------------
|
25
|
+
|
26
|
+
## -------------------------------------------------------------------
|
27
|
+
## Constants
|
28
|
+
|
29
|
+
UNIT_TEST_FLAGS = []
|
30
|
+
INT_TEST_FLAGS = []
|
31
|
+
PERF_TEST_FLAGS = []
|
32
|
+
|
33
|
+
TEST_ROOT = "."
|
34
|
+
TEST_LOG_DIR = "#{TEST_ROOT}/logs"
|
35
|
+
|
36
|
+
UNIT_TEST_DIR = "#{PWD}/#{TEST_ROOT}/test"
|
37
|
+
INT_TEST_DIR = "#{PWD}/#{TEST_ROOT}/int_test"
|
38
|
+
PERF_TEST_DIR = "#{PWD}/#{TEST_ROOT}/perf_test"
|
39
|
+
|
40
|
+
CLOBBER.include TEST_LOG_DIR
|
41
|
+
|
42
|
+
## -------------------------------------------------------------------
|
43
|
+
## Tasks
|
44
|
+
|
45
|
+
namespace :test do
|
46
|
+
|
47
|
+
desc "Test preparation run before all tests"
|
48
|
+
task :prepare do
|
49
|
+
fail "No tests defined" unless File.directory?(TEST_ROOT)
|
50
|
+
Dir.mkdir(TEST_LOG_DIR) unless File.directory?(TEST_LOG_DIR)
|
51
|
+
|
52
|
+
# Always compile tests with debug info
|
53
|
+
puts "Debugging is enabled for test builds."
|
54
|
+
ERLC_FLAGS << '+debug_info'
|
55
|
+
end
|
56
|
+
|
57
|
+
desc "Show test results in a browser"
|
58
|
+
task :results do
|
59
|
+
`open #{TEST_LOG_DIR}/index.html`
|
60
|
+
end
|
61
|
+
|
62
|
+
['unit', 'int', 'perf'].each do |type|
|
63
|
+
desc "Run #{type} tests"
|
64
|
+
task type => "test:#{type}:prepare" do
|
65
|
+
check_and_run_tests(type, false)
|
66
|
+
end
|
67
|
+
|
68
|
+
namespace type do
|
69
|
+
desc "Prepare #{type} tests"
|
70
|
+
task :prepare => ['^prepare', 'compile']
|
71
|
+
|
72
|
+
desc "Compile #{type} tests"
|
73
|
+
task :compile => 'rake:compile'
|
74
|
+
|
75
|
+
desc "Run #{type} tests with coverage"
|
76
|
+
task :cover => :prepare do
|
77
|
+
check_and_run_tests(type, true)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
desc "Run all tests"
|
83
|
+
task :all => [:unit, :int, :perf]
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
task :test => 'test:unit'
|
88
|
+
task :int_test => 'test:int'
|
89
|
+
task :perf_test => 'test:perf'
|
90
|
+
|
91
|
+
## -------------------------------------------------------------------
|
92
|
+
## Helpers
|
93
|
+
|
94
|
+
def test_dir(type)
|
95
|
+
eval("#{type.to_s.upcase}_TEST_DIR")
|
96
|
+
end
|
97
|
+
|
98
|
+
def check_and_run_tests(type, use_cover = false)
|
99
|
+
dir = test_dir(type)
|
100
|
+
if File.directory?(dir)
|
101
|
+
run_tests(dir, use_cover, print_flags(eval("#{type.upcase}_TEST_FLAGS")))
|
102
|
+
else
|
103
|
+
puts "No #{type} tests defined. Skipping."
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def run_tests(dir, cover = false, rest = "")
|
108
|
+
puts "running tests in #{dir}#{' with coverage' if cover}..."
|
109
|
+
|
110
|
+
config_flags = ""
|
111
|
+
if File.exists?("#{dir}/test.config")
|
112
|
+
config_flags << "-ct_config #{dir}/test.config"
|
113
|
+
end
|
114
|
+
|
115
|
+
if File.exists?("#{dir}/app.config")
|
116
|
+
config_flags << " -config #{dir}/app.config"
|
117
|
+
end
|
118
|
+
|
119
|
+
cmd = "erl #{expand_path(ERL_PATH)} -pa #{PWD}/ebin -I#{PWD}/include\
|
120
|
+
-noshell\
|
121
|
+
-s ct_run script_start\
|
122
|
+
-s erlang halt\
|
123
|
+
-name test@#{`hostname`.strip}\
|
124
|
+
#{cover_flags(dir, cover)}\
|
125
|
+
#{get_suites(dir)}\
|
126
|
+
-logdir #{TEST_LOG_DIR}\
|
127
|
+
-env TEST_DIR #{dir}\
|
128
|
+
#{config_flags} #{rest}"
|
129
|
+
|
130
|
+
if !defined?(NOISY_TESTS) && !verbose?
|
131
|
+
output = `#{cmd}`
|
132
|
+
|
133
|
+
fail if $?.exitstatus != 0 && !ENV["stop_on_fail"].nil?
|
134
|
+
|
135
|
+
File.open("#{PWD}/#{TEST_LOG_DIR}/raw.log", "w") do |file|
|
136
|
+
file.write "--- Test run on #{Time.now.to_s} ---\n"
|
137
|
+
file.write output
|
138
|
+
file.write "\n\n"
|
139
|
+
end
|
140
|
+
|
141
|
+
if output[/, 0 failed/]
|
142
|
+
puts "==> " + output[/TEST COMPLETE,.*test cases$/]
|
143
|
+
else
|
144
|
+
puts output
|
145
|
+
end
|
146
|
+
else
|
147
|
+
puts cmd.squeeze(' ')
|
148
|
+
sh cmd
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def cover_flags(dir, use_cover)
|
153
|
+
use_cover ? "-cover #{dir}/cover.spec" : ""
|
154
|
+
end
|
155
|
+
|
156
|
+
def get_suites(dir)
|
157
|
+
suites = ENV['suites']
|
158
|
+
if suites
|
159
|
+
all_suites = ""
|
160
|
+
suites.each(' ') {|s| all_suites << "#{dir}/#{s.strip}_SUITE "}
|
161
|
+
"-suite #{all_suites}"
|
162
|
+
else
|
163
|
+
"-dir #{dir}"
|
164
|
+
end
|
165
|
+
end
|