Repository: melexis/warnings-plugin

Issue:
Return code of main() could/should be number of warnings
When count of warnings is not within limit min/max, the return code of main() could be the number of actual warnings found. This way programs can take the return value from shell and do something with it.

Comments:

Patch:
diff --git a/README.rst b/README.rst
index 7b37e9c..139e744 100644
--- a/README.rst
+++ b/README.rst
@@ -99,6 +99,11 @@ that case command will look like:
 
 Help prints all currently supported commands and their usages.
 
+The command returns (shell $? variable):
+
+- value 0 when the number of counted warnings is within the supplied minimum and maximum limits: ok,
+- number of counted warnings (positive) when the counter number is not within those limit.
+
 ----------------------------
 Parse for Sphinx warnings
 ----------------------------
diff --git a/src/mlx/warnings.py b/src/mlx/warnings.py
index 70a8474..ccbb45a 100644
--- a/src/mlx/warnings.py
+++ b/src/mlx/warnings.py
@@ -94,14 +94,14 @@ class WarningsChecker(object):
         ''' Function for checking whether the warning count is within the configured limits
 
         Returns:
-            int: 0 if the amount of warnings is within limits. 1 otherwise
+            int: 0 if the amount of warnings is within limits. the count of warnings otherwise
         '''
         if self.count > self.warn_max:
             print("Number of warnings ({count}) is higher than the maximum limit ({max}). Returning error code 1.".format(count=self.count, max=self.warn_max))
-            return 1
+            return self.count
         elif self.count < self.warn_min:
             print("Number of warnings ({count}) is lower than the minimum limit ({min}). Returning error code 1.".format(count=self.count, min=self.warn_min))
-            return 1
+            return self.count
         else:
             print("Number of warnings ({count}) is between limits {min} and {max}. Well done.".format(count=self.count, min=self.warn_min, max=self.warn_max))
             return 0


Test patch:
diff --git a/tests/test_limits.py b/tests/test_limits.py
index 7a6b1c9..9e477a8 100644
--- a/tests/test_limits.py
+++ b/tests/test_limits.py
@@ -45,7 +45,7 @@ class TestLimits(TestCase):
         warnings.check('testfile.c:12: warning: group test: ignoring title "Some test functions" that does not match old title "Some freaky test functions"')
         self.assertEqual(warnings.return_count(), 2)
         warnings.set_maximum(1)
-        self.assertEqual(warnings.return_check_limits(), 1)
+        self.assertEqual(warnings.return_check_limits(), 2)
         warnings.set_maximum(2)
         self.assertEqual(warnings.return_check_limits(), 0)
 
@@ -56,7 +56,7 @@ class TestLimits(TestCase):
         warnings.check('testfile.c:6: warning: group test: ignoring title "Some test functions" that does not match old title "Some freaky test functions"')
         self.assertEqual(warnings.return_count(), 2)
         # default behavior
-        self.assertEqual(warnings.return_check_limits(), 1)
+        self.assertEqual(warnings.return_check_limits(), 2)
 
         # to set minimum we need to make maximum higher
         warnings.set_maximum(10)
@@ -64,7 +64,7 @@ class TestLimits(TestCase):
             if x <= 3:
                 self.assertEqual(warnings.return_check_limits(), 0)
             else:
-                self.assertEqual(warnings.return_check_limits(), 1)
+                self.assertEqual(warnings.return_check_limits(), 2)
             warnings.set_minimum(x)