From: Rafael Zalamena Date: Tue, 7 Nov 2017 23:17:15 +0000 (-0200) Subject: topotest: fix a regression in version_cmp X-Git-Tag: frr-7.1-dev~151^2~199 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=034237db1254da359f13933b5beab16b15b65838;p=matthieu%2Ffrr.git topotest: fix a regression in version_cmp It was found a regression on an edge case when the second number in the comparison was (at least) 2 numbers longer the comparison would fail with a wrong return value. It succeeded for some cases because the first comparison in the exception was correct, but not the second. --- diff --git a/tests/topotests/lib/test/test_version.py b/tests/topotests/lib/test/test_version.py old mode 100644 new mode 100755 index 4bb1c0b018..9204ac2084 --- a/tests/topotests/lib/test/test_version.py +++ b/tests/topotests/lib/test/test_version.py @@ -78,3 +78,10 @@ def test_invalid_versions(): assert version_cmp(curver, badver2) assert version_cmp(curver, badver3) assert version_cmp(curver, badver4) + +def test_regression_1(): + """ + Test regression on the following type of comparison: '3.0.2' > '3' + Expected result is 1. + """ + assert version_cmp('3.0.2', '3') == 1 diff --git a/tests/topotests/lib/topotest.py b/tests/topotests/lib/topotest.py index 0e0a1e8876..ccdea83393 100644 --- a/tests/topotests/lib/topotest.py +++ b/tests/topotests/lib/topotest.py @@ -291,7 +291,7 @@ def version_cmp(v1, v2): while v1g: v1n = int(v1g.pop()) if v1n > 0: - return -1 + return 1 break if v1n > v2n: