changeset 20863:876c17336b4e

revset: raise ValueError when calling min or max on empty smartset min([]) raise a ValueError, we do the same thing in smartset.min() and smartset.max() for the sake of consistency. The min/amax test are greatly improved in the process to prevent this familly of regression
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 28 Mar 2014 17:00:13 -0700
parents 97b2f26dfc43
children 9a75d2559cff
files mercurial/revset.py tests/test-revset.t
diffstat 2 files changed, 37 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Thu Mar 20 18:44:25 2014 -0700
+++ b/mercurial/revset.py	Fri Mar 28 17:00:13 2014 -0700
@@ -2287,7 +2287,7 @@
         """return the first revision in the set"""
         for r in self:
             return r
-        return None
+        raise ValueError('arg is an empty sequence')
 
     def _last(self):
         """return the last revision in the set"""
--- a/tests/test-revset.t	Thu Mar 20 18:44:25 2014 -0700
+++ b/tests/test-revset.t	Fri Mar 28 17:00:13 2014 -0700
@@ -355,10 +355,46 @@
   $ log 'matching(6:7, "phase parents user date branch summary files description substate")'
   6
   7
+
+Testing min and max
+
+max: simple
+
   $ log 'max(contains(a))'
   5
+
+max: simple on unordered set)
+
+  $ log 'max((4+0+2+5+7) and contains(a))'
+  5
+
+max: no result
+
+  $ log 'max(contains(stringthatdoesnotappearanywhere))'
+
+max: no result on unordered set
+
+  $ log 'max((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))'
+
+min: simple
+
   $ log 'min(contains(a))'
   0
+
+min: simple on unordered set
+
+  $ log 'min((4+0+2+5+7) and contains(a))'
+  0
+
+min: empty
+
+  $ log 'min(contains(stringthatdoesnotappearanywhere))'
+
+min: empty on unordered set
+
+  $ log 'min((4+0+2+5+7) and contains(stringthatdoesnotappearanywhere))'
+
+
   $ log 'merge()'
   6
   $ log 'branchpoint()'