all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alex <agrambot@gmail.com>
To: Tino Calancha <tino.calancha@gmail.com>
Cc: Gemini Lasswell <gazally@runbox.com>, 24402@debbugs.gnu.org
Subject: bug#24402: should-error doesn't catch all errors
Date: Wed, 05 Jul 2017 13:56:48 -0600	[thread overview]
Message-ID: <87o9sywtbz.fsf@lylat> (raw)
In-Reply-To: <874lur0zki.fsf@calancha-pc> (Tino Calancha's message of "Wed, 05 Jul 2017 22:43:09 +0900")

Tino Calancha <tino.calancha@gmail.com> writes:

> Hi!
> I just arrived from teletransportation from Bug#27559.  Very fast! (and
> cheap!).
>
> Thank you for looking on this.  I think you go in the right direction to
> fix this problem.
>
> * I have updated your patch and all the test suite pass (even your
>   proposed tests in Bug#27559 without requiring "(eval '....)").
>
> * Bear in mind that I am far to be an expert on `ert.el', and i am
>   already in my second beer, so please double check that
>   the patch have sense.
>   
>
> commit a07f99f062f3da3418060ef30e1a00030fa0b947
> Author: Tino Calancha <tino.calancha@gmail.com>
> Date:   Wed Jul 5 22:11:46 2017 +0900
>
>     Tweak Alex's 2nd patch
>
> diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el
> index eb2b2e3e11..2d131cf99e 100644
> --- a/lisp/emacs-lisp/ert.el
> +++ b/lisp/emacs-lisp/ert.el
> @@ -276,13 +276,15 @@ ert--special-operator-p
>  (defun ert--expand-should-1 (whole form inner-expander)
>    "Helper function for the `should' macro and its variants."
>    (let ((form
> -         (macroexpand form (append (bound-and-true-p
> -                                    byte-compile-macro-environment)
> -                                   (cond
> -                                    ((boundp 'macroexpand-all-environment)
> -                                     macroexpand-all-environment)
> -                                    ((boundp 'cl-macro-environment)
> -                                     cl-macro-environment))))))
> +         (condition-case err
> +             (macroexpand-all form (append (bound-and-true-p
> +                                            byte-compile-macro-environment)
> +                                           (cond
> +                                            ((boundp 'macroexpand-all-environment)
> +                                             macroexpand-all-environment)
> +                                            ((boundp 'cl-macro-environment)
> +                                             cl-macro-environment))))
> +           (error `(signal ',(car err) ',(cdr err))))))
>      (cond
>       ((or (atom form) (ert--special-operator-p (car form)))
>        (let ((value (cl-gensym "value-")))
> @@ -303,8 +305,14 @@ ert--expand-should-1
>                (args (cl-gensym "args-"))
>                (value (cl-gensym "value-"))
>                (default-value (cl-gensym "ert-form-evaluation-aborted-")))
> -          `(let ((,fn (function ,fn-name))
> -                 (,args (list ,@arg-forms)))
> +          `(let* ((,fn (function ,fn-name))
> +                  (,args (condition-case err
> +                             (list ,@arg-forms)
> +                           (error (if (or (eq (car err) 'ert-test-failed)
> +                                          (eq (car err) 'ert-test-skipped))
> +                                      (list ,@arg-forms)
> +                                    (setq ,fn #'signal)
> +                                    (list (car err) (cdr err)))))))
>               (let ((,value ',default-value))
>                 ,(funcall inner-expander
>                           `(setq ,value (apply ,fn ,args))

Thanks, that helps with my understanding of the issue. Sadly, I don't
think your tweak will work in all cases, namely whenever (list
,@arg-forms) has side-effects. Luckily this doesn't happen in any
current tests, but I think those types of tests should be supported.

I believe the following is why my previous diff doesn't work. Consider:

(let ((test (make-ert-test :body (lambda () (ert-fail "failed")))))
  (ert-run-test test))

The above returns a struct/record and does not error.

(let ((test (make-ert-test :body (lambda () (ert-fail "failed")))))
  (condition-case err
      (ert-run-test test)
    (error "woops")))

Even though ert-run-test by itself does not error, the error handler is
ran. I believe this is because `ert--run-test-internal' binds `debugger'
around the evaluation of the test to somehow suppress this error.

Using condition-case-unless-debug gets around this, but now anytime
debug-on-error is non-nil the condition-case won't catch the error. I'm
not sure how to solve this.





  reply	other threads:[~2017-07-05 19:56 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-10  1:26 bug#24402: 25.1.50; testcover-start breaks should-error Gemini Lasswell
     [not found] ` <handler.24402.B.14734739098199.ack@debbugs.gnu.org>
2016-09-20  4:27   ` bug#24402: More Information Gemini Lasswell
2017-07-04  3:28     ` bug#24402: should-error doesn't catch all errors (Was:bug#24402: More Information) Alex
2017-07-05  0:00       ` bug#24402: should-error doesn't catch all errors Alex
2017-07-05 13:43         ` Tino Calancha
2017-07-05 19:56           ` Alex [this message]
2017-07-07 10:15             ` Tino Calancha
2017-07-09  7:04               ` Alex
2017-07-11 12:18             ` npostavs
2017-07-12  3:47               ` Alex
2017-07-12 12:30                 ` npostavs
2017-07-12 16:45                   ` Alex
2017-07-13  1:31                     ` npostavs
2017-07-13  3:04                       ` Alex
2017-07-13  3:44                         ` npostavs
2017-07-13 22:45                           ` Alex
2017-07-13 23:49                             ` npostavs
2017-07-14  4:42                               ` Alex
2017-07-14  4:45                                 ` Alex
2017-07-15 21:57                                 ` npostavs
2017-07-16  3:49                                   ` Alex
2017-07-17  0:46                                     ` npostavs
2017-07-19 21:23                                     ` Gemini Lasswell
2017-07-19 22:40                                       ` Alex
2017-07-19 23:04                                       ` npostavs
2017-07-20  4:04                                         ` Alex
2017-07-20 19:23                                         ` Gemini Lasswell
2017-08-08  1:15                                           ` npostavs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o9sywtbz.fsf@lylat \
    --to=agrambot@gmail.com \
    --cc=24402@debbugs.gnu.org \
    --cc=gazally@runbox.com \
    --cc=tino.calancha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.