From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.bugs Subject: bug#22632: [PATCH 2/4] Make use of the `ert-with-function-mocked' macro Date: Thu, 11 Feb 2016 16:02:33 +0100 Message-ID: <1455202955-25751-2-git-send-email-mina86@mina86.com> References: <1455202258-23963-1-git-send-email-mina86@mina86.com> <1455202955-25751-1-git-send-email-mina86@mina86.com> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1455203049 4051 80.91.229.3 (11 Feb 2016 15:04:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Feb 2016 15:04:09 +0000 (UTC) To: 22632@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Feb 11 16:04:00 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aTsml-0001DR-TC for geb-bug-gnu-emacs@m.gmane.org; Thu, 11 Feb 2016 16:04:00 +0100 Original-Received: from localhost ([::1]:50801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTsml-00083R-1J for geb-bug-gnu-emacs@m.gmane.org; Thu, 11 Feb 2016 10:03:59 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTslx-00073b-97 for bug-gnu-emacs@gnu.org; Thu, 11 Feb 2016 10:03:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTslr-0001c0-Hp for bug-gnu-emacs@gnu.org; Thu, 11 Feb 2016 10:03:09 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:55943) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTslr-0001bw-E7 for bug-gnu-emacs@gnu.org; Thu, 11 Feb 2016 10:03:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aTslr-0000nh-8R for bug-gnu-emacs@gnu.org; Thu, 11 Feb 2016 10:03:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michal Nazarewicz Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 Feb 2016 15:03:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22632 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 22632-submit@debbugs.gnu.org id=B22632.14552029753035 (code B ref 22632); Thu, 11 Feb 2016 15:03:03 +0000 Original-Received: (at 22632) by debbugs.gnu.org; 11 Feb 2016 15:02:55 +0000 Original-Received: from localhost ([127.0.0.1]:36846 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aTsli-0000mo-Pi for submit@debbugs.gnu.org; Thu, 11 Feb 2016 10:02:54 -0500 Original-Received: from mail-wm0-f54.google.com ([74.125.82.54]:36120) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aTslh-0000mH-58 for 22632@debbugs.gnu.org; Thu, 11 Feb 2016 10:02:53 -0500 Original-Received: by mail-wm0-f54.google.com with SMTP id p63so77187968wmp.1 for <22632@debbugs.gnu.org>; Thu, 11 Feb 2016 07:02:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=2WOqY5KDHPkkx3V1r4Xj87F7DWX6mmeNQP5FcaPLQ/U=; b=gVMZ73ajlr2tHmuKMG5Sd8APwqgYchgHqmo0YkU3pCs61rv1SL0eU2lvLjI6CATnLa p2RWy6d0MYsXgMaOJAq7/ZmxEVgpIbQm/KS1S8rhUzM9/TUSXaz8CpCArSyt0PRVNllE 7Y6qA8s9FPzS5FKcUW9fkl4a75jCUS6+5MB8XTQCN5YYeKZG+A71Kmz4QAj1Jnj5ieGn GApuZ+7ZjbTj28NwsoP2F/HueoDtpiNB3IQS5hhh0D4Y5QoycOUflFORPGGvAOlyLJ98 50Qk4/OtoWK4Q63x4oQG4WbbsEio+todpARJQbSzekaoCuehITMx326aWprwy1056rCz W0LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=2WOqY5KDHPkkx3V1r4Xj87F7DWX6mmeNQP5FcaPLQ/U=; b=mozqnR+6uKfW3SsVg+LT7neY/zqR5eE/MiMPQIdPncMAA4Lo+IQjobYIk2m6fMaUQY aNkEMLGw5A6CEQxRP9k+bb0f7hwrwmdfIE/vjQzsLo0NEIZA5H0MLHUQc7arUIaMgJ4F VdvhxtT0app6E4Jzh7YOyq1oCjJPRcGbaoLSJE7acfSPlKFsQLYIEtwgOH0n6bhnHaGu smo2QkqdjF6T+Qg4Xarp0UylJ8WYsvem1iS8IOqUOLBU2FJfc1pJWeRQAFZ2t3oo3gGh wJSR+B5BM0JOF0cdd4FI4tgxR2i5xOxYCnvdGNIskQSZGRnG72tvUIyKIR31LjeVH3L2 CqWg== X-Gm-Message-State: AG10YOQg99HM2g5zgtSzSJUKIChcKAKWrw80AV50HeypcEewUPhmwynPcdTQqyJbY3ltALrC X-Received: by 10.194.158.135 with SMTP id wu7mr47327303wjb.142.1455202967514; Thu, 11 Feb 2016 07:02:47 -0800 (PST) Original-Received: from mpn.zrh.corp.google.com ([172.16.113.135]) by smtp.gmail.com with ESMTPSA id lc3sm7970885wjb.7.2016.02.11.07.02.44 for <22632@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Feb 2016 07:02:44 -0800 (PST) Original-Received: by mpn.zrh.corp.google.com (Postfix, from userid 126942) id C2EB71E0273; Thu, 11 Feb 2016 16:02:43 +0100 (CET) X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1455202955-25751-1-git-send-email-mina86@mina86.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:112892 Archived-At: * test/lisp/calendar/icalendar-tests.el (icalendar--create-uid): * test/lisp/vc/vc-bzr-tests.el (vc-bzr-test-bug9781): Use `ert-with-function-mocked' instead of implementing the fragile `unwind-protect' logic openly. --- test/lisp/calendar/icalendar-tests.el | 20 +++++++------------- test/lisp/vc/vc-bzr-tests.el | 9 +++------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/test/lisp/calendar/icalendar-tests.el b/test/lisp/calendar/icalendar-tests.el index 2c13a36..20d8834 100644 --- a/test/lisp/calendar/icalendar-tests.el +++ b/test/lisp/calendar/icalendar-tests.el @@ -32,6 +32,7 @@ ;;; Code: (require 'ert) +(require 'ert-x) (require 'icalendar) ;; ====================================================================== @@ -58,23 +59,16 @@ icalendar-tests--trim (ert-deftest icalendar--create-uid () "Test for `icalendar--create-uid'." (let* ((icalendar-uid-format "xxx-%t-%c-%h-%u-%s") - t-ct (icalendar--uid-count 77) (entry-full "30.06.1964 07:01 blahblah") (hash (format "%d" (abs (sxhash entry-full)))) (contents "DTSTART:19640630T070100\nblahblah") - (username (or user-login-name "UNKNOWN_USER")) - ) - (fset 't-ct (symbol-function 'current-time)) - (unwind-protect - (progn - (fset 'current-time (lambda () '(1 2 3))) - (should (= 77 icalendar--uid-count)) - (should (string= (concat "xxx-123-77-" hash "-" username "-19640630") - (icalendar--create-uid entry-full contents))) - (should (= 78 icalendar--uid-count))) - ;; restore 'current-time - (fset 'current-time (symbol-function 't-ct))) + (username (or user-login-name "UNKNOWN_USER"))) + (ert-with-function-mocked current-time (lambda () '(1 2 3)) + (should (= 77 icalendar--uid-count)) + (should (string= (concat "xxx-123-77-" hash "-" username "-19640630") + (icalendar--create-uid entry-full contents))) + (should (= 78 icalendar--uid-count))) (setq contents "blahblah") (setq icalendar-uid-format "yyy%syyy") (should (string= (concat "yyyDTSTARTyyy") diff --git a/test/lisp/vc/vc-bzr-tests.el b/test/lisp/vc/vc-bzr-tests.el index 82721ee..98d176c 100644 --- a/test/lisp/vc/vc-bzr-tests.el +++ b/test/lisp/vc/vc-bzr-tests.el @@ -25,6 +25,7 @@ ;;; Code: (require 'ert) +(require 'ert-x) (require 'vc-bzr) (require 'vc-dir) @@ -101,12 +102,8 @@ (while (vc-dir-busy) (sit-for 0.1)) (vc-dir-mark-all-files t) - (let ((f (symbol-function 'y-or-n-p))) - (unwind-protect - (progn - (fset 'y-or-n-p (lambda (prompt) t)) - (vc-next-action nil)) - (fset 'y-or-n-p f))) + (ert-with-function-mocked y-or-n-p (lambda (_) t) + (vc-next-action nil)) (should (get-buffer "*vc-log*"))) (delete-directory homedir t)))) -- 2.7.0.rc3.207.g0ac5344