GNU bug report logs - #66042
30.0.50; ERT test fails while trying to indent pretty-print

Previous Next

Package: emacs;

Reported by: Protesilaos Stavrou <info <at> protesilaos.com>

Date: Sun, 17 Sep 2023 06:14:02 UTC

Severity: normal

Tags: confirmed

Found in version 30.0.50

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Protesilaos Stavrou <info <at> protesilaos.com>
To: bug-gnu-emacs <at> gnu.org
Cc: Lei Zhu <julytreee <at> gmail.com>
Subject: 30.0.50; ERT test fails while trying to indent pretty-print
Date: Sun, 17 Sep 2023 09:13:06 +0300
Dear maintainers,

I have encountered a possible bug with an ERT test where it is trying to
perform indentation and fails with:

    lisp-indent-initial-state: Wrong type argument: wholenump, -2

This is the test I am running:

    (defun test-case (text pos expected)
      (with-temp-buffer
        (insert text)
        (goto-char pos)
        (backward-kill-word 1)
        (should (string-equal (buffer-string) expected))))

    (ert-deftest my-test ()
      (test-case "aaa)))" 7 "aaa"))

Upon investigating further, I found that 'ert--pp-with-indentation-and-newline'
performs an 'indent-sexp'.  When I comment that out and redefine the
function, the test no longer reports an indentation error with
wholenump.  The test fails gracefully, as expected.  Thus, the whole
file I am using is this:

    (require 'ert)

    (defun ert--pp-with-indentation-and-newline (object)
      "Pretty-print OBJECT, indenting it to the current column of point.
    Ensures a final newline is inserted."
      (let ((begin (point))
            (pp-escape-newlines t)
            (print-escape-control-characters t))
        (pp object (current-buffer))
        (unless (bolp) (insert "\n"))
        (save-excursion
          (goto-char begin)
          ;; (indent-sexp)
          )))

    (defun test-case (text pos expected)
      (with-temp-buffer
        (insert text)
        (goto-char pos)
        (backward-kill-word 1)
        (should (string-equal (buffer-string) expected))))

    (ert-deftest my-test ()
      (test-case "aaa)))" 7 "aaa"))

To be clear, my test should fail, but that is expected.  I encountered
the ERT wholenump issue which prevented me from going further.

Is the indentation expected behaviour?  Can we disable any/all
indentation of sexps within a test?

Thank you for your time,
Protesilaos (or simply "Prot")

-- 
Protesilaos Stavrou
https://protesilaos.com




This bug report was last modified 1 year and 271 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.