|
1 | | -require 'rake' |
2 | | -require 'bundler/gem_tasks' |
3 | | -require 'fileutils' |
4 | | -require 'open3' |
5 | | - |
6 | | -desc "Open a Pry session preloaded with this library" |
7 | | -task :console do |
8 | | - sh "pry -I lib -r solargraph.rb" |
9 | | -end |
10 | | - |
11 | | -desc "Run the type checker" |
12 | | -task typecheck: [:typecheck_typed] |
13 | | - |
14 | | -desc "Run the type checker at typed level - return code issues provable without annotations being correct" |
15 | | -task :typecheck_typed do |
16 | | - sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level typed" |
17 | | -end |
18 | | - |
19 | | -desc "Run the type checker at strict level - report issues using type annotations" |
20 | | -task :typecheck_strict do |
21 | | - sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level strict" |
22 | | -end |
23 | | - |
24 | | -desc "Run the type checker at strong level - enforce that type annotations exist" |
25 | | -task :typecheck_strong do |
26 | | - sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level strong" |
27 | | -end |
28 | | - |
29 | | -desc "Run the type checker at alpha level - run high-false-alarm checks" |
30 | | -task :typecheck_alpha do |
31 | | - sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level alpha" |
32 | | -end |
33 | | - |
34 | | -desc "Run RSpec tests, starting with the ones that failed last time" |
35 | | -task spec: %i[spec_failed undercover_no_fail full_spec] do |
36 | | - undercover |
37 | | -end |
38 | | - |
39 | | -desc "Run all RSpec tests" |
40 | | -task :full_spec do |
41 | | - warn 'starting spec' |
42 | | - sh 'TEST_COVERAGE_COMMAND_NAME=full-new bundle exec rspec' # --profile' |
43 | | - warn 'ending spec' |
44 | | - # move coverage/full-new to coverage/full on success so that we |
45 | | - # always have the last successful run's 'coverage info |
46 | | - FileUtils.rm_rf('coverage/full') |
47 | | - FileUtils.mv('coverage/full-new', 'coverage/full') |
48 | | -end |
49 | | - |
50 | | -# @sg-ignore #undercover return type could not be inferred |
51 | | -# @return [Process::Status] |
52 | | -def undercover |
53 | | - simplecov_collate |
54 | | - cmd = 'bundle exec undercover ' \ |
55 | | - '--simplecov coverage/combined/coverage.json ' \ |
56 | | - '--exclude-files "Rakefile,spec/*,spec/**/*,lib/solargraph/version.rb" ' \ |
57 | | - '--compare origin/master' |
58 | | - output, status = Bundler.with_unbundled_env do |
59 | | - Open3.capture2e(cmd) |
60 | | - end |
61 | | - puts output |
62 | | - $stdout.flush |
63 | | - status |
64 | | -rescue StandardError => e |
65 | | - warn "hit error: #{e.message}" |
66 | | - warn "Backtrace:\n#{e.backtrace.join("\n")}" |
67 | | - warn "output: #{output}" |
68 | | - puts "Flushing" |
69 | | - $stdout.flush |
70 | | - raise |
71 | | -end |
72 | | - |
73 | | -desc "Check PR coverage" |
74 | | -task :undercover do |
75 | | - raise "Undercover failed" unless undercover.success? |
76 | | -end |
77 | | - |
78 | | -desc "Branch-focused fast-feedback quality/spec/coverage checks" |
79 | | -task test: %i[overcommit spec typecheck] do |
80 | | - # do these in order |
81 | | - Rake::Task['typecheck_strict'].invoke |
82 | | - Rake::Task['typecheck_strong'].invoke |
83 | | - Rake::Task['typecheck_alpha'].invoke |
84 | | -end |
85 | | - |
86 | | -desc "Re-run failed specs. Add --fail-fast in your .rspec-local file if desired." |
87 | | -task :spec_failed do |
88 | | - # allow user to check out any persistent failures while looking for |
89 | | - # more in the whole test suite |
90 | | - sh 'TEST_COVERAGE_COMMAND_NAME=next-failure bundle exec rspec --only-failures || true' |
91 | | -end |
92 | | - |
93 | | -desc "Run undercover and show output without failing the task if it fails" |
94 | | -task :undercover_no_fail do |
95 | | - undercover |
96 | | -rescue StandardError |
97 | | - puts "Undercover failed, but continuing with other tasks." |
98 | | -end |
99 | | - |
100 | | -# @return [void] |
101 | | -def simplecov_collate |
102 | | - require 'simplecov' |
103 | | - require 'simplecov-lcov' |
104 | | - require 'undercover/simplecov_formatter' |
105 | | - |
106 | | - SimpleCov.collate(Dir["coverage/{next-failure,full,ad-hoc}/.resultset.json"]) do |
107 | | - cname = 'combined' |
108 | | - command_name cname |
109 | | - new_dir = File.join('coverage', cname) |
110 | | - coverage_dir new_dir |
111 | | - |
112 | | - formatter \ |
113 | | - SimpleCov::Formatter::MultiFormatter |
114 | | - .new([ |
115 | | - SimpleCov::Formatter::HTMLFormatter, |
116 | | - SimpleCov::Formatter::Undercover, |
117 | | - SimpleCov::Formatter::LcovFormatter |
118 | | - ]) |
119 | | - SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true |
120 | | - end |
121 | | - puts "Simplecov collated results into coverage/combined/.resultset.json" |
122 | | -rescue StandardError => e |
123 | | - puts "Simplecov collate failed: #{e.message}" |
124 | | -ensure |
125 | | - $stdout.flush |
126 | | -end |
127 | | - |
128 | | -desc 'Add incremental coverage for rapid iteration with undercover' |
129 | | -task :simplecov_collate do |
130 | | - simplecov_collate |
131 | | -end |
132 | | - |
133 | | -desc "Show quality checks on this development branch so far, including any staged files" |
134 | | -task :overcommit do |
135 | | - # OVERCOMMIT_DEBUG=1 will show more detail |
136 | | - sh 'SOLARGRAPH_ASSERTS=on bundle exec overcommit --run --diff origin/master' |
137 | | -end |
| 1 | +require 'rake' |
| 2 | +require 'bundler/gem_tasks' |
| 3 | +require 'fileutils' |
| 4 | +require 'open3' |
| 5 | + |
| 6 | +desc 'Open a Pry session preloaded with this library' |
| 7 | +task :console do |
| 8 | + sh 'pry -I lib -r solargraph.rb' |
| 9 | +end |
| 10 | + |
| 11 | +desc 'Run the type checker' |
| 12 | +task typecheck: [:typecheck_typed] |
| 13 | + |
| 14 | +desc 'Run the type checker at typed level - return code issues provable without annotations being correct' |
| 15 | +task :typecheck_typed do |
| 16 | + sh 'SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level typed' |
| 17 | +end |
| 18 | + |
| 19 | +desc 'Run the type checker at strict level - report issues using type annotations' |
| 20 | +task :typecheck_strict do |
| 21 | + sh 'SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level strict' |
| 22 | +end |
| 23 | + |
| 24 | +desc 'Run the type checker at strong level - enforce that type annotations exist' |
| 25 | +task :typecheck_strong do |
| 26 | + sh 'SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level strong' |
| 27 | +end |
| 28 | + |
| 29 | +desc 'Run the type checker at alpha level - run high-false-alarm checks' |
| 30 | +task :typecheck_alpha do |
| 31 | + sh 'SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level alpha' |
| 32 | +end |
| 33 | + |
| 34 | +desc 'Run RSpec tests, starting with the ones that failed last time' |
| 35 | +task spec: %i[spec_failed undercover_no_fail full_spec] do |
| 36 | + undercover |
| 37 | +end |
| 38 | + |
| 39 | +desc 'Run all RSpec tests' |
| 40 | +task :full_spec do |
| 41 | + warn 'starting spec' |
| 42 | + sh 'TEST_COVERAGE_COMMAND_NAME=full-new bundle exec rspec' # --profile' |
| 43 | + warn 'ending spec' |
| 44 | + # move coverage/full-new to coverage/full on success so that we |
| 45 | + # always have the last successful run's 'coverage info |
| 46 | + FileUtils.rm_rf('coverage/full') |
| 47 | + FileUtils.mv('coverage/full-new', 'coverage/full') |
| 48 | +end |
| 49 | + |
| 50 | +# @sg-ignore #undercover return type could not be inferred |
| 51 | +# @return [Process::Status] |
| 52 | +def undercover |
| 53 | + simplecov_collate |
| 54 | + cmd = 'bundle exec undercover ' \ |
| 55 | + '--simplecov coverage/combined/coverage.json ' \ |
| 56 | + '--exclude-files "Rakefile,spec/*,spec/**/*,lib/solargraph/version.rb" ' \ |
| 57 | + '--compare origin/master' |
| 58 | + output, status = Bundler.with_unbundled_env do |
| 59 | + Open3.capture2e(cmd) |
| 60 | + end |
| 61 | + puts output |
| 62 | + $stdout.flush |
| 63 | + status |
| 64 | +rescue StandardError => e |
| 65 | + warn "hit error: #{e.message}" |
| 66 | + warn "Backtrace:\n#{e.backtrace.join("\n")}" |
| 67 | + warn "output: #{output}" |
| 68 | + puts 'Flushing' |
| 69 | + $stdout.flush |
| 70 | + raise |
| 71 | +end |
| 72 | + |
| 73 | +desc 'Check PR coverage' |
| 74 | +task :undercover do |
| 75 | + raise 'Undercover failed' unless undercover.success? |
| 76 | +end |
| 77 | + |
| 78 | +desc 'Branch-focused fast-feedback quality/spec/coverage checks' |
| 79 | +task test: %i[overcommit spec typecheck] do |
| 80 | + # do these in order |
| 81 | + Rake::Task['typecheck_strict'].invoke |
| 82 | + Rake::Task['typecheck_strong'].invoke |
| 83 | + Rake::Task['typecheck_alpha'].invoke |
| 84 | +end |
| 85 | + |
| 86 | +desc 'Re-run failed specs. Add --fail-fast in your .rspec-local file if desired.' |
| 87 | +task :spec_failed do |
| 88 | + # allow user to check out any persistent failures while looking for |
| 89 | + # more in the whole test suite |
| 90 | + sh 'TEST_COVERAGE_COMMAND_NAME=next-failure bundle exec rspec --only-failures || true' |
| 91 | +end |
| 92 | + |
| 93 | +desc 'Run undercover and show output without failing the task if it fails' |
| 94 | +task :undercover_no_fail do |
| 95 | + undercover |
| 96 | +rescue StandardError |
| 97 | + puts 'Undercover failed, but continuing with other tasks.' |
| 98 | +end |
| 99 | + |
| 100 | +# @return [void] |
| 101 | +def simplecov_collate |
| 102 | + require 'simplecov' |
| 103 | + require 'simplecov-lcov' |
| 104 | + require 'undercover/simplecov_formatter' |
| 105 | + |
| 106 | + SimpleCov.collate(Dir['coverage/{next-failure,full,ad-hoc}/.resultset.json']) do |
| 107 | + cname = 'combined' |
| 108 | + command_name cname |
| 109 | + new_dir = File.join('coverage', cname) |
| 110 | + coverage_dir new_dir |
| 111 | + |
| 112 | + formatter \ |
| 113 | + SimpleCov::Formatter::MultiFormatter |
| 114 | + .new([ |
| 115 | + SimpleCov::Formatter::HTMLFormatter, |
| 116 | + SimpleCov::Formatter::Undercover, |
| 117 | + SimpleCov::Formatter::LcovFormatter |
| 118 | + ]) |
| 119 | + SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true |
| 120 | + end |
| 121 | + puts 'Simplecov collated results into coverage/combined/.resultset.json' |
| 122 | +rescue StandardError => e |
| 123 | + puts "Simplecov collate failed: #{e.message}" |
| 124 | +ensure |
| 125 | + $stdout.flush |
| 126 | +end |
| 127 | + |
| 128 | +desc 'Add incremental coverage for rapid iteration with undercover' |
| 129 | +task :simplecov_collate do |
| 130 | + simplecov_collate |
| 131 | +end |
| 132 | + |
| 133 | +desc 'Show quality checks on this development branch so far, including any staged files' |
| 134 | +task :overcommit do |
| 135 | + # OVERCOMMIT_DEBUG=1 will show more detail |
| 136 | + sh 'SOLARGRAPH_ASSERTS=on bundle exec overcommit --run --diff origin/master' |
| 137 | +end |
0 commit comments