Subject: bug#67862: 30.0.50; Handler-bind and ert-test-error-debug

From: Gerd Möllmann <[email-masked]>
Date: Tue, 26 Dec 2023 19:00:34 +0100

Stefan Monnier <[email-masked]> writes:

> AFAICT
>
>             (let ((ert-debug-on-error t))
>               (ert-run-test test))
>
> is supposed to say "run the test and please pop up a debugger if there's
> an error".  The ERT code even goes to the trouble to store&use the value of
> `ert-debug-on-error` upon entry to the tests rather the value that
> happens to be current when the error is signaled.

That's also what I've seen in ert.el, and how I think things are
supposed to work.

> So to me the code looks like it wants to test that `ert-debug-on-error`
> indeed brings up a debugger, tho none of the surrounding code tries to
> detect whether the debugger is/was entered, and instead that surrounding
> code uses `condition-case` which prevents entering the debugger.
>
> Is it really the purpose of this test to make sure that "even if we ask
> for the debugger, `condition-case` prevents the use of a debugger"?

from the fact that the test

  (ert-deftest ert-test-error-debug ()
    (let ((test (make-ert-test :body (lambda () (error "Error message")))))
      (condition-case condition
          (progn
            (let ((ert-debug-on-error t))
              (ert-run-test test))
            (cl-assert nil))
        ((error)
         (cl-assert (equal condition '(error "Error message")) t)))))

explicitly tests that the handler for `error' sees the "Error message"
(last 2 lines of the test), I'd also conjecture that tests intends to
check that the debugger does not run in a condition-case.

Also, a bit strange is that this:

  (ert-deftest ert-test-fail-debug-with-condition-case ()
    (let ((test (make-ert-test :body (lambda () (ert-fail "failure message")))))
      (condition-case condition
          (progn
            (let ((ert-debug-on-error t))
              (ert-run-test test))
            (cl-assert nil))
        ((error)
         (cl-assert (equal condition '(ert-test-failed "failure message")) t)))))

is almost the saem test? (Uses ert-fail instead of error).

BTW, there are some more tests in the vicinity of the test above that
test if the debugger is/isn't invoked in various circumstances.