-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
c
committed
Oct 7, 2024
1 parent
6ba523f
commit 9f032cb
Showing
6 changed files
with
219 additions
and
80 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |