Skip to content

Commit

Permalink
coalaTest: Add test preventing unknown warnings
Browse files Browse the repository at this point in the history
Currently the test_coala_with_color and _without_color
tests fail with little indication of what is happening,
especially as the first warnings messages are related to
the .coafile 'Default' section.  The reported error is
trimmed, preventing the real cause of the error from
being seen in the logs.  It can be hiding a backtrace.

This introduces a new test which explicitly checks for
the two types of warnings which are currently happening,
being the 'Default' section and missing bears warnings.
These are happening because the repository .coafile is
being loaded instead of only using CLI arguments.

Then any additional warnings are considered to be an
error, and the entire output is show, so the reader
can see what is causing the problem.

Related to coala#5390
  • Loading branch information
jayvdb committed Nov 1, 2018
1 parent db96a8f commit 3dad245
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/coalaTest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import sys
import unittest
import unittest.mock
Expand Down Expand Up @@ -344,6 +345,38 @@ def test_logged_error_causes_non_zero_exitcode(self):

assert exitcode == 1

def test_coala_no_unexpected_warnings(self):
with bear_test_module(), \
prepare_file(['#fixme'], None) as (lines, filename):
retval, stdout, stderr = execute_coala(
coala.main, 'coala')
errors = filter(bool, stderr.split('\n'))
errors = list(errors)

unexpected = errors.copy()

expected = [
err for err in unexpected
if "Implicit 'Default' section inheritance" in err]
self.assertNotEqual([], expected)
# Filter them out
unexpected = [err for err in unexpected if err not in expected]

expected = [
err for err in errors
if re.search("No bears matching '.*' were installed", err)]
self.assertNotEqual([], expected)
# Filter them out
unexpected = [err for err in unexpected if err not in expected]

# Every error message must be about 'fixme'
unexpected = [err for err in errors if '#fixme' not in err]
self.assertEqual([], unexpected)
self.assertEqual(
retval, 0,
'coala must return zero when there are no errors;'
' errors={errors}'.format(errors=list(errors)))

def test_coala_with_color(self):
with bear_test_module(), \
prepare_file(['#fixme'], None) as (lines, filename):
Expand Down

0 comments on commit 3dad245

Please sign in to comment.