|
6 | 6 | WMH = Overcommit::MessageProcessor::WARNINGS_MODIFIED_HEADER + "\n"
|
7 | 7 | EUH = Overcommit::MessageProcessor::ERRORS_UNMODIFIED_HEADER + "\n"
|
8 | 8 | WUH = Overcommit::MessageProcessor::WARNINGS_UNMODIFIED_HEADER + "\n"
|
| 9 | + EGH = Overcommit::MessageProcessor::ERRORS_GENERIC_HEADER + "\n" |
| 10 | + WGH = Overcommit::MessageProcessor::WARNINGS_GENERIC_HEADER + "\n" |
9 | 11 |
|
10 | 12 | let(:config) { double('config') }
|
11 | 13 | let(:context) { double('context') }
|
|
27 | 29 | end
|
28 | 30 | end
|
29 | 31 |
|
30 |
| - def error(file, line) |
| 32 | + def error(file = nil, line = nil) |
31 | 33 | Overcommit::Hook::Message.new(:error, file, line, 'Error')
|
32 | 34 | end
|
33 | 35 |
|
34 |
| - def warning(file, line) |
| 36 | + def warning(file = nil, line = nil) |
35 | 37 | Overcommit::Hook::Message.new(:warning, file, line, 'Warning')
|
36 | 38 | end
|
37 | 39 |
|
@@ -209,5 +211,80 @@ def warning(file, line)
|
209 | 211 | it { should == [:fail, "#{EMH}Error\n#{WMH}Warning\n"] }
|
210 | 212 | end
|
211 | 213 | end
|
| 214 | + |
| 215 | + context 'when there are generic errors' do |
| 216 | + let(:messages) { [error] * 2 } |
| 217 | + let(:setting) { 'report' } |
| 218 | + |
| 219 | + it { should == [:fail, "Error\nError\n"] } |
| 220 | + end |
| 221 | + |
| 222 | + context 'when there are generic warnings' do |
| 223 | + let(:messages) { [warning] * 2 } |
| 224 | + let(:setting) { 'report' } |
| 225 | + |
| 226 | + it { should == [:warn, "Warning\nWarning\n"] } |
| 227 | + end |
| 228 | + |
| 229 | + context 'when there are generic errors and warnings' do |
| 230 | + let(:messages) { [warning, error] * 2 } |
| 231 | + let(:setting) { 'report' } |
| 232 | + |
| 233 | + it { should == [:fail, "Warning\nError\nWarning\nError\n"] } |
| 234 | + end |
| 235 | + |
| 236 | + context 'when there are errors and warnings on modified/unmodified lines' do |
| 237 | + let(:modified_lines) { { 'a.txt' => [2], 'b.txt' => [3, 4] } } |
| 238 | + let(:setting) { 'report' } |
| 239 | + |
| 240 | + let(:messages) do |
| 241 | + [ |
| 242 | + warning('a.txt', 3), |
| 243 | + warning('b.txt', 3), |
| 244 | + error('a.txt', 2), |
| 245 | + error('b.txt', 5), |
| 246 | + ] |
| 247 | + end |
| 248 | + |
| 249 | + context 'and there are generic errors before them' do |
| 250 | + let(:messages) { [error] * 2 + super() } |
| 251 | + |
| 252 | + it do |
| 253 | + should == [:fail, "#{EGH}Error\nError\n" \ |
| 254 | + "#{EMH}Error\n#{WMH}Warning\n" \ |
| 255 | + "#{EUH}Error\n#{WUH}Warning\n"] |
| 256 | + end |
| 257 | + end |
| 258 | + |
| 259 | + context 'and there are generic warnings before them' do |
| 260 | + let(:messages) { [warning] * 2 + super() } |
| 261 | + |
| 262 | + it do |
| 263 | + should == [:fail, "#{WGH}Warning\nWarning\n" \ |
| 264 | + "#{EMH}Error\n#{WMH}Warning\n" \ |
| 265 | + "#{EUH}Error\n#{WUH}Warning\n"] |
| 266 | + end |
| 267 | + end |
| 268 | + |
| 269 | + context 'and there are generic errors after them' do |
| 270 | + let(:messages) { super() + [error] * 2 } |
| 271 | + |
| 272 | + it do |
| 273 | + should == [:fail, "#{EGH}Error\nError\n" \ |
| 274 | + "#{EMH}Error\n#{WMH}Warning\n" \ |
| 275 | + "#{EUH}Error\n#{WUH}Warning\n"] |
| 276 | + end |
| 277 | + end |
| 278 | + |
| 279 | + context 'and there are generic warnings after them' do |
| 280 | + let(:messages) { super() + [warning] * 2 } |
| 281 | + |
| 282 | + it do |
| 283 | + should == [:fail, "#{WGH}Warning\nWarning\n" \ |
| 284 | + "#{EMH}Error\n#{WMH}Warning\n" \ |
| 285 | + "#{EUH}Error\n#{WUH}Warning\n"] |
| 286 | + end |
| 287 | + end |
| 288 | + end |
212 | 289 | end
|
213 | 290 | end
|
0 commit comments