/
run_mutant
executable file
·89 lines (73 loc) · 2.03 KB
/
run_mutant
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
#!/usr/bin/env ruby
require 'fileutils'
class Mutt
FILE_NAME="audio_book_creator"
attr_accessor :src
attr_accessor :spec
attr_accessor :mutant
attr_accessor :class_name
def initialize(src)
@src = src
@spec = src.sub("lib/","spec/").sub(".rb","_spec.rb")
@mutant = src.sub("lib/","muts/").sub(".rb",".txt")
@class_name = file_to_class(src.sub("lib/",""))
end
def need_to_run?
!File.exist?(mutant) ||
File.stat(src).mtime > File.stat(mutant).mtime ||
File.stat(spec).mtime > File.stat(mutant).mtime
end
def skip?
class_name.include?("::Version")
end
def ensure_mutant_dir
FileUtils.mkdir_p(File.dirname(mutant))
end
def mutant_count
if File.exist?(mutant)
%w(Kills Mutations).map { |field| `awk "/#{field}/ { print \\$2; }" #{mutant}`.chomp.to_i }
else
["", ""]
end
end
def count_in_progress
k, m = mutant_count
"%s%4s/%4s #{class_name}" % ["?", k, m]
end
def counts
k, m = mutant_count
"%s%4s/%4s #{class_name}" % [(k == m ? " " : "*"), k, m]
end
def run_mutant
# ensure_mutant_dir
# --fail-fast
system({ "MUTANT" => "true"},
"bundle exec mutant --include lib --require #{FILE_NAME} --require audio_book_creator/cli " +
"--use rspec #{class_name} --jobs 1 > #{mutant}")
rescue SystemExit, Interrupt
FileUtils.rm(mutant)
raise
end
def self.run(filenames, force)
filenames.map { |src| Mutt.new(src) }.select { |mutant| !mutant.skip? }.each do |mutant|
if force || mutant.need_to_run?
puts "#{mutant.count_in_progress} ..."
mutant.run_mutant
print back_a_line
puts "#{mutant.counts} "
else
puts mutant.counts
end
end
end
private
def self.back_a_line
@back_a_line ||= `tput cuu1; tput el`
end
def file_to_class(str)
str.sub(".rb","").split("/").collect { |f| f.split("_").collect(&:capitalize).join }.join("::")
end
end
force = ARGV.delete("-f")
filenames = ARGV.empty? ? Dir["lib/**/*.rb"] : ARGV
Mutt.run(filenames, force)