-
Notifications
You must be signed in to change notification settings - Fork 6
/
Rakefile.test
185 lines (163 loc) · 4.77 KB
/
Rakefile.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
namespace :test do
desc 'sets up the Erlang "common test" framework using sudo'
# Testing
task :setup_ct do |t|
installer = File.join(ct_root,'install.sh')
privbin = File.join(ct_root,'priv','bin')
sh "sudo mkdir -p #{ct_root}/priv/bin"
sh "sudo #{installer} #{otp_lib}"
end
desc 'run tests using common_test'
task :run => ["build:compile"] do |t|
require 'find'
# Probe Environment
runtest = ct_runtest
config = File.expand_path "config/default.testconf"
cover = File.expand_path "config/cover.spec"
cmdline = "#{runtest} -config #{config} -cover #{cover} -dir"
# Search for Tests and Source Files
tests = []
covered = []
found = false
Find.find "lib" do |f|
next unless FileTest.directory? f
if f =~ %r{/test$}
tests << f
found = true
elsif f =~ %r{/ebin}
covered << f
end
end
unless found
puts "No tests found"
exit 1
end
# Finish Building Command Line
tests.each do |t|
cmdline << " #{File.expand_path t}"
end
# Build Code Coverage Specification
cp "templates/cover.spec", "#{cover}"
cf = File.open cover, "a"
cf << "{incl_dirs_r,["
covered.map! do |c|
"\"#{File.expand_path c}\""
end
cf << covered.join(",")
cf << "]}.\n"
cf.close
# Run Tests
chdir "var/" # where the logs are kept
test_results = open("|#{cmdline}")
failed = false
test_results.each_line do |l|
failed = true if /FAILED/.match l
print l
end
puts ""
chdir ".."
if failed
puts "FAILED TESTS DETECTED"
exit 1
end
if File.exists? File.join ['var','erl_crash.dump']
puts "TEST SERVER CRASHED"
exit 1
end
end
# TODO: Make this generate the report if it doesn't exist
desc 'open the report created by common_test (on a Mac)'
task :report do |t|
sh "open var/index.html"
end
desc 'save test logs'
task :save_logs, [:path] do |t,args|
args.with_defaults(:path => '~/test_logs/default')
vault = File.expand_path args[:path]
current = Dir.glob File.join('var','*')
rm_rf vault
mkdir_p vault
cp_r current, vault
end
desc 'restore test logs'
task :restore_logs, [:path] do |t,args|
args.with_defaults(:path => '~/test_logs/default')
vault = File.expand_path args[:path]
vault = Dir.glob File.join(vault,'*')
current = 'var'
rm_rf Dir.glob File.join(current,'*')
mkdir_p current
cp_r vault, current
end
desc 'copy test results and generated docs to some location'
task :collect_results, [:path] do |t,args|
# Handle Args
args.with_defaults(:path => '~/html')
path = args[:path]
# Build Paths
where = File.expand_path path
docs = File.join(where,'doc')
docpage = File.join(where,'docs.html')
# Clean Out Target Directory
rm_rf where
mkdir_p where
# Copy Generated Docs
app_info = apps
app_info.each do |app|
src = Dir.glob File.join([app[:dir], 'doc', '*'])
dst = File.join docs, app[:spec]
mkdir_p dst
cp_r src, dst
end
# Copy Test Results
cp_r Dir.glob('var/*'), where
# Generate Main Page
begin
require 'mustache'
# Template and Data
template = <<EOT
<html>
<head><title>Generated Documentation</title></head>
<body style="text-align: center; font-family: Verdana, Arial, Helvetica, sans-serif;">
<h1>Application Documentation</h1>
{{#docs}}
<p><a href="doc/{{spec}}/index.html">{{pretty}} {{ver}} documentation</a></p>
{{/docs}}
</body>
</html>
EOT
data = { :docs => app_info }
# Render Page
page = File.open docpage, "w"
page << Mustache.render(template, data)
page.close
rescue LoadError
puts "Unable to generate main page without mustache..."
end
end
desc "Run tests for Continuous Integration Server"
task :ci, [:project_name] do |t,args|
# Collect CI Run Info
project_name = args[:project_name]
unless project_name
puts "need project name"
exit 1
end
rev_hash = %x{git rev-parse HEAD}.chomp
# Build Correct Paths and Argument Lists
log_dir = File.join ['~','test_logs',project_name]
www_dir = File.join ['~','html',project_name,rev_hash]
log_args = Rake::TaskArguments.new [:path], [log_dir]
collect_args = Rake::TaskArguments.new [:path], [www_dir]
# Execute Rake Tasks
Rake::Task["test:restore_logs"].execute(log_args)
begin
Rake::Task["build:compile"].execute()
Rake::Task["build:doc"].execute()
Rake::Task["test:run"].execute()
ensure # Clean Up Appropriately But Preserve Exit Behavior
Rake::Task["test:save_logs"].execute(log_args)
Rake::Task["test:collect_results"].execute(collect_args)
end
end
end