Function: ibtypes::ert-should

ibtypes::ert-should is a byte-compiled function defined in hsys-ert.el.

Signature

(ibtypes::ert-should)

Documentation

Jump to the source code definition of a should expr from an ert test failure.

If on the first line of a failure, jump to the source definition of the associated test.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20260414.325/hsys-ert.el
(require 'hmouse-tag)  ;; For smart-lisp

;;; ************************************************************************
;;; Implicit button types
;;; ************************************************************************

(defib ert-should ()
  "Jump to the source code definition of a should expr from an ert test failure.
If on the first line of a failure, jump to the source definition of the
associated test."
  (when (or (and (derived-mode-p 'ert-results-mode)
		 (save-excursion
		   (forward-line 0)
		   (or (search-backward "(ert-test-failed\n" nil t)
                       (search-forward "(ert-test-failed\n" nil t))))
	    ;; In any other mode, consider only the current line
	    (save-excursion
	      (forward-line 0)
              (search-forward "(ert-test-failed" (line-end-position) t)))
    (catch 'exit
    (save-excursion
      (save-restriction
        (forward-line 0)
        (cond ((looking-at "\\`\\|^[AFPS] ")
	       ;; On a result line with a test name, jump to the test
               (goto-char (match-end 0))
	       ;; Use the test definition name as the ibut label
               (ibut:label-set (buffer-substring-no-properties
				(+ 2 (line-beginning-position))
				(line-end-position))
			       (+ 2 (line-beginning-position))
			       (line-end-position))
               (let ((major-mode 'emacs-lisp-mode))
                 (if (button-at (point))
                     ;; jump to source buffer
                     (push-button)
                   (throw 'exit (hact 'smart-lisp)))))
               ((looking-at "\\s-*(ert-test-failed\\s-")
		(when (re-search-forward "^\\s-+(\\((should\\)\\(-\\|\\s-\\)" nil t)
                  (goto-char (match-beginning 1))))
               ((looking-at "\\s-*(\\((should\\)\\(-\\|\\s-\\)")
		(goto-char (match-beginning 1)))
               ((re-search-backward "\\`\\|^[AFPS] " nil t)
		(let ((start (point)))
                  (goto-char (1+ (point)))
                  (when (re-search-forward "^[AFPS] \\|\\'" nil t)
                    (goto-char (1- (match-beginning 0)))
                    (narrow-to-region start (point))
                    (goto-char start)
                    (when (re-search-forward "^\\s-+(\\((should\\)\\(-\\|\\s-\\)" nil t)
                      (goto-char (match-beginning 1)))))))
              (when (looking-at "(should\\(-\\|\\s-\\)")
		(let ((should-regexp (regexp-quote (thing-at-point 'sexp))))
		  (setq should-regexp (replace-regexp-in-string
                                       "[ \t\n\r\f]+" "\\s-+" (string-trim should-regexp)
                                       t t))
		  ;; follow the function link to the source file of the function
		  (when (re-search-backward "^[AFPS] " nil t)
		    (goto-char (match-end 0))
		    (let ((major-mode 'emacs-lisp-mode))
                      (if (button-at (point))
			  ;; jump to source buffer
			  (push-button)
			(smart-lisp))
                      ;; re-search-forward for should-regexp
                      (when (re-search-forward should-regexp nil t)
			(goto-char (match-beginning 0))
			(ibut:label-set "(should" (point) (+ (point) 7))
			(hact 'identity t)))))))))))