cl-scopes/test/test-csys.lisp

70 lines
2.4 KiB
Common Lisp

;;;; cl-scopes/test-csys - testing for the scopes-csys system.
(defpackage :scopes/test-csys
(:use :common-lisp)
(:local-nicknames (:alx :alexandria)
(:actor :scopes/core/actor)
(:async :scopes/util/async)
(:config :scopes/config)
(:core :scopes/core)
(:csys :scopes/csys)
(:logging :scopes/logging)
(:message :scopes/core/message)
(:shape :scopes/shape)
(:util :scopes/util)
(:t :scopes/testing)
(:tc :scopes/test-core))
(:export #:run)
(:import-from :scopes/testing #:deftest #:== #:!= #:in-seq))
(in-package :scopes/test-csys)
;;;; testing environment
(defclass test-env (csys:environment)
((test-suite :reader test-suite :initarg :test-suite)))
(defun setup-config ()
(config:add :test-receiver :setup #'tc:setup)
(config:add-action '(:csys :sub) #'tc:check-message)
(config:add-action '(:csys) (constantly nil))
)
(defun eff-proc (msg state syns env)
(let ((t:*test-suite* (test-suite env)))
(destructuring-bind (nmsg nst nsyns)
(csys:handle-action msg state syns env)
(util:lgi nmsg)
(actor:send (core:mailbox (tc:receiver t:*test-suite*)) nmsg))))
;;;; test runner
(defun run ()
(async:init)
(let* ((t:*test-suite* (make-instance 'tc:test-suite :name "csys"))
(csys:*environment* (make-instance 'test-env :test-suite t:*test-suite*)))
(load (t:test-path "config-csys" "etc"))
(setup-config)
(core:setup-services)
(unwind-protect
(let ((rcvr (core:find-service :test-receiver)))
(setf (tc:receiver t:*test-suite*) rcvr)
(test-init rcvr))
(sleep 0.1)
(core:shutdown)
(tc:check-expected)
(t:show-result))))
(deftest test-init (rcvr)
(setf (gethash '(:effect :default) (csys:procs csys:*environment*)) #'eff-proc)
;(csys:make-eff-proc (eff-handler '(1 3 4 5))))
(csys:init)
(csys:send-message '(:csys :sensor :init :zero) '(:std :s1))
(csys:send-message '(:csys :sensor :init :zero) '(:std :s2))
(sleep 0.1)
(csys:send-message '(:csys :add :std :s1) 1)
(csys:send-message '(:csys :add :std :s1) 3)
(tc:expect rcvr (message:create '(:csys :sub :std :s2) :data 4))
(csys:send-message '(:csys :sub :std :s2) 4)
(csys:send-message '(:csys :add :std :s2) 5)
)