diff mbox series

[ovs-dev,v4] checkpatch: Normalize exit code for Windows

Message ID 20190318224300.37416-1-aserdean@ovn.org
State Accepted
Headers show
Series [ovs-dev,v4] checkpatch: Normalize exit code for Windows | expand

Commit Message

Alin-Gabriel Serdean March 18, 2019, 10:43 p.m. UTC
Using python `sys.exit(-1)` on Windows produces mixed results.
Let's take the following results from different shells:
CMD
>python -c "import sys; sys.exit(-1)" & echo %errorlevel%
1
MSYS
$ python -c "import sys; sys.exit(-1)" && echo $?
0
WSL
$ python -c "import sys; sys.exit(-1)"; echo $?
255

this results in the following tests to fail:
checkpatch

 10: checkpatch - sign-offs                          FAILED (checkpatch.at:32)
 11: checkpatch - parenthesized constructs           FAILED (checkpatch.at:32)
 12: checkpatch - parenthesized constructs - for     FAILED (checkpatch.at:32)
 13: checkpatch - comments                           FAILED (checkpatch.at:32)

because of:
 ./checkpatch.at:32: exit code was 0, expected 255

This patch introduces a positive constant for the default exit code (1)
similar to other OVS utilities.

Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
Acked-by: Ben Pfaff <blp@ovn.org>
---
 tests/checkpatch.at     |  2 +-
 utilities/checkpatch.py | 23 ++++++++++++-----------
 2 files changed, 13 insertions(+), 12 deletions(-)

Comments

Alin-Gabriel Serdean April 3, 2019, 3:02 p.m. UTC | #1
Applied on master!

> On 19 Mar 2019, at 00:43, Alin Gabriel Serdean <aserdean@ovn.org> wrote:
> 
> Using python `sys.exit(-1)` on Windows produces mixed results.
> Let's take the following results from different shells:
> CMD
>> python -c "import sys; sys.exit(-1)" & echo %errorlevel%
> 1
> MSYS
> $ python -c "import sys; sys.exit(-1)" && echo $?
> 0
> WSL
> $ python -c "import sys; sys.exit(-1)"; echo $?
> 255
> 
> this results in the following tests to fail:
> checkpatch
> 
> 10: checkpatch - sign-offs                          FAILED (checkpatch.at:32)
> 11: checkpatch - parenthesized constructs           FAILED (checkpatch.at:32)
> 12: checkpatch - parenthesized constructs - for     FAILED (checkpatch.at:32)
> 13: checkpatch - comments                           FAILED (checkpatch.at:32)
> 
> because of:
> ./checkpatch.at:32: exit code was 0, expected 255
> 
> This patch introduces a positive constant for the default exit code (1)
> similar to other OVS utilities.
> 
> Signed-off-by: Alin Gabriel Serdean <aserdean@ovn.org>
> Acked-by: Ben Pfaff <blp@ovn.org>
> Acked-by: Aaron Conole <aconole@redhat.com>
diff mbox series

Patch

diff --git a/tests/checkpatch.at b/tests/checkpatch.at
index 9a72bc279..07f4b137c 100755
--- a/tests/checkpatch.at
+++ b/tests/checkpatch.at
@@ -30,7 +30,7 @@  try_checkpatch__() {
         :
     elif test -s expout; then
         AT_CHECK([$2 $top_srcdir/utilities/checkpatch.py -q test.patch],
-                 [255], [stdout])
+                 [1], [stdout])
         AT_CHECK([sed '/^Lines checked:/,$d' stdout], [0], [expout])
     else
         AT_CHECK([$2 $top_srcdir/utilities/checkpatch.py -q test.patch])
diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index 4164ea8ec..369911960 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -24,6 +24,7 @@  import sys
 RETURN_CHECK_INITIAL_STATE = 0
 RETURN_CHECK_STATE_WITH_RETURN = 1
 RETURN_CHECK_AWAITING_BRACE = 2
+EXIT_FAILURE = 1
 __errors = 0
 __warnings = 0
 empty_return_check_state = 0
@@ -842,7 +843,7 @@  def ovs_checkpatch_parse(text, filename, author=None, committer=None):
 
     run_file_checks(text)
     if __errors or __warnings:
-        return -1
+        return EXIT_FAILURE
     return 0
 
 
@@ -868,10 +869,10 @@  Check options:
           % sys.argv[0])
 
 
-def ovs_checkpatch_print_result(result):
+def ovs_checkpatch_print_result():
     global quiet, __warnings, __errors, total_line
 
-    if result < 0:
+    if __errors or __warnings:
         print("Lines checked: %d, Warnings: %d, Errors: %d\n" %
               (total_line, __warnings, __errors))
     elif not quiet:
@@ -891,7 +892,7 @@  def ovs_checkpatch_file(filename):
     result = ovs_checkpatch_parse(part.get_payload(decode=False), filename,
                                   mail.get('Author', mail['From']),
                                   mail['Commit'])
-    ovs_checkpatch_print_result(result)
+    ovs_checkpatch_print_result()
     return result
 
 
@@ -925,7 +926,7 @@  if __name__ == '__main__':
                                        "quiet"])
     except:
         print("Unknown option encountered. Please rerun with -h for help.")
-        sys.exit(-1)
+        sys.exit(EXIT_FAILURE)
 
     for o, a in optlist:
         if o in ("-h", "--help"):
@@ -951,7 +952,7 @@  if __name__ == '__main__':
             quiet = True
         else:
             print("Unknown option '%s'" % o)
-            sys.exit(-1)
+            sys.exit(EXIT_FAILURE)
 
     if sys.stdout.isatty():
         colors = True
@@ -977,17 +978,17 @@  Subject: %s
             if not quiet:
                 print('== Checking %s ("%s") ==' % (revision[0:12], name))
             result = ovs_checkpatch_parse(patch, revision)
-            ovs_checkpatch_print_result(result)
+            ovs_checkpatch_print_result()
             if result:
-                status = -1
+                status = EXIT_FAILURE
         sys.exit(status)
 
     if not args:
         if sys.stdin.isatty():
             usage()
-            sys.exit(-1)
+            sys.exit(EXIT_FAILURE)
         result = ovs_checkpatch_parse(sys.stdin.read(), '-')
-        ovs_checkpatch_print_result(result)
+        ovs_checkpatch_print_result()
         sys.exit(result)
 
     status = 0
@@ -996,5 +997,5 @@  Subject: %s
             print('== Checking "%s" ==' % filename)
         result = ovs_checkpatch_file(filename)
         if result:
-            status = -1
+            status = EXIT_FAILURE
     sys.exit(status)