From 99586247decdfe852f92dc223268ef43c7652464 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sat, 7 Sep 2024 16:35:43 +0200 Subject: [PATCH] testing improvements; start with util/iter --- lib/auth/test/etc/config.lisp | 2 +- lib/auth/test/test-auth.lisp | 2 +- lib/auth/web.lisp | 3 ++- scopes-core.asd | 1 + test/test-core.lisp | 15 ++++++++++++--- testing.lisp | 21 ++++++++++----------- util/iter.lisp | 9 +++++++++ 7 files changed, 36 insertions(+), 17 deletions(-) create mode 100644 util/iter.lisp diff --git a/lib/auth/test/etc/config.lisp b/lib/auth/test/etc/config.lisp index 64bfc0d..6e7b587 100644 --- a/lib/auth/test/etc/config.lisp +++ b/lib/auth/test/etc/config.lisp @@ -11,7 +11,7 @@ :env-path (t:test-path ".test.env")) (config:add :logger :class 'logging:config - :loglevel :info + :loglevel :debug :logfile (t:test-path "scopes-test.log" "log") :console nil) diff --git a/lib/auth/test/test-auth.lisp b/lib/auth/test/test-auth.lisp index 3a8e339..d8a0606 100644 --- a/lib/auth/test/test-auth.lisp +++ b/lib/auth/test/test-auth.lisp @@ -46,5 +46,5 @@ (deftest test-client (client) (let ((msg (message:create '(:auth :login) - :data '(:name "admin" :password "sc0pes")))) + :data '(:org "system" :name "admin" :password "sc0pes")))) (client:send-message client msg))) diff --git a/lib/auth/web.lisp b/lib/auth/web.lisp index c147495..2d837db 100644 --- a/lib/auth/web.lisp +++ b/lib/auth/web.lisp @@ -4,7 +4,8 @@ (:use :common-lisp) (:local-nicknames (:auth :scopes-auth) (:config :scopes/config) - (:core :scopes/core)) + (:core :scopes/core) + (:util :scopes/util)) (:export #:login)) (in-package :scopes-auth/web) diff --git a/scopes-core.asd b/scopes-core.asd index ddaf993..dfd518b 100644 --- a/scopes-core.asd +++ b/scopes-core.asd @@ -18,6 +18,7 @@ (:file "shape/shape") (:file "util/util") (:file "util/crypt" :depends-on ("util/util")) + (:file "util/iter") (:file "testing" :depends-on ("util/util"))) :long-description "scopes/core: The core packages of the scopes project." :in-order-to ((test-op (test-op "scopes-core/test")))) diff --git a/test/test-core.lisp b/test/test-core.lisp index b0e550c..0337a1f 100644 --- a/test/test-core.lisp +++ b/test/test-core.lisp @@ -6,6 +6,7 @@ (:config :scopes/config) (:core :scopes/core) (:crypt :scopes/util/crypt) + (:iter :scopes/util/iter) (:logging :scopes/logging) (:message :scopes/core/message) (:shape :scopes/shape) @@ -55,7 +56,9 @@ (unwind-protect (progn (test-util) - (test-record) + (test-util-crypt) + (test-util-iter) + (test-shape) (core:setup-services) (setf (receiver t:*test-suite*) (core:find-service :test-receiver)) (test-send)) @@ -64,7 +67,6 @@ (t:show-result)))) (deftest test-util () - (util:lgi (crypt:create-secret)) (let ((now (get-universal-time))) (== (util:from-unix-time (util:to-unix-time now)) now)) (let* ((x (util:ptr)) @@ -80,7 +82,14 @@ (== (util:plist-add pl :b 1) '(:b 1 :a 0)) (== pl '(:b 1 :a 0)))) -(deftest test-record () +(deftest test-util-crypt () + (util:lgi (crypt:create-secret)) + ) + +(deftest test-util-iter () + ) + +(deftest test-shape() (let ((rec (make-instance 'shape:record :head '(:t1)))) (== (shape:head rec) '(:t1 nil)) (== (shape:head-value rec :taskid) :t1) diff --git a/testing.lisp b/testing.lisp index 24a6346..6500e7b 100644 --- a/testing.lisp +++ b/testing.lisp @@ -6,7 +6,7 @@ (:use :common-lisp) (:export #:*test-suite* #:test-suite #:deftest #:show-result - #:failure #:test #:== #:has-prefix + #:failure #:check #:test #:== #:has-prefix #:test-path #:*current-system*)) (in-package :scopes/testing) @@ -35,19 +35,18 @@ (defun failure (fmt &rest vals) (push (apply #'format nil fmt vals) (errors *test-suite*))) -(defun == (have wanted) - (let ((suite *test-suite*) - (is-ok (equalp have wanted))) - (push is-ok (car (result suite))) +(defun check (fn fmt have wanted) + (let ((is-ok (funcall fn have wanted))) + (push is-ok (car (result *test-suite*))) (unless is-ok - (failure "~s!=~s" have wanted)))) + (failure fmt have wanted)))) + +(defun == (have wanted) + (check #'equalp "~s!=~s" have wanted)) (defun has-prefix (have wanted) - (let ((suite *test-suite*) - (is-ok (string= (str:prefix (list have wanted)) wanted))) - (push is-ok (car (result suite))) - (unless is-ok - (failure "~s has not prefix ~s" have wanted)))) + (check #'(lambda (h w) (string= (str:prefix (list h w)) w)) + "~s has not prefix ~s" have wanted)) (defmacro deftest (name args &body body) `(defun ,name ,args diff --git a/util/iter.lisp b/util/iter.lisp new file mode 100644 index 0000000..b09f3cc --- /dev/null +++ b/util/iter.lisp @@ -0,0 +1,9 @@ +;;;; cl-scopes/util/iter + +;;;; iterators, queues, and other sequentially accessible stuff +;;;; producing items (objects) like: numbers, strings, symbols, lists, ... + +(defpackage :scopes/util/iter + (:use :common-lisp)) + +(in-package :scopes/util/iter)