Currently if commonprefix is passed ['foo', 'bar'] it will pass an empty
list to join, which requires at least one argument to work. This will
cause an exception to be raised. Rather than doing that, we should check
that there are common values, and just return '' if there isn't.

Signed-off-by: Dylan Baker <[email protected]>
---
 framework/grouptools.py             | 6 +++++-
 framework/tests/grouptools_tests.py | 5 +++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/framework/grouptools.py b/framework/grouptools.py
index b223bf4..62d3f9c 100644
--- a/framework/grouptools.py
+++ b/framework/grouptools.py
@@ -94,7 +94,11 @@ def commonprefix(args):
         else:
             break
 
-    return join(*common)
+    # Join needs at least one element to join
+    if common:
+        return join(*common)
+    else:
+        return ''
 
 
 def join(first, *args):
diff --git a/framework/tests/grouptools_tests.py 
b/framework/tests/grouptools_tests.py
index f36e350..acab7ed 100644
--- a/framework/tests/grouptools_tests.py
+++ b/framework/tests/grouptools_tests.py
@@ -114,3 +114,8 @@ def test_join_empty():
     expected = 'spec'
     test = grouptools.join('', 'spec')
     nt.eq_(expected, test)
+
+
+def test_commonprefix_none():
+    """grouptools.commonprefix: returns '' when no values are the same"""
+    nt.eq_('', grouptools.commonprefix(['foo', 'bar']))
-- 
2.5.1

_______________________________________________
Piglit mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to