forked from Sage/i18n_yaml_editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
73 lines (63 loc) · 1.83 KB
/
Rakefile
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
# frozen_string_literal: true
require 'rake/testtask'
require 'rubocop/rake_task'
require 'capture_io/capture_io'
Rake::TestTask.new do |t|
t.libs << 'test'
t.libs << 'lib'
t.pattern = 'test/**/test_*.rb'
end
# Mixin
module RuboCop
# Mixin
class RakeTask
private
def run_cli(verbose, options)
require 'rubocop'
cli = CLI.new
puts "\033[1;33m# Running RuboCop...\033[0m" if verbose
result = cli.run(options)
failed = result.nonzero? && fail_on_error
abort("\033[0;31mRuboCop failed!\033[0m\n") if failed
puts "\033[0;32mRuboCop passed\033[0m\n\n\n"
end
end
end
desc 'Run RuboCop'
RuboCop::RakeTask.new(:rubocop)
desc 'Generate documentation in doc/ and check documentation coverage'
task :yardoc do
require 'yard'
puts "\n\033[1;33m# Running Yardoc...\033[0m"
yard = `yard stats --list-undoc --compact`
if yard =~ /Undocumented Objects/
puts yard
puts "\033[0;31mYardoc failed - documentation coverage < 100%\033[0m\n"
exit 1
else
puts yard.each_line.to_a[0..-2]
puts "\033[0;32mYardoc passed - 100.00% documented\033[0m\n\n\n"
end
end
task :coverage do
puts "\033[1;33m# Running Minitest...\033[0m"
out, = capture_io do
puts `bundle exec rake test`
end
puts out
err = /\d+ tests, \d+ assertions, (\d+) failures, (\d+) errors, \d+ skips/
unless out.scan(err).flatten.map(&:to_i).reduce(&:+).zero?
puts "\n\033[0;31mMinitest failed\033[0m\n"
exit 1
end
if out.lines.last =~ /LOC \(100\.0%\) covered/ ||
out.lines[-2] =~ /Coverage is at 100\.0%/
puts "\033[0;32mMinitest passed - 100.00% covered\033[0m\n\n"
else
puts "\n\033[0;31mMinitest failed - Code coverage < 100%\033[0m\n"
exit 1
end
end
task default: %i[coverage yardoc rubocop] do
puts "\033[0;32mYAY! - I18n Yaml Editor test suite passed\033[0m\n\n"
end