From patchwork Mon Mar 31 18:39:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2, of, 2, V3] revset: raise ValueError when calling min or max on empty smartset From: Pierre-Yves David X-Patchwork-Id: 4160 Message-Id: <35a21b04c019e3993a66.1396291149@marginatus.alto.octopoid.net> To: mercurial-devel@selenic.com Cc: pierre-yves.david@ens-lyon.org Date: Mon, 31 Mar 2014 11:39:09 -0700 # HG changeset patch # User Pierre-Yves David # Date 1396051213 25200 # Fri Mar 28 17:00:13 2014 -0700 # Node ID 35a21b04c019e3993a6679b612cd28d108be92b1 # Parent c49f6dae96445ee65830f21dc76466d9384c659d 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 diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -2285,11 +2285,11 @@ class _orderedsetmixin(object): def _first(self): """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""" self.reverse() m = self._first() diff --git a/tests/test-revset.t b/tests/test-revset.t --- a/tests/test-revset.t +++ b/tests/test-revset.t @@ -353,14 +353,50 @@ ancestor can accept 0 or more arguments $ log 'matching(6)' 6 $ 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()' 1 4