From 034237db1254da359f13933b5beab16b15b65838 Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Tue, 7 Nov 2017 21:17:15 -0200 Subject: [PATCH] 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. --- tests/topotests/lib/test/test_version.py | 7 +++++++ tests/topotests/lib/topotest.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) mode change 100644 => 100755 tests/topotests/lib/test/test_version.py 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: -- 2.39.5