branch: externals/hyperbole commit 564c1475877c18ae7a9750ed99620f0303214d7f Author: Mats Lidell <mats.lid...@lidells.se> Commit: GitHub <nore...@github.com>
Add tests for hypb-ert (#429) --- ChangeLog | 5 ++++ test/hypb-ert-tests.el | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/ChangeLog b/ChangeLog index 00ed751672..650a09db5b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2024-01-02 Mats Lidell <ma...@gnu.org> + +* test/hypb-ert-tests.el (hypb-ert-tests--def-at-p) + (hypb-ert-tests--edebug-is-called): Add tests for hypb-ert. + 2024-01-01 Bob Weiner <r...@gnu.org> * hypb-ert.el (hypb-ert-def-at-p): Update doc. Fix grouping ref that was diff --git a/test/hypb-ert-tests.el b/test/hypb-ert-tests.el new file mode 100644 index 0000000000..cdc39118f9 --- /dev/null +++ b/test/hypb-ert-tests.el @@ -0,0 +1,63 @@ +;;; hypb-ert-tests.el --- tests for hypb-ert -*- lexical-binding: t; -*- +;; +;; Author: Mats Lidell +;; +;; Orig-Date: 1-Jan-24 at 23:11:54 +;; Last-Mod: 2-Jan-24 at 00:28:42 by Mats Lidell +;; +;; SPDX-License-Identifier: GPL-3.0-or-later +;; +;; Copyright (C) 2024 Free Software Foundation, Inc. +;; See the "HY-COPY" file for license information. +;; +;; This file is part of GNU Hyperbole. + +;;; Commentary: +;; + +;;; Code: + +(require 'ert) +(require 'el-mock) +(require 'hypb-ert) + +(ert-deftest hypb-ert-tests--def-at-p () + "Verify an `ert-deftest' name is identified." + (let ((test-name "hypb-ert-tests--test")) + (with-temp-buffer + (insert "(ert-deftest " test-name " ()\n\"Docstring.\"\nt\n)\n") + + (goto-char (point-min)) + (should-not (hypb-ert-def-at-p)) + + (goto-char (1+ (point-min))) + (should (string= (hypb-ert-def-at-p) test-name)) + + (goto-char (- (line-end-position) 3)) + (should (string= (hypb-ert-def-at-p) test-name)) + + (goto-char (- (line-end-position) 2)) + (should-not (hypb-ert-def-at-p)) + + (end-of-line) + (should-not (hypb-ert-def-at-p)) + + (goto-char (1+ (point-min))) + (pcase-let ((`(,name ,start ,end) + (hypb-ert-def-at-p t))) + (should (string= name test-name)) + (should (string= (buffer-substring start end) test-name)))))) + +(ert-deftest hypb-ert-tests--edebug-is-called () + "Verify `edebug-defun' is called when debug-it argument is set." + (let ((test-name "hypb-ert-tests--test")) + (with-temp-buffer + (insert "(ert-deftest " test-name " ()\n\"Docstring.\"\nt\n)\n") + (emacs-lisp-mode) + (goto-char (1+ (point-min))) + (mocklet (((edebug-defun) => t) + ((hypb-ert *) => t)) + (hypb-ert-run-test-at-definition test-name t))))) + +(provide 'hypb-ert-tests) +;;; hypb-ert-tests.el ends here