Skip to content

Commit

Permalink
strengthen regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
c committed Oct 7, 2024
1 parent 6ba523f commit 9f032cb
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 80 deletions.
72 changes: 0 additions & 72 deletions tests/bench.el

This file was deleted.

23 changes: 21 additions & 2 deletions tests/bench1.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
(load-file "bench.el")
;;; uniline.el --- Draw lines, boxes, & arrows with the keyboard -*- coding:utf-8; lexical-binding: t; -*-

(bench
;; Copyright (C) 2024 Thierry Banel

;; Author: Thierry Banel tbanelwebmin at free dot fr
;; Version: 1.0
;; URL: https://github.com/tbanel/uniline

;; Uniline is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; Uniline is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

(uniline-bench
"a b RET <right> c <right> - <right> <right> <right> <down> <left> <left> <left> <left> <left> <up> C-SPC <down> <right> <right> <right> <right> <right> <right> <insert> <down> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> RET RET <down> <right> <right> + <down> <left> <left> <left> <left> <insert> a a <left> <left> <left> <insert> a S-<up> <left> <left> <left> <left> <left> <left> <left> <left> RET <up> <up> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> - <up> <up> <up>"

"
Expand Down
23 changes: 21 additions & 2 deletions tests/bench2.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
(load-file "bench.el")
;;; uniline.el --- Draw lines, boxes, & arrows with the keyboard -*- coding:utf-8; lexical-binding: t; -*-

(bench
;; Copyright (C) 2024 Thierry Banel

;; Author: Thierry Banel tbanelwebmin at free dot fr
;; Version: 1.0
;; URL: https://github.com/tbanel/uniline

;; Uniline is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; Uniline is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

(uniline-bench
"C-c C-c i n i t i a l SPC t e x t e <backspace> <return> SPC SPC g o o d <return> <backspace> <backspace> M-x u n i l i n e - m o d e RET <up> <up> C-SPC <down> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <insert> <down> <down> <right> <right> <right> R <end> <return> <kp-subtract> <right> q <kp-subtract> <down> <left> <left> <return> <up> <up> <right> <right> <down> <kp-subtract> <up> <right> <right> <right> <up> <up> <up> <return> <down> <down> <down> <up> <up> <right> <down> <down> <down> C-SPC <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <up> <up> <up> <insert> <up> <down> <down> c <end> SPC SPC C-SPC <insert> y <return> <return> <down> <down> <down> <right> <right> <right> <right> = <down> <left> <left> <left> <left> <left> <left> <insert> s s s <left> <left> <left> <left> <left> <insert> o <left> <left> <left> <left> <left> <left> <up>"

"
Expand Down
23 changes: 21 additions & 2 deletions tests/bench3.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
(load-file "bench.el")
;;; uniline.el --- Draw lines, boxes, & arrows with the keyboard -*- coding:utf-8; lexical-binding: t; -*-

(bench
;; Copyright (C) 2024 Thierry Banel

;; Author: Thierry Banel tbanelwebmin at free dot fr
;; Version: 1.0
;; URL: https://github.com/tbanel/uniline

;; Uniline is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; Uniline is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

(uniline-bench
"<return> <down> <down> <right> <right> <right> # <right> <right> <right> <right> <right> <right> <down> <down> <down> <right> <right> <right> <right> <right> <right> <up> <up> <up> <right> <right> <right> <right> <right> <right> <down> <down> <down> <right> <right> <right> <right> <right> <right> <up> <up> <up> <up> <right> <right> <right> <down> <down> <down> <down> <down> <down> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <return> <up> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <up> C-SPC <down> <down> <down> <down> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <insert> r # R <return> <kp-subtract> <down> <down> <down> <down> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <up> <up> <up> <up> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <return> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <up> <up> C-SPC <down> <down> <down> <down> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <insert> <down> <down> <right> <right> <right> <return> C-c C-c"

"
Expand Down
24 changes: 22 additions & 2 deletions tests/bench4.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
(load-file "bench.el")
(bench
;;; uniline.el --- Draw lines, boxes, & arrows with the keyboard -*- coding:utf-8; lexical-binding: t; -*-

;; Copyright (C) 2024 Thierry Banel

;; Author: Thierry Banel tbanelwebmin at free dot fr
;; Version: 1.0
;; URL: https://github.com/tbanel/uniline

;; Uniline is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; Uniline is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

(uniline-bench
"<return> <down> <right> <right> <right> <right> <down> <down> <right> <right> <right> <right> <down> <left> M = <up> <up> <up> <right> <right> <right> <right> <right> <right> <down> <down> <down> <left> <left> <insert> a <left> <left> <left> <left> <left> <left> <left> <insert> a a a <left> <down> <down> <down> <right> <right> <right> <right> <up> <up> <up> <return> <up> <up> <right> <right> <insert> s <down> <right> <right> <insert> s s <down> <down> <down> <left> <left> <left> <left> <left> <left> <insert> x <up> <insert> o o o o o <up> <up> <up> <up> <right> <right> <right> <right> <right> <right> <right> <right> <right> C-SPC <down> <down> <down> <down> <down> <down> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <left> <insert> c <right> <return> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <right> <up> <up> <up> <up> <up> <up> C-SPC <insert> y <return>"
"
Expand Down
134 changes: 134 additions & 0 deletions tests/uniline-bench.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
;;; uniline-bench.el --- Regression tests for Uniline -*- coding:utf-8; lexical-binding: t; -*-

;; Copyright (C) 2024 Thierry Banel

;; Author: Thierry Banel tbanelwebmin at free dot fr
;; Version: 1.0
;; Package-Requires: ((emacs "29.1"))
;; URL: https://github.com/tbanel/uniline

;; Uniline is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; Uniline is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; Running regression tests
;; Just load this file:
;; (load "uniline-bench.el")
;; or
;; (eval-buffer)
;;
;; If OK, the "*uniline-summary*" summary buffer is displayed
;; If ERROR, two windows are displayed, the actual an the expected sketchs
;; with points on the first difference.

;; Creating a new bench
;; - Eval (uniline-bench-create)
;; - Draw a sketch
;; - When done, type $
;; A Lisp buffer implementing the new test is displayed
;; - Save it permanently in a file ending in *.el along with this one

;;; Code:

(defvar uniline-bench-result
nil
"Boolean where a bench result is stored.
t if the bench ran as expected.
nil if there was an error.")

(defun uniline-bench (commands result)
"Run a bench.
COMMANDS is a string describing a sequence of keyboard strokes,
supposed to draw a sketch using uniline minor-mode.
Its format is the one used to store keyboard macros.
RESULT is a string representing the expected result.
Note that RESULT begins with an empty line not part of the result,
making it more human-readable."
(setq result
(substring result (1+ (string-search "\n" result))))

(ignore-errors (kill-buffer "*uniline-interactive*"))
(switch-to-buffer "*uniline-interactive*")
(uniline-mode 1)
(eval `(,(kmacro commands)))

(setq uniline-bench-result
(string-equal
(buffer-substring (point-min) (point-max))
result))

(unless uniline-bench-result
(delete-other-windows)
(switch-to-buffer "*uniline-interactive*")
(goto-char (point-min))
(ignore-errors (kill-buffer "*uniline-expected*"))
(switch-to-buffer-other-window "*uniline-expected*")
(insert result)
(goto-char (point-min))
(compare-windows nil)))

(defun uniline-bench-create ()
"Interactively create a bench.
An empty buffer is made available, with uniline mode active.
Draw a sketch.
When done, type $.
A Lisp buffer able to automatically re-run the drawing is presented.
Save it in a *.el file along with other benches."
(interactive)
(ignore-errors (kill-buffer "*uniline-interactive*"))
(switch-to-buffer "*uniline-interactive*")
(uniline-mode)
(local-set-key "$" 'uniline-bench-collect)
(message "draw a sketch, type $ whend done")
(kmacro-start-macro nil))

(defun uniline-bench-collect ()
"Called when typing $ to close the interactive drawing.
Do not call it directly."
(interactive)
(kmacro-end-macro 1)
(ignore-errors (kill-buffer "b.el"))
(switch-to-buffer "b.el")
(insert "(uniline-bench\n\"")
(insert (key-description (kmacro--keys (kmacro last-kbd-macro))))
(insert "\"\n\"\n")
(insert-buffer-substring "*uniline-interactive*")
(insert "\")\n")
(lisp-mode))

(defun uniline-bench-run ()
"Run all benches.
The benches are all files with *.el suffix.
Stops on the first error, presenting two buffers,
- one with the actual drawing,
- the other with the expected drawing,
with points on the first difference.
If there are no errors, a summary buffer is presented."
(interactive)
(let ((buf (current-buffer)))
(cl-loop
for file in (directory-files "." nil "\.el$")
unless (equal "uniline-bench.el" file)
do
(load (format "%s%s" default-directory file) nil nil t)
while uniline-bench-result)
(if (not uniline-bench-result)
(message "at least one bench FAILED")
(switch-to-buffer buf)
(message "all benches PASSED"))))

(uniline-bench-run)

(provide 'uniline-bench)
;;; uniline-bench.el ends here

0 comments on commit 9f032cb

Please sign in to comment.