From efe8c84a7cfcfa69a6a7dd696268c5c550a80324 Mon Sep 17 00:00:00 2001 From: Morgan Smith Date: Mon, 4 Dec 2023 09:42:12 -0500 Subject: [PATCH 4/5] test: Make consistant use of test framework --- Makefile.am | 1 - test/advice.scm | 18 +++----- test/block.scm | 17 ++------ test/buffer.scm | 10 +---- test/command.scm | 18 +++----- test/core.scm | 11 +---- test/coroutine.scm | 8 +++- test/emacsy.scm | 100 -------------------------------------------- test/event.scm | 21 +++------- test/help.scm | 4 +- test/job.scm | 7 ++-- test/kbd-macro.scm | 17 +++----- test/keymap.scm | 18 +++----- test/klecl.scm | 14 ++----- test/minibuffer.scm | 17 +++----- test/mru-stack.scm | 7 +++- test/self-doc.scm | 2 + test/text.scm | 12 +----- test/window.scm | 17 +++----- test/windows.scm | 16 ++----- 20 files changed, 71 insertions(+), 264 deletions(-) delete mode 100644 test/emacsy.scm diff --git a/Makefile.am b/Makefile.am index 1d3345d..9ad42ba 100644 --- a/Makefile.am +++ b/Makefile.am @@ -89,7 +89,6 @@ TESTS = \ test/command.scm \ test/core.scm \ test/coroutine.scm \ - test/emacsy.scm \ test/event.scm \ test/help.scm \ test/job.scm \ diff --git a/test/advice.scm b/test/advice.scm index d4282a0..6ca5afc 100644 --- a/test/advice.scm +++ b/test/advice.scm @@ -19,20 +19,15 @@ ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -(use-modules (emacsy advice) +(use-modules (check) + (emacsy advice) (emacsy event) (emacsy klecl) (oop goops) (srfi srfi-11)) -(eval-when (compile load eval) - ;; Some trickery so we can test private procedures. - (module-use! (current-module) (resolve-module '(emacsy advice)))) +(use-private-modules (emacsy advice)) -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) ;;; To test this functionality, we're going to make some counter ;;; procedures. ;;; @@ -96,10 +91,7 @@ (define advised-func (make-advising-function advice)) (check (my-orig-func 1) => 2) (check (advised-func 1) => 1) + ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) diff --git a/test/block.scm b/test/block.scm index b4ca8fb..61f9c63 100644 --- a/test/block.scm +++ b/test/block.scm @@ -21,17 +21,12 @@ ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -(use-modules (emacsy block) +(use-modules (check) + (emacsy block) (oop goops)) -(eval-when (compile load eval) - ;; Some trickery so we can test private procedures. - (module-use! (current-module) (resolve-module '(emacsy block)))) +(use-private-modules (emacsy block)) -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) ;;; % -*- mode: Noweb; noweb-code-mode: scheme-mode -*- ;;; @section Block Module ;;; @@ -164,9 +159,5 @@ (check (length blocking-continuations) => 0)) ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) diff --git a/test/buffer.scm b/test/buffer.scm index 54e7f40..a823e27 100644 --- a/test/buffer.scm +++ b/test/buffer.scm @@ -28,10 +28,6 @@ (use-private-modules (emacsy buffer)) -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) ;;; = (define b (make #:name "*test-buffer*")) (check (buffer-name b) => "*test-buffer*") @@ -54,9 +50,5 @@ (check (current-buffer) => a) ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) diff --git a/test/command.scm b/test/command.scm index dcd4743..4f9fc51 100644 --- a/test/command.scm +++ b/test/command.scm @@ -21,18 +21,13 @@ ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -(use-modules (emacsy command) +(use-modules (check) + (emacsy command) (emacsy event) (oop goops)) -(eval-when (compile load eval) - ;; Some trickery so we can test private procedures. - (module-use! (current-module) (resolve-module '(emacsy command)))) +(use-private-modules (emacsy command)) -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) ;;; = (define test-cmd (lambda-cmd args 1)) (define (test-cmd-2) 2) @@ -69,10 +64,7 @@ (check-throw (command-execute 'foo) => 'misc-error) (check (command-execute foo) => 'non-interactive) (check (call-interactively foo) => 'interactive) + ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) diff --git a/test/core.scm b/test/core.scm index 6d78fd3..fa94aa0 100644 --- a/test/core.scm +++ b/test/core.scm @@ -31,10 +31,6 @@ (use-private-modules (emacsy core)) (set! emacsy-interactive? #t) -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) ;;; = (set! emacsy-interactive? #f) (check (eval-expression '(+ 1 2)) => 3) @@ -85,10 +81,7 @@ (update-agenda) (check-true mouse-event) ;(block-tick) + ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) diff --git a/test/coroutine.scm b/test/coroutine.scm index 9cb80ee..4fd2e5d 100644 --- a/test/coroutine.scm +++ b/test/coroutine.scm @@ -17,8 +17,8 @@ ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -(use-modules (emacsy coroutine) - (check)) +(use-modules (check) + (emacsy coroutine)) (define a (make-coroutine (lambda () @@ -32,3 +32,7 @@ 'a-user-data)) (check (a) => 'a-user-data) + +;;; <+ Test Postscript>= +(check-report) +(check-exit) diff --git a/test/emacsy.scm b/test/emacsy.scm deleted file mode 100644 index 399bdfa..0000000 --- a/test/emacsy.scm +++ /dev/null @@ -1,100 +0,0 @@ -;;; = -;;; @subsection Legal Stuff -;;; -;;; Emacsy --- An embeddable Emacs-like library using GNU Guile -;;; -;;; Copyright (C) 2012, 2013 Shane Celis -;;; -;;; This file is part of Emacsy. -;;; -;;; Emacsy 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. -;;; -;;; Emacsy 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 Emacsy. If not, see . -;;; Finally, let's provide this as our testing preamble. -;;; -;;; -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) - -;;; = -(define unit-tests '()) - -(define (register-test name func) - (set! unit-tests (acons name func unit-tests))) - -;;; The function register-test does the work, but we don't want to require -;;; the user to call it, so we'll define a macro that will automatically -;;; call it. -;;; -;;; -;;; = -(define-syntax define-test - (syntax-rules () - ((define-test (name args ...) expr ...) - (begin (define* (name args ...) - expr ...) - (register-test 'name name))))) -;;; Finally, now we just need a way to run all the unit tests. -;;; -;;; -;;; = -(define test-errors '()) -(define (run-tests) - (catch 'first-error - (lambda () (for-each (lambda (elt) - (display "TEST: ") - (pretty-print elt) - (catch #t - (lambda () - (with-throw-handler #t - (lambda () - (apply (cdr elt) '())) - (lambda args - (set! test-errors (cons (car elt) test-errors)) - (format #t "Error in test ~a: ~a" (car elt) args) - - (backtrace)))) - (lambda args - ;(throw 'first-error) - #f - ))) - (reverse unit-tests))) - (lambda args - #f))) -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) -(eval-when (compile load eval) - (module-use! (current-module) (resolve-module '(emacsy)))) - - -;;; Let's run these tests at the end. -;;; -;;; -;;; <+ Test Postscript>= - -(run-tests) -(check-report) -(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) - -;;; <+ Test Postscript>= -;(run-tests) -(check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) diff --git a/test/event.scm b/test/event.scm index 668a87d..55139e5 100644 --- a/test/event.scm +++ b/test/event.scm @@ -21,18 +21,12 @@ ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -(use-modules (emacsy event) - (oop goops) - ) +(use-modules (check) + (emacsy event) + (oop goops)) -(eval-when (compile load eval) - ;; Some trickery so we can test private procedures. - (module-use! (current-module) (resolve-module '(emacsy event)))) +(use-private-modules (emacsy event)) -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) ;;; = (check-true (make #:command-char #\a)) ;;; = @@ -70,10 +64,7 @@ ;;; = (check (kbd "mouse-1") => '("mouse-1")) (check (kbd "S-S-mouse-1") => '("S-mouse-1")) + ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) diff --git a/test/help.scm b/test/help.scm index b74a56f..3e67adb 100644 --- a/test/help.scm +++ b/test/help.scm @@ -23,6 +23,6 @@ (emacsy help)) (use-private-modules (emacsy help)) - - +;;; <+ Test Postscript>= +(check-report) (check-exit) diff --git a/test/job.scm b/test/job.scm index ab6d5f1..9f6d206 100644 --- a/test/job.scm +++ b/test/job.scm @@ -17,11 +17,11 @@ ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -(use-modules (emacsy coroutine) +(use-modules (check) + (emacsy coroutine) (emacsy agenda) (emacsy job) - (ice-9 receive) - (check)) + (ice-9 receive)) (use-private-modules (emacsy job)) @@ -116,5 +116,6 @@ (check (format #f "~a" (car *current-job-list*)) => "#") +;;; <+ Test Postscript>= (check-report) (check-exit) diff --git a/test/kbd-macro.scm b/test/kbd-macro.scm index 49b787f..066b6fb 100644 --- a/test/kbd-macro.scm +++ b/test/kbd-macro.scm @@ -21,21 +21,17 @@ ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -(use-modules (emacsy kbd-macro) +(use-modules (check) + (emacsy kbd-macro) (emacsy event) (emacsy command) (emacsy klecl) - (oop goops) - (check)) + (oop goops)) (use-private-modules (emacsy kbd-macro)) (set! emacsy-interactive? #t) -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) ;;; Let's set up a command to test our functionality with. ;;; ;;; @@ -64,10 +60,7 @@ (execute-temporal-kbd-macro last-kbd-macro) (primitive-command-loop (lambda args #f)) (check test-command-called => 3) + ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) diff --git a/test/keymap.scm b/test/keymap.scm index 83e9fb7..88b396f 100644 --- a/test/keymap.scm +++ b/test/keymap.scm @@ -21,18 +21,13 @@ ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -(use-modules (emacsy keymap) +(use-modules (check) + (emacsy keymap) (emacsy event) (oop goops)) -(eval-when (compile load eval) - ;; Some trickery so we can test private procedures. - (module-use! (current-module) (resolve-module '(emacsy keymap)))) +(use-private-modules (emacsy keymap)) -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) ;;; = (check-true (make )) ;;; The core functionality of the keymap is being able to define and look @@ -87,10 +82,7 @@ ;;; = (check-true (keymap? (make ))) (check-false (keymap? 1)) + ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) diff --git a/test/klecl.scm b/test/klecl.scm index 765fa5f..01e6885 100644 --- a/test/klecl.scm +++ b/test/klecl.scm @@ -21,17 +21,14 @@ ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -(use-modules (emacsy klecl) +(use-modules (check) + (emacsy klecl) (emacsy event) (check) (oop goops)) (use-private-modules (emacsy klecl)) -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) ;;; = (define last-event #f) (codefine (test-read-event) @@ -127,10 +124,7 @@ (update-agenda) ;(with-blockable (primitive-command-tick)) (check my-command-count => 1) + ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) diff --git a/test/minibuffer.scm b/test/minibuffer.scm index ed53c9f..5906388 100644 --- a/test/minibuffer.scm +++ b/test/minibuffer.scm @@ -21,21 +21,17 @@ ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -(use-modules (emacsy minibuffer) +(use-modules (check) + (emacsy minibuffer) (emacsy event) (emacsy klecl) - (oop goops) - (check)) + (oop goops)) (use-private-modules (emacsy minibuffer)) (set! emacsy-interactive? #t) (set! aux-buffer minibuffer) -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) ;;; = (check (buffer-string) => "") (check (point) => 1) @@ -225,10 +221,7 @@ (cursor-right! h) (cursor-right! h) (check (cursor-list->list h) => '("3" "2" "a"))) + ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -;;(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) diff --git a/test/mru-stack.scm b/test/mru-stack.scm index fac9b04..d7a5f6e 100644 --- a/test/mru-stack.scm +++ b/test/mru-stack.scm @@ -19,8 +19,8 @@ ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -(use-modules (emacsy mru-stack) - (check)) +(use-modules (check) + (emacsy mru-stack)) (use-private-modules (emacsy mru-stack)) ;;; = @@ -63,4 +63,7 @@ (mru-remove! ms 'b) (mru-remove! ms 'c) (check (mru-list ms) => '())) + +;;; <+ Test Postscript>= +(check-report) (check-exit) diff --git a/test/self-doc.scm b/test/self-doc.scm index 04d7881..384b356 100644 --- a/test/self-doc.scm +++ b/test/self-doc.scm @@ -103,4 +103,6 @@ (check (source-properties 'x) => '()) (check (source-properties (module-variable (current-module) 'x)) => '()) +;;; <+ Test Postscript>= +(check-report) (check-exit) diff --git a/test/text.scm b/test/text.scm index 53be242..2d16eea 100644 --- a/test/text.scm +++ b/test/text.scm @@ -30,11 +30,6 @@ (use-private-modules (emacsy buffer)) (use-private-modules (emacsy text)) -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) - ;;; Let's test this regex search in a gap buffer. ;;; ;;; = @@ -70,10 +65,7 @@ ;; is ^ ^ ;; goto ^ ;; was ^ + ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) diff --git a/test/window.scm b/test/window.scm index ff65dac..1b4a23d 100644 --- a/test/window.scm +++ b/test/window.scm @@ -19,14 +19,11 @@ ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) +(use-modules (check) + (emacsy window)) + +(use-private-modules (emacsy window)) -(use-modules (emacsy window)) -(eval-when (compile load eval) - (module-use! (current-module) (resolve-module '(emacsy window)))) ;;; = (check (window? root-window) => #t) ;;; = @@ -82,9 +79,5 @@ ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) diff --git a/test/windows.scm b/test/windows.scm index b313547..09054bf 100644 --- a/test/windows.scm +++ b/test/windows.scm @@ -19,16 +19,10 @@ ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with Emacsy. If not, see . -;;; <+ Test Preamble>= -(use-modules (check)) -(use-modules (ice-9 pretty-print)) -(define test-errors '()) - -(use-modules (emacsy windows)) +(use-modules (check) + (emacsy windows)) (use-private-modules (emacsy windows)) -;; (eval-when (compile load eval) -;; (module-use! (current-module) (resolve-module '(emacsy windows)))) ;;; = (check (window? root-window) => #t) ;;; = @@ -111,9 +105,5 @@ (check (window-unproject window #(1. 1. 1.)) => #(1. 1. 1.)) ;;; <+ Test Postscript>= -;(run-tests) (check-report) -'(if (> (length test-errors) 0) - (format #t "~a ERROR in tests: ~a." (length test-errors) (reverse test-errors)) - (format #t "NO ERRORs in tests.")) -(exit (if (and (= (length test-errors) 0) (= 0 (length check:failed))) 0 1)) +(check-exit) -- 2.41.0