rake_command_filter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +26 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.rubocop.yml +10 -0
- data/.travis.yml +21 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +95 -0
- data/Rakefile +18 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/command_definition.rb +148 -0
- data/lib/command_failed_error.rb +4 -0
- data/lib/line_filter.rb +24 -0
- data/lib/line_filter_result.rb +70 -0
- data/lib/rake_command_definition.rb +21 -0
- data/lib/rake_command_filter/version.rb +4 -0
- data/lib/rake_command_filter.rb +111 -0
- data/lib/rspec_command_definition.rb +49 -0
- data/lib/rubocop_command_definition.rb +29 -0
- data/lib/yard_command_definition.rb +32 -0
- data/rake_command_filter.gemspec +31 -0
- data/test_cases/rspec/fail/coverage/.last_run.json +5 -0
- data/test_cases/rspec/fail/coverage/.resultset.json +7 -0
- data/test_cases/rspec/fail/coverage/.resultset.json.lock +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/application.css +799 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/application.js +1707 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/colorbox/border.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/colorbox/controls.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/favicon_green.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/favicon_red.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/favicon_yellow.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/loading.gif +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/magnify.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/test_cases/rspec/fail/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/test_cases/rspec/fail/coverage/index.html +72 -0
- data/test_cases/rspec/fail/fail_spec.rb +7 -0
- data/test_cases/rspec/ok/coverage/.last_run.json +5 -0
- data/test_cases/rspec/ok/coverage/.resultset.json +15 -0
- data/test_cases/rspec/ok/coverage/.resultset.json.lock +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/application.css +799 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/application.js +1707 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/colorbox/border.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/colorbox/controls.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/colorbox/loading.gif +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/colorbox/loading_background.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/favicon_green.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/favicon_red.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/favicon_yellow.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/loading.gif +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/magnify.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/test_cases/rspec/ok/coverage/assets/0.10.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/test_cases/rspec/ok/coverage/index.html +136 -0
- data/test_cases/rspec/ok/ok_spec.rb +11 -0
- data/test_cases/rspec/ok/test_coverage.rb +6 -0
- data/test_cases/rubocop/fail/rubocop_fail.rb +3 -0
- data/test_cases/rubocop/ok/rubocop_ok.rb +2 -0
- data/test_cases/rubocop/rubocop.yml +4 -0
- data/test_cases/yard/.yardoc/checksums +0 -0
- data/test_cases/yard/.yardoc/object_types +0 -0
- data/test_cases/yard/.yardoc/objects/root.dat +0 -0
- data/test_cases/yard/.yardoc/proxy_types +0 -0
- data/test_cases/yard/fail/.yardoc/checksums +1 -0
- data/test_cases/yard/fail/.yardoc/object_types +0 -0
- data/test_cases/yard/fail/.yardoc/objects/root.dat +0 -0
- data/test_cases/yard/fail/.yardoc/proxy_types +0 -0
- data/test_cases/yard/fail/doc/YardUndocumented.html +306 -0
- data/test_cases/yard/fail/doc/_index.html +101 -0
- data/test_cases/yard/fail/doc/class_list.html +58 -0
- data/test_cases/yard/fail/doc/css/common.css +1 -0
- data/test_cases/yard/fail/doc/css/full_list.css +57 -0
- data/test_cases/yard/fail/doc/css/style.css +339 -0
- data/test_cases/yard/fail/doc/file_list.html +57 -0
- data/test_cases/yard/fail/doc/frames.html +26 -0
- data/test_cases/yard/fail/doc/index.html +101 -0
- data/test_cases/yard/fail/doc/js/app.js +219 -0
- data/test_cases/yard/fail/doc/js/full_list.js +181 -0
- data/test_cases/yard/fail/doc/js/jquery.js +4 -0
- data/test_cases/yard/fail/doc/method_list.html +75 -0
- data/test_cases/yard/fail/doc/top-level-namespace.html +112 -0
- data/test_cases/yard/fail/yard_fail.rb +12 -0
- data/test_cases/yard/ok/.yardoc/checksums +1 -0
- data/test_cases/yard/ok/.yardoc/object_types +0 -0
- data/test_cases/yard/ok/.yardoc/objects/root.dat +0 -0
- data/test_cases/yard/ok/.yardoc/proxy_types +0 -0
- data/test_cases/yard/ok/doc/YardDocumented.html +343 -0
- data/test_cases/yard/ok/doc/YardUndocumented.html +343 -0
- data/test_cases/yard/ok/doc/_index.html +101 -0
- data/test_cases/yard/ok/doc/class_list.html +58 -0
- data/test_cases/yard/ok/doc/css/common.css +1 -0
- data/test_cases/yard/ok/doc/css/full_list.css +57 -0
- data/test_cases/yard/ok/doc/css/style.css +339 -0
- data/test_cases/yard/ok/doc/file_list.html +57 -0
- data/test_cases/yard/ok/doc/frames.html +26 -0
- data/test_cases/yard/ok/doc/index.html +101 -0
- data/test_cases/yard/ok/doc/js/app.js +219 -0
- data/test_cases/yard/ok/doc/js/full_list.js +181 -0
- data/test_cases/yard/ok/doc/js/jquery.js +4 -0
- data/test_cases/yard/ok/doc/method_list.html +75 -0
- data/test_cases/yard/ok/doc/top-level-namespace.html +112 -0
- data/test_cases/yard/ok/yard_ok.rb +16 -0
- data/test_cases/yard/warn/.yardoc/checksums +1 -0
- data/test_cases/yard/warn/.yardoc/object_types +0 -0
- data/test_cases/yard/warn/.yardoc/objects/root.dat +0 -0
- data/test_cases/yard/warn/.yardoc/proxy_types +0 -0
- data/test_cases/yard/warn/doc/YardDocumented.html +343 -0
- data/test_cases/yard/warn/doc/_index.html +101 -0
- data/test_cases/yard/warn/doc/class_list.html +58 -0
- data/test_cases/yard/warn/doc/css/common.css +1 -0
- data/test_cases/yard/warn/doc/css/full_list.css +57 -0
- data/test_cases/yard/warn/doc/css/style.css +339 -0
- data/test_cases/yard/warn/doc/file_list.html +57 -0
- data/test_cases/yard/warn/doc/frames.html +26 -0
- data/test_cases/yard/warn/doc/index.html +101 -0
- data/test_cases/yard/warn/doc/js/app.js +219 -0
- data/test_cases/yard/warn/doc/js/full_list.js +181 -0
- data/test_cases/yard/warn/doc/js/jquery.js +4 -0
- data/test_cases/yard/warn/doc/method_list.html +75 -0
- data/test_cases/yard/warn/doc/top-level-namespace.html +112 -0
- data/test_cases/yard/warn/yard_warn.rb +16 -0
- metadata +306 -0
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/tasklib'
|
4
|
+
require 'rake_command_filter/version'
|
5
|
+
require_relative './line_filter_result'
|
6
|
+
require_relative './line_filter'
|
7
|
+
require_relative './command_definition'
|
8
|
+
require_relative './rake_command_definition'
|
9
|
+
require_relative './rubocop_command_definition'
|
10
|
+
require_relative './rspec_command_definition'
|
11
|
+
require_relative './yard_command_definition'
|
12
|
+
require_relative './command_failed_error'
|
13
|
+
|
14
|
+
# A rake task that filters the output of other rake tasks so you can see
|
15
|
+
# what you care about.
|
16
|
+
module RakeCommandFilter
|
17
|
+
# Always hide the line, no matter what
|
18
|
+
LINE_HANDLING_HIDE_ALWAYS = :hide_always
|
19
|
+
|
20
|
+
# Show the line only after an error pattern line has been matched
|
21
|
+
LINE_HANDLING_HIDE_UNTIL_ERROR = :hide_until_error
|
22
|
+
|
23
|
+
# Show the line
|
24
|
+
LINE_HANDLING_SHOW_ALWAYS = :show_always
|
25
|
+
|
26
|
+
@@testing = false # rubocop:disable Style/ClassVars
|
27
|
+
|
28
|
+
# set to true if we are in at test context
|
29
|
+
def self.testing=(_val)
|
30
|
+
@@testing = true # rubocop:disable Style/ClassVars
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return true if we are in a test context.
|
34
|
+
def self.testing?
|
35
|
+
return @@testing
|
36
|
+
end
|
37
|
+
|
38
|
+
# Provides a custom rake task.
|
39
|
+
#
|
40
|
+
# require 'rake_command_filter'
|
41
|
+
# RakeCommandFilter::RakeTask.new
|
42
|
+
class RakeTask < Rake::TaskLib
|
43
|
+
attr_accessor :name
|
44
|
+
attr_accessor :verbose
|
45
|
+
attr_accessor :fail_on_error
|
46
|
+
attr_accessor :patterns
|
47
|
+
attr_accessor :formatters
|
48
|
+
attr_accessor :requires
|
49
|
+
attr_accessor :options
|
50
|
+
|
51
|
+
# default rake task initializer
|
52
|
+
def initialize(*args, &task_block)
|
53
|
+
@name = args.shift || :filter_tasks
|
54
|
+
@verbose = true
|
55
|
+
@commands = []
|
56
|
+
|
57
|
+
desc 'TODO: FILL THIS IN THE BLOCK WHERE YOU CREATE THE TASK'
|
58
|
+
|
59
|
+
instance_eval(&task_block)
|
60
|
+
run_task(name, *args)
|
61
|
+
end
|
62
|
+
|
63
|
+
# call this to run a {CommandDefinition} subclass
|
64
|
+
# @param defin an instance of a command definition subclass
|
65
|
+
# @yield in the block, you can modify the internal state of the command,
|
66
|
+
# using desc, add_filter, etc.
|
67
|
+
def run_definition(defin, &block)
|
68
|
+
command = defin
|
69
|
+
defin.instance_eval(&block) if block
|
70
|
+
add_command(command)
|
71
|
+
end
|
72
|
+
|
73
|
+
# run all the tasks that have been added via {#run_definition}.
|
74
|
+
def run_main_task(verbose)
|
75
|
+
run_tasks(verbose)
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def run_task(name, *args)
|
81
|
+
task(name, *args) do |_, _task_args|
|
82
|
+
RakeFileUtils.send(:verbose, verbose) do
|
83
|
+
begin
|
84
|
+
run_main_task(verbose)
|
85
|
+
rescue
|
86
|
+
exit 1
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def add_command(command)
|
93
|
+
@commands << command
|
94
|
+
end
|
95
|
+
|
96
|
+
def run_tasks(_verbose)
|
97
|
+
failure = nil
|
98
|
+
@commands.each do |command|
|
99
|
+
results = command.execute
|
100
|
+
worst = CommandDefinition.find_worst_result(results)
|
101
|
+
if !worst.empty? && worst[0].severity > 0
|
102
|
+
failure = worst[0]
|
103
|
+
break
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# raise an error so that the rake task will return 1 to the shell
|
108
|
+
raise CommandFailedError, failure.message if failure
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module RakeCommandFilter
|
2
|
+
# default way to run rubocop and parse its output
|
3
|
+
class RSpecCommandDefinition < RakeCommandDefinition
|
4
|
+
# for testing
|
5
|
+
def self.failure_msg(failures)
|
6
|
+
"#{failures} failed"
|
7
|
+
end
|
8
|
+
|
9
|
+
# for testing
|
10
|
+
def self.success_msg(success)
|
11
|
+
"#{success} passed"
|
12
|
+
end
|
13
|
+
|
14
|
+
# for testing
|
15
|
+
def self.coverage_msg(percent)
|
16
|
+
"#{percent} test coverage"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Default parser for rspec output.
|
20
|
+
# @param id override this if you want to do something other than 'rake spec'
|
21
|
+
def initialize(coverage_threshold = 95, id = :spec)
|
22
|
+
super(id, 'rspec')
|
23
|
+
# just use sensible defaults here.
|
24
|
+
add_rspec
|
25
|
+
add_simplecov(coverage_threshold)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def add_rspec
|
31
|
+
add_filter(:rspec_filter, /(\d+)\s+example[s]?,\s+(\d+)\s+failure/) do |matches|
|
32
|
+
failures = matches[1].to_i
|
33
|
+
if failures > 0
|
34
|
+
result_failure(RSpecCommandDefinition.failure_msg(failures))
|
35
|
+
else
|
36
|
+
result_success(RSpecCommandDefinition.success_msg(matches[0]))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_simplecov(coverage_threshold)
|
42
|
+
add_filter(:simplecov_filter, /Coverage.+LOC\s+\((\d+[\.]?\d+)%/) do |matches|
|
43
|
+
percent = matches[0].to_f
|
44
|
+
msg = RSpecCommandDefinition.coverage_msg(percent)
|
45
|
+
(percent >= coverage_threshold) ? result_success(msg) : result_failure(msg)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RakeCommandFilter
|
2
|
+
# default way to run rubocop and parse its output
|
3
|
+
class RubocopCommandDefinition < RakeCommandDefinition
|
4
|
+
# used for testing
|
5
|
+
def self.failure_msg(offenses, files)
|
6
|
+
"#{offenses} offenses in #{files} files"
|
7
|
+
end
|
8
|
+
|
9
|
+
# used for testing
|
10
|
+
def self.success_msg(files)
|
11
|
+
"#{files} files"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Default parser for rubocop output.
|
15
|
+
# @param id override this if you want to do something other than 'rake rubocop'
|
16
|
+
def initialize(id = :rubocop)
|
17
|
+
super(id, 'rubocop')
|
18
|
+
|
19
|
+
# just use sensible defaults here.
|
20
|
+
add_filter(:offenses_filter, /(\d+)\s+file.*,\s+(\d+)\s+offense/) do |matches|
|
21
|
+
result_failure(RubocopCommandDefinition.failure_msg(matches[1], matches[0]))
|
22
|
+
end
|
23
|
+
|
24
|
+
add_filter(:no_offenses_filter, /(\d+)\s+file.*,\s+no\s+offenses/) do |matches|
|
25
|
+
result_success(RubocopCommandDefinition.success_msg(matches[0]))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RakeCommandFilter
|
2
|
+
# default way to run rubocop and parse its output
|
3
|
+
class YardCommandDefinition < RakeCommandDefinition
|
4
|
+
attr_accessor :threshold
|
5
|
+
|
6
|
+
# for testing
|
7
|
+
def self.percent_msg(percent)
|
8
|
+
"#{percent} documented"
|
9
|
+
end
|
10
|
+
|
11
|
+
# for testing
|
12
|
+
def self.warning_msg
|
13
|
+
'One or more yard warnings, see above'
|
14
|
+
end
|
15
|
+
|
16
|
+
# Default parser for yard output.
|
17
|
+
# @param threshold override this if you want to require less than 95% documentation
|
18
|
+
# @param id override this if you want to do something other than 'rake spec'
|
19
|
+
def initialize(threshold = 95, id = :yard)
|
20
|
+
super(id, 'yard')
|
21
|
+
# just use sensible defaults here.
|
22
|
+
add_filter(:yard_percentage, /(\d+.?\d+)%\s+document/) do |matches|
|
23
|
+
percent = matches[0].to_f
|
24
|
+
msg = YardCommandDefinition.percent_msg(percent)
|
25
|
+
(percent >= threshold) ? result_success(msg) : result_failure(msg)
|
26
|
+
end
|
27
|
+
add_filter(:yard_warning, /\[warn\]:(.*)/) do |_matches|
|
28
|
+
result_warning(YardCommandDefinition.warning_msg)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rake_command_filter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rake_command_filter'
|
8
|
+
spec.version = RakeCommandFilter::VERSION
|
9
|
+
spec.authors = ['Chris Jones']
|
10
|
+
spec.email = ['chris@tripletriangle.com']
|
11
|
+
|
12
|
+
spec.summary = 'Runs several rake tasks or system commands, and filters their output for easy review'
|
13
|
+
spec.description = 'Runs several rake tasks or system commands, and filters their output for easy review'
|
14
|
+
spec.homepage = 'https://github.com/chrisjones-tripletri/rake_command_filter'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_runtime_dependency 'colorize'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'rubocop', '~> 0.37.0'
|
28
|
+
spec.add_development_dependency 'simplecov', '~> 0.11'
|
29
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
30
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
31
|
+
end
|
File without changes
|