Add parameters for output & match string.
This commit is contained in:
parent
97d76be063
commit
e5107da4f9
2 changed files with 145 additions and 42 deletions
|
@ -68,7 +68,7 @@ module Ewoga
|
||||||
m = Mail.read_from_string message.attr[@saved_key]
|
m = Mail.read_from_string message.attr[@saved_key]
|
||||||
return if m.from.nil?
|
return if m.from.nil?
|
||||||
return if m.to.nil?
|
return if m.to.nil?
|
||||||
return unless m.subject =~ /RUBY\s+NEXTFORMATION/
|
return unless m.subject =~ Regexp.new(@config[:match])
|
||||||
|
|
||||||
begin
|
begin
|
||||||
puts "\n### #{m.subject}"
|
puts "\n### #{m.subject}"
|
||||||
|
@ -76,7 +76,7 @@ module Ewoga
|
||||||
print "#{m.from.first} --> #{m.to.join(',')} "
|
print "#{m.from.first} --> #{m.to.join(',')} "
|
||||||
|
|
||||||
attach = m.attachments.first
|
attach = m.attachments.first
|
||||||
fn = "extract/%s/projet.tar" % [m.from.first, attach.filename]
|
fn = "%s/%s/projet-%s.tar" % [@config[:output], m.from.first, m.date.to_date.to_s]
|
||||||
puts "- #{fn}"
|
puts "- #{fn}"
|
||||||
begin
|
begin
|
||||||
FileUtils.mkdir_p File.dirname(fn)
|
FileUtils.mkdir_p File.dirname(fn)
|
||||||
|
@ -122,14 +122,17 @@ module Ewoga
|
||||||
default_task :crawl
|
default_task :crawl
|
||||||
|
|
||||||
|
|
||||||
|
option :match, required: true
|
||||||
|
option :output, required: true
|
||||||
desc 'crawl', 'Crawls email to save mails'
|
desc 'crawl', 'Crawls email to save mails'
|
||||||
def crawl
|
def crawl
|
||||||
#saved_info = []
|
#saved_info = []
|
||||||
parse_configuration
|
parse_configuration
|
||||||
|
@config['match'] = options[:match]
|
||||||
|
@config['output'] = options[:match]
|
||||||
|
|
||||||
## Run application
|
## Run application
|
||||||
app = CrawlerApp.new @config
|
app = CrawlerApp.new @config
|
||||||
|
|
||||||
app.connect!
|
app.connect!
|
||||||
app.examine_all
|
app.examine_all
|
||||||
app.disconnect!
|
app.disconnect!
|
||||||
|
|
176
bin/ewoga-test
176
bin/ewoga-test
|
@ -21,15 +21,18 @@ class Project
|
||||||
@name = File.basename path
|
@name = File.basename path
|
||||||
@score = 0
|
@score = 0
|
||||||
@score_max = 0
|
@score_max = 0
|
||||||
|
@errors = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
class ExtractionError < Exception ; end
|
class ExtractionError < Exception ; end
|
||||||
|
|
||||||
def extract
|
def extract
|
||||||
Dir.chdir(@path)
|
Dir.chdir(@path)
|
||||||
print indent + "Extracting project data ... "
|
|
||||||
|
|
||||||
tarfile = @path + '/projet.tar'
|
tarfile = Dir.glob('projet-*.tar').sort.last
|
||||||
|
# tarfile = @path + '/projet.tar'
|
||||||
|
print indent + "Extracting project data from #{tarfile}... "
|
||||||
|
|
||||||
system "tar xavf #{tarfile} > extractlog"
|
system "tar xavf #{tarfile} > extractlog"
|
||||||
raise ExtractionError unless $?.success?
|
raise ExtractionError unless $?.success?
|
||||||
puts "success".green
|
puts "success".green
|
||||||
|
@ -41,29 +44,27 @@ class Project
|
||||||
end
|
end
|
||||||
FileUtils.rm 'extractlog'
|
FileUtils.rm 'extractlog'
|
||||||
puts ""
|
puts ""
|
||||||
|
FileUtils.rm_f ENV['HOME'] + '/.taskman.yml'
|
||||||
|
FileUtils.rm_f ENV['HOME'] + '/.taskman'
|
||||||
end
|
end
|
||||||
|
|
||||||
def patch
|
def test_patch
|
||||||
|
res = { log: [], errors: [], score: 0, score_max: 0 }
|
||||||
|
|
||||||
Dir.chdir(@path)
|
Dir.chdir(@path)
|
||||||
print indent + "Patching project data ... "
|
FileUtils.rm_f '.pc/applied-patches'
|
||||||
$INDENT += 2
|
if File.exist? 'patches' then
|
||||||
if File.exist? 'patch.d' then
|
Dir.chdir(@path + '/taskman')
|
||||||
log = []
|
res[:log].concat %x{quilt push -a -v 2>&1 }.split(/\n/).map(&:strip)
|
||||||
Dir.glob('patch.d/*.patch').sort.each do |patchfile|
|
|
||||||
patchname = File.basename(patchfile).gsub(/\.patch$/,'')
|
# We generate an error for each patch
|
||||||
IO.popen("patch -p0 < #{patchfile}") do |fh|
|
res[:score_max] += File.readlines('../patches/series').length
|
||||||
log.concat fh.readlines.map(&:strip).map { |line|
|
res[:log] << ""
|
||||||
patchname + ': ' + line
|
res[:log] << "Applied #{res[:score_max]} patch(es)"
|
||||||
}
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
puts "success".green
|
|
||||||
puts log.map {|line| indent + line }
|
res
|
||||||
else
|
|
||||||
puts 'skipping'
|
|
||||||
end
|
|
||||||
$INDENT -= 2
|
|
||||||
puts ""
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_structure
|
def test_structure
|
||||||
|
@ -187,6 +188,7 @@ class Project
|
||||||
no_error = res[:log].select{|line| line =~ /ERROR/i or line =~ /Erreur/i }.empty?
|
no_error = res[:log].select{|line| line =~ /ERROR/i or line =~ /Erreur/i }.empty?
|
||||||
res[:score] += 1 if not $?.success? and not no_error
|
res[:score] += 1 if not $?.success? and not no_error
|
||||||
res[:score_max] += 1
|
res[:score_max] += 1
|
||||||
|
res[:errors] << "Error not detected in output" if no_error or $?.success?
|
||||||
|
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
@ -196,13 +198,26 @@ class Project
|
||||||
|
|
||||||
command = bundle_prefix + './bin/taskman list 2>&1'
|
command = bundle_prefix + './bin/taskman list 2>&1'
|
||||||
res[:log] << "Running command: #{command}"
|
res[:log] << "Running command: #{command}"
|
||||||
|
output = []
|
||||||
IO.popen(command) do |fh|
|
IO.popen(command) do |fh|
|
||||||
res[:log].concat fh.readlines.map(&:strip)
|
output.concat fh.readlines.map(&:strip)
|
||||||
end
|
end
|
||||||
no_error = res[:log].select{|line| line =~ /ERROR/i or line =~ /Erreur/i }.empty?
|
res[:log].concat output
|
||||||
res[:score] += 1 if $?.success? and no_error
|
res[:score] += 1 if $?.success?
|
||||||
res[:score_max] += 1
|
res[:score_max] += 1
|
||||||
|
|
||||||
|
# detect errors in output
|
||||||
|
no_error = output.select{|line| line =~ /ERROR/i or line =~ /Erreur/i }.empty?
|
||||||
|
res[:score] += 1 if no_error
|
||||||
|
res[:score_max] += 1
|
||||||
|
res[:errors] << "Detected error in output" unless no_error
|
||||||
|
|
||||||
|
# detect bad output formating
|
||||||
|
bad_formatted = output.select{|line| not line =~ /^\d+:/ }
|
||||||
|
res[:score] += 1 if bad_formatted.empty?
|
||||||
|
res[:score_max] += 1
|
||||||
|
res[:errors] << "Lines are badly formatted" unless bad_formatted.empty?
|
||||||
|
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -215,7 +230,8 @@ class Project
|
||||||
before.concat fh.readlines.map(&:strip)
|
before.concat fh.readlines.map(&:strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
command = bundle_prefix + './bin/taskman add "Tester taskman 1" 2>&1'
|
testid = Random.rand(10000)
|
||||||
|
command = bundle_prefix + "./bin/taskman add \"Tester taskman #{testid}\" 2>&1"
|
||||||
res[:log] << "Running command: #{command}"
|
res[:log] << "Running command: #{command}"
|
||||||
IO.popen(command) do |fh|
|
IO.popen(command) do |fh|
|
||||||
res[:log].concat fh.readlines.map(&:strip)
|
res[:log].concat fh.readlines.map(&:strip)
|
||||||
|
@ -230,18 +246,94 @@ class Project
|
||||||
after.concat fh.readlines.map(&:strip)
|
after.concat fh.readlines.map(&:strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
res[:log] << "List difference :"
|
||||||
|
diff = (after-before).map{|x| '+' + x}
|
||||||
|
res[:log].concat diff
|
||||||
|
res[:score] += 1 if diff.length == 1
|
||||||
|
res[:score_max] += 1
|
||||||
|
|
||||||
|
res[:errors] << "Save was not implemented" if diff.length < 1
|
||||||
|
res[:errors] << "Listing called everywhere" if diff.length > 1
|
||||||
|
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_taskman_command_del
|
def test_taskman_command_del
|
||||||
res = { log: [], errors: [], score: 0, score_max: 0 }
|
res = { log: [], errors: [], score: 0, score_max: 0 }
|
||||||
|
|
||||||
|
command = bundle_prefix + './bin/taskman list 2>&1'
|
||||||
|
before = []
|
||||||
|
IO.popen(command) do |fh|
|
||||||
|
before.concat fh.readlines.map(&:strip)
|
||||||
|
end
|
||||||
|
|
||||||
|
testid = ((before.first || "").match(/^(\d+):/) || [])[1]
|
||||||
|
command = bundle_prefix + "./bin/taskman del #{testid} 2>&1"
|
||||||
|
res[:log] << "Running command: #{command}"
|
||||||
|
IO.popen(command) do |fh|
|
||||||
|
res[:log].concat fh.readlines.map(&:strip)
|
||||||
|
end
|
||||||
|
no_error = res[:log].select{|line| line =~ /ERROR/i or line =~ /Erreur/i }.empty?
|
||||||
|
res[:score] += 1 if $?.success? and no_error
|
||||||
|
res[:score_max] += 1
|
||||||
|
|
||||||
|
command = bundle_prefix + './bin/taskman list 2>&1'
|
||||||
|
after = []
|
||||||
|
IO.popen(command) do |fh|
|
||||||
|
after.concat fh.readlines.map(&:strip)
|
||||||
|
end
|
||||||
|
|
||||||
|
res[:log] << "List difference :"
|
||||||
|
diff = (before - after).map{|x| '-' + x}
|
||||||
|
res[:log].concat diff
|
||||||
|
res[:score] += 1 if diff.length == 1
|
||||||
|
res[:score_max] += 1
|
||||||
|
|
||||||
|
res[:errors] << "Save was not implemented" if diff.length < 1
|
||||||
|
res[:errors] << "Listing called everywhere" if diff.length > 1
|
||||||
|
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_taskman_command_mod
|
def test_taskman_command_mod
|
||||||
res = { log: [], errors: [], score: 0, score_max: 0 }
|
res = { log: [], errors: [], score: 0, score_max: 0 }
|
||||||
|
|
||||||
|
command = bundle_prefix + './bin/taskman list 2>&1'
|
||||||
|
before = []
|
||||||
|
IO.popen(command) do |fh|
|
||||||
|
before.concat fh.readlines.map(&:strip)
|
||||||
|
end
|
||||||
|
|
||||||
|
testid = ((before.first || "").match(/^(\d+):/) || [])[1]
|
||||||
|
command = bundle_prefix + "./bin/taskman mod #{testid} Modified 2>&1"
|
||||||
|
res[:log] << "Running command: #{command}"
|
||||||
|
IO.popen(command) do |fh|
|
||||||
|
res[:log].concat fh.readlines.map(&:strip)
|
||||||
|
end
|
||||||
|
no_error = res[:log].select{|line| line =~ /ERROR/i or line =~ /Erreur/i }.empty?
|
||||||
|
res[:score] += 1 if $?.success? and no_error
|
||||||
|
res[:score_max] += 1
|
||||||
|
|
||||||
|
command = bundle_prefix + './bin/taskman list 2>&1'
|
||||||
|
after = []
|
||||||
|
IO.popen(command) do |fh|
|
||||||
|
after.concat fh.readlines.map(&:strip)
|
||||||
|
end
|
||||||
|
|
||||||
|
mod_found = after.select{|line| line =~ /^\s*#{testid}:.*Modified/ }
|
||||||
|
res[:score] += 1 unless mod_found.empty?
|
||||||
|
res[:errors] << "Title was not changed" if mod_found.empty?
|
||||||
|
res[:score_max] += 1
|
||||||
|
|
||||||
|
|
||||||
|
res[:log] << "List difference :"
|
||||||
|
diff = (before - after).map{|x| '-' + x} + (after - before).map{|x| '+' + x}
|
||||||
|
res[:log].concat diff
|
||||||
|
res[:score] += 1 if diff.length == 2
|
||||||
|
res[:score_max] += 1
|
||||||
|
|
||||||
|
# res[:errors] << "Save was not implemented" if diff.length < 1
|
||||||
|
# res[:errors] << "Listing called everywhere" if diff.length > 1
|
||||||
res
|
res
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -259,16 +351,14 @@ class Project
|
||||||
else
|
else
|
||||||
success = res[:score].to_f / res[:score_max].to_f
|
success = res[:score].to_f / res[:score_max].to_f
|
||||||
success_pcent = (success * 100).to_i
|
success_pcent = (success * 100).to_i
|
||||||
if success == 1.0 then
|
case (10 * success).to_i
|
||||||
# success case
|
when 10 then puts ("%d%% success" % success_pcent).green
|
||||||
puts ("%d%% success" % success_pcent).green
|
when 3..9 then puts ("%d%% error" % success_pcent).yellow
|
||||||
elsif success > 0.5 then
|
else puts ("%d%% error" % success_pcent).red
|
||||||
puts ("%d%% error" % success_pcent).yellow
|
|
||||||
else
|
|
||||||
puts ("%d%% error" % success_pcent).red
|
|
||||||
end
|
end
|
||||||
@score += res[:score]
|
@score += res[:score]
|
||||||
@score_max += res[:score_max]
|
@score_max += res[:score_max]
|
||||||
|
@errors += res[:errors].size
|
||||||
end
|
end
|
||||||
|
|
||||||
unless res[:log].empty? then
|
unless res[:log].empty? then
|
||||||
|
@ -276,7 +366,12 @@ class Project
|
||||||
puts ""
|
puts ""
|
||||||
end
|
end
|
||||||
unless res[:errors].empty? then
|
unless res[:errors].empty? then
|
||||||
puts res[:errors].map{|line| indent + line.red }.join("\n")
|
puts (
|
||||||
|
res[:errors]
|
||||||
|
.map{|line| "EWOGA_ERROR: " + line }
|
||||||
|
.map{|line| indent + line.red }
|
||||||
|
.join("\n")
|
||||||
|
)
|
||||||
puts ""
|
puts ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -284,8 +379,9 @@ class Project
|
||||||
$INDENT = prev_INDENT
|
$INDENT = prev_INDENT
|
||||||
end
|
end
|
||||||
|
|
||||||
def score
|
def score out
|
||||||
puts indent + "[ #{@score} / #{@score_max} ]"
|
puts indent + "[ passed #{@score} / total #{@score_max} / errors #{@errors} ]"
|
||||||
|
out.puts "#{File.basename @path}, #{@score}, #{@score_max}, #{@errors}"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -304,13 +400,14 @@ else
|
||||||
projects = ARGV
|
projects = ARGV
|
||||||
end
|
end
|
||||||
|
|
||||||
|
out = File.open('result.csv','w+')
|
||||||
projects.each do |name|
|
projects.each do |name|
|
||||||
projectpath = Pathname.new(name).realpath.to_s
|
projectpath = Pathname.new(name).realpath.to_s
|
||||||
puts "[#{File.basename(projectpath).yellow.on_blue}] #{projectpath}"
|
puts "[#{File.basename(projectpath).yellow.on_blue}] #{projectpath}"
|
||||||
|
|
||||||
project = Project.new(projectpath)
|
project = Project.new(projectpath)
|
||||||
project.extract
|
project.extract
|
||||||
project.patch
|
project.test :patch, "Apply corrective patches"
|
||||||
project.test :structure, "Testing project structure"
|
project.test :structure, "Testing project structure"
|
||||||
project.test :bundle_install, "Installing bundled Gems"
|
project.test :bundle_install, "Installing bundled Gems"
|
||||||
project.test :taskman_help_short, "Testing taskman short help"
|
project.test :taskman_help_short, "Testing taskman short help"
|
||||||
|
@ -318,11 +415,14 @@ projects.each do |name|
|
||||||
project.test :taskman_command_wrong, "Testing taskman wrong command"
|
project.test :taskman_command_wrong, "Testing taskman wrong command"
|
||||||
project.test :taskman_command_list, "Testing taskman command: list"
|
project.test :taskman_command_list, "Testing taskman command: list"
|
||||||
project.test :taskman_command_add, "Testing taskman command: add"
|
project.test :taskman_command_add, "Testing taskman command: add"
|
||||||
project.test :taskman_command_del, "Testing taskman command: del"
|
|
||||||
project.test :taskman_command_mod, "Testing taskman command: mod"
|
project.test :taskman_command_mod, "Testing taskman command: mod"
|
||||||
project.score
|
project.test :taskman_command_del, "Testing taskman command: del"
|
||||||
|
project.score out
|
||||||
|
|
||||||
puts ""
|
puts ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
out.close
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue