diff --git a/tests/bench.el b/tests/bench.el deleted file mode 100644 index b81204e..0000000 --- a/tests/bench.el +++ /dev/null @@ -1,72 +0,0 @@ -(defun bench (commands result) - (setq result - (substring result (1+ (string-search "\n" result)))) - - (eval - `(defalias 'bench-function (kmacro ,commands))) - - (delete-file "/tmp/ttt.txt") - (ignore-errors (kill-buffer "ttt.txt")) - (find-file "/tmp/ttt.txt") - - (uniline-mode 1) - (bench-function) - - (goto-char (point-min)) - (save-buffer) - - (delete-file "/tmp/ttt1.txt") - (ignore-errors (kill-buffer "ttt1.txt")) - (find-file-other-window "/tmp/ttt1.txt") - (insert result) - - (goto-char (point-min)) - (save-buffer) - - (compare-windows nil) - - (if (string-equal - (with-current-buffer "ttt.txt" - (buffer-substring (point-min) (point-max))) - (with-current-buffer "ttt1.txt" - (buffer-substring (point-min) (point-max)))) - (message "test PASSED") - (message "test FAILED")) - ) - - -(defun bench-create () - (interactive) - (delete-file "/tmp/ttt.txt") - (ignore-errors (kill-buffer "ttt.txt")) - (find-file "/tmp/ttt.txt") - - (uniline-mode) - - (local-set-key "$" 'bench-collect) - - (kmacro-start-macro nil)) - -(defun bench-collect () - (interactive) - - (kmacro-end-macro 1) - (save-buffer) - - (ignore-errors (kill-buffer "b.el")) - (find-file "b.el") - - (insert "(load-file \"bench.el\")\n") - - (insert "(bench\n\"") - - (insert (key-description (kmacro--keys (kmacro last-kbd-macro)))) - - (insert "\"\n\"\n") - - (insert - (with-current-buffer "ttt.txt" - (buffer-substring (point-min) (point-max)))) - - (insert "\")\n") - ) diff --git a/tests/bench1.el b/tests/bench1.el index e667b28..6aa39a9 100644 --- a/tests/bench1.el +++ b/tests/bench1.el @@ -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 . + +(uniline-bench "a b RET c - C-SPC RET RET + a a a S- RET - " " diff --git a/tests/bench2.el b/tests/bench2.el index 2b7be2d..d53aea3 100644 --- a/tests/bench2.el +++ b/tests/bench2.el @@ -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 . + +(uniline-bench "C-c C-c i n i t i a l SPC t e x t e SPC SPC g o o d M-x u n i l i n e - m o d e RET C-SPC R q C-SPC c SPC SPC C-SPC y = s s s o " " diff --git a/tests/bench3.el b/tests/bench3.el index 49b696a..c674de7 100644 --- a/tests/bench3.el +++ b/tests/bench3.el @@ -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 . + +(uniline-bench " # C-SPC r # R C-SPC C-c C-c" " diff --git a/tests/bench4.el b/tests/bench4.el index 0694a91..07c0029 100644 --- a/tests/bench4.el +++ b/tests/bench4.el @@ -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 . + +(uniline-bench " M = a a a a s s s x o o o o o C-SPC c C-SPC y " " diff --git a/tests/uniline-bench.el b/tests/uniline-bench.el new file mode 100644 index 0000000..c492e61 --- /dev/null +++ b/tests/uniline-bench.el @@ -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 . + +;;; 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