Switch unit testing framework to cl-unit2

This commit is contained in:
HiPhish 2022-10-01 15:51:26 +02:00
parent 903f81fb82
commit f4d8550877
7 changed files with 136 additions and 127 deletions

View file

@ -48,7 +48,7 @@
:author "HiPhish <hiphish@posteo.de>" :author "HiPhish <hiphish@posteo.de>"
:license "AGPL-3.0-or-later" :license "AGPL-3.0-or-later"
:version "0.0.0" :version "0.0.0"
:depends-on ("hssg" "fiveam") :depends-on ("hssg" "clunit2")
:serial t :serial t
:perform (test-op (o s) :perform (test-op (o s)
(symbol-call :hssg/test :test-all)) (symbol-call :hssg/test :test-all))

View file

@ -1,10 +1,28 @@
;;;; SPDX-License-Identifier AGPL-3.0-or-later
;;;; compound.lisp Compound artifact implementation
;;;; Copyright (C) 2022 Alejandro "HiPhish" Sanchez
;;;;
;;;; This file is part of CL-HSSG.
;;;;
;;;; CL-HSSG is free software: you can redistribute it and/or modify it under
;;;; the terms of the GNU Affero General Public License as published by the
;;;; Free Software Foundation, either version 3 of the License, or (at your
;;;; option) any later version.
;;;;
;;;; CL-HSSG 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 Affero General Public License for
;;;; more details.
;;;;
;;;; You should have received a copy of the GNU Affero General Public License
;;;; along with CL-HSSG If not, see <https://www.gnu.org/licenses/>.(in-package #:hssg.artifact)
(defpackage #:hssg/test/artifact/compound (defpackage #:hssg/test/artifact/compound
(:use #:cl)) (:use #:cl))
(in-package #:hssg/test/artifact/compound) (in-package #:hssg/test/artifact/compound)
(fiveam:def-suite hssg/artifact/compound ;;; "Compound artifact implementation tests")
:description "Compound artifact implementation tests") (clunit:defsuite hssg.artifact.compound (hssg/test:hssg))
(fiveam:in-suite hssg/artifact/compound)
;;; --------------------------------------------------------------------------- ;;; ---------------------------------------------------------------------------
@ -22,25 +40,29 @@
(incf (counter-count (dummy-counter dummy))) (incf (counter-count (dummy-counter dummy)))
:ok) :ok)
(clunit:deffixture hssg.artifact.compound (@body)
(let ((counter (make-counter)))
@body))
;;; ---------------------------------------------------------------------------
(fiveam:test create-and-write (clunit:deftest create-and-write (hssg.artifact.compound)
"Writing a compound artifacts writes all all of its artifacts" "Writing a compound artifacts writes all all of its artifacts"
(let ((counter (make-counter))) (let ((artifact (hssg:make-compound-artifact
(let ((artifact (hssg:make-compound-artifact (make-instance 'dummy-artifact :counter counter)
(make-instance 'dummy-artifact :counter counter) (make-instance 'dummy-artifact :counter counter)
(make-instance 'dummy-artifact :counter counter) (make-instance 'dummy-artifact :counter counter))))
(make-instance 'dummy-artifact :counter counter)))) (hssg:write-artifact artifact))
(hssg:write-artifact artifact)) (let ((count (counter-count counter)))
(fiveam:is (= 3 (counter-count counter))))) (clunit:assert-eql 3 count count)))
(fiveam:test push-artifact (clunit:deftest push-artifact (hssg.artifact.compound)
"Push a new artifact onto the list of wrapped artifacts" "Push a new artifact onto the list of wrapped artifacts"
(let ((counter (make-counter))) (let ((compound (hssg:make-compound-artifact))
(let ((compound (hssg:make-compound-artifact)) (dummy1 (make-instance 'dummy-artifact :counter counter))
(dummy1 (make-instance 'dummy-artifact :counter counter)) (dummy2 (make-instance 'dummy-artifact :counter counter)))
(dummy2 (make-instance 'dummy-artifact :counter counter))) (hssg:compound-artifact-push compound dummy1)
(hssg:compound-artifact-push compound dummy1) (hssg:compound-artifact-push compound dummy2)
(hssg:compound-artifact-push compound dummy2) (hssg:write-artifact compound))
(hssg:write-artifact compound)) (clunit:assert-eql 2 (counter-count counter)))
(fiveam:is (= 2 (counter-count counter)))))
(hssg/test:test-all)

View file

@ -20,11 +20,7 @@
(in-package #:hssg/test) (in-package #:hssg/test)
(defun test-all () (defun test-all ()
(run! 'all-tests)) (clunit:run-suite 'all-tests))
(def-suite all-tests (clunit:defsuite all-tests ())
:description "The root suite of all tests.") (clunit:defsuite hssg (all-tests))
(def-suite hssg
:description "Parent suite of tests for the HSSG core"
:in hssg/test:all-tests)

View file

@ -19,5 +19,5 @@
;;;; along with CL-HSSG If not, see <https://www.gnu.org/licenses/>.(in-package #:hssg.artifact) ;;;; along with CL-HSSG If not, see <https://www.gnu.org/licenses/>.(in-package #:hssg.artifact)
(defpackage #:hssg/test (defpackage #:hssg/test
(:documentation "Main test package") (:documentation "Main test package")
(:use #:cl #:fiveam) (:use #:cl)
(:export test-all all-tests hssg)) (:export test-all all-tests hssg))

View file

@ -26,45 +26,37 @@
(declare (ignore pathname)) (declare (ignore pathname))
'()) '())
(fiveam:def-suite hssg/reader ;; "Tests for the reader interface"
:description "Tests for the reader interface" (clunit:defsuite hssg.reader (hssg/test:hssg))
:in hssg/test:hssg)
(fiveam:in-suite hssg/reader) (clunit:deffixture hssg.reader (@body)
"Installs the dummy \"foo\" reader."
(fiveam:test retrieve-reader
"A registered reader can be retrieved by its type"
(let ((hssg.reader::*file-readers* `(("foo" . ,#'dummy-reader)))) (let ((hssg.reader::*file-readers* `(("foo" . ,#'dummy-reader))))
(fiveam:is-true (eq #'dummy-reader (hssg.reader:get-reader "foo"))))) @body))
(fiveam:test retrieve-missing-reader (clunit:deftest retrieve-reader (hssg.reader)
"A registered reader can be retrieved by its type"
(clunit:assert-true (eq #'dummy-reader (hssg.reader:get-reader "foo"))))
(clunit:deftest retrieve-missing-reader (hssg.reader)
"Retrieving a reader that has not been registered signals a condition" "Retrieving a reader that has not been registered signals a condition"
(let ((hssg.reader::*file-readers* '())) (clunit:assert-condition error
(fiveam:signals (error) (hssg.reader:get-reader "bar")))
(hssg.reader:get-reader "foo"))))
(fiveam:test add-reader (clunit:deftest add-reader (hssg.reader)
"A new reader can be added by file type" "A new reader can be added by file type"
(let ((original hssg.reader::*file-readers*)) (hssg.reader:register-reader "bar" #'dummy-reader)
(unwind-protect (let ((reader (hssg.reader:get-reader "bar")))
(progn (clunit:assert-eq #'dummy-reader reader reader)))
(hssg.reader:register-reader "foo" #'dummy-reader)
(fiveam:is-true (eq #'dummy-reader (hssg.reader:get-reader "foo"))))
(setf hssg.reader::*file-readers* original))))
(fiveam:test remove-reader (clunit:deftest remove-reader (hssg.reader)
"An added reader can be removed" "An added reader can be removed"
(let ((original hssg.reader::*file-readers*)) (hssg.reader:register-reader "bar" #'dummy-reader)
(unwind-protect (hssg.reader:unregister-reader "bar")
(progn (clunit:assert-condition error (hssg.reader:get-reader "bar")))
(hssg.reader:register-reader "foo" #'dummy-reader)
(hssg.reader:unregister-reader "foo")
(fiveam:is-true (equal original hssg.reader::*file-readers*)))
(setf hssg.reader::*file-readers* original))))
(fiveam:test temporary-reader (clunit:deftest temporary-reader (hssg.reader)
"Register a reader for the duration of the body expressions only" "Register a reader for the duration of the body expressions only"
(hssg.reader:with-readers (("foo" #'dummy-reader)) (hssg.reader:with-readers (("bar" #'dummy-reader))
(fiveam:is-true (eq #'dummy-reader (hssg.reader:get-reader "foo")))) (clunit:assert-eq #'dummy-reader (hssg.reader:get-reader "bar")))
(fiveam:signals (error) (clunit:assert-condition error (hssg.reader:get-reader "bar")))
(hssg.reader:get-reader "foo")))

View file

@ -21,29 +21,29 @@
(:use #:cl)) (:use #:cl))
(in-package #:hssg/test/reader/lisp) (in-package #:hssg/test/reader/lisp)
(fiveam:def-suite hssg/reader/lisp ;; "Tests for the Lisp reader"
:description "Tests for the Lisp reader" (clunit:defsuite hssg.reader.lisp (hssg/test:hssg))
:in hssg/test:hssg)
(fiveam:in-suite hssg/reader/lisp) (clunit:deffixture hssg.reader.lisp (@body)
(let ((reader (hssg.reader:get-reader "lisp")))
@body))
(fiveam:test lisp-reader-is-registered (clunit:deftest lisp-reader-is-registered (hssg.reader.lisp)
"The Lisp reader is registered by default" "The Lisp reader is registered by default"
(fiveam:is-true (eq (hssg.reader:get-reader "lisp") #'hssg.reader.lisp::read-lisp-metadata))) (clunit:assert-eq #'hssg.reader.lisp::read-lisp-metadata reader reader))
(fiveam:test lisp-reader-can-read-files (clunit:deftest lisp-reader-can-read-files (hssg.reader.lisp)
"The Lisp reader can read the contents of a Lisp file" "The Lisp reader can read the contents of a Lisp file"
(let* ((reader (hssg.reader:get-reader "lisp")) (let ((data (funcall reader "test/hssg/sample-files/metadata.lisp")))
(data (funcall reader "test/hssg/sample-files/metadata.lisp")))
(hssg:let-metadata data ((foo :foo) (hssg:let-metadata data ((foo :foo)
(bar :bar) (bar :bar)
(baz :baz)) (baz :baz))
(fiveam:is-true (string-equal "foo" foo)) (let ((clunit:*clunit-equality-test* #'string-equal))
(fiveam:is-true (string-equal "bar" bar)) (clunit:assert-equality* "foo" foo foo)
(fiveam:is-true (string-equal "baz" baz))))) (clunit:assert-equality* "bar" bar bar)
(clunit:assert-equality* "baz" baz baz)))))
(fiveam:test lisp-reader-does-not-pollute (clunit:deftest lisp-reader-does-not-pollute (hssg.reader.lisp)
"The Lisp reader does not leak symbols from the file" "The Lisp reader does not leak symbols from the file"
(let* ((reader (hssg.reader:get-reader "lisp"))) (funcall reader "test/hssg/sample-files/metadata.lisp")
(funcall reader "test/hssg/sample-files/metadata.lisp") (clunit:assert-false (find-symbol "THROWAWAY-FUNCTION")))
(fiveam:is-true (null (find-symbol "THROWAWAY-FUNCTION")))))

View file

@ -17,58 +17,59 @@
;;;; ;;;;
;;;; You should have received a copy of the GNU Affero General Public License ;;;; You should have received a copy of the GNU Affero General Public License
;;;; along with CL-HSSG If not, see <https://www.gnu.org/licenses/>.(in-package #:hssg.artifact) ;;;; along with CL-HSSG If not, see <https://www.gnu.org/licenses/>.(in-package #:hssg.artifact)
(in-package #:hssg/test) (defpackage #:hssg/test.template
(:use :cl))
(in-package #:hssg/test.template)
(def-suite hssg/template ;; "Tests for the HTML template engine"
:description "Tests for the HTML template engine" (clunit:defsuite hssg.template (hssg/test:hssg))
:in hssg)
(in-suite hssg/template) (clunit:deffixture hssg.template (@body)
"Default dummy data to operate on"
(let ((foo-data '((:foo . "foo")))
(foo-bar-data '((:foo . "foo")
(:bar . "bar"))))
@body))
(test let-metadata-form
(clunit:deftest let-metadata-form (hssg.template)
"The LET-METADATA form can bind data from an association list" "The LET-METADATA form can bind data from an association list"
(let ((data '((:foo . "foo") (:bar . "bar")))) (hssg:let-metadata foo-bar-data ((foo :foo)
(hssg:let-metadata data ((foo :foo) (bar :bar)
(bar :bar) (baz :baz)
(baz :baz) (qux :qux "qux"))
(qux :qux "qux")) (clunit:assert-equal "foo" foo foo)
(is-every equal (clunit:assert-equal "bar" bar bar)
(foo "foo") (clunit:assert-equal nil baz baz)
(bar "bar") (clunit:assert-equal "qux" qux qux)))
(baz nil)
(qux "qux")))))
(test identity-template-unchanged (clunit:deftest identity-template-unchanged (hssg.template)
"The identity template returns its input unchanged" "The identity template returns its input unchanged"
(let* ((data '((:foo . "foo") (:bar . "bar"))) (let ((out (hssg:apply-template 'hssg:identity-template foo-bar-data)))
(out (hssg:apply-template 'hssg:identity-template data))) (clunit:assert-equal foo-bar-data out out)))
(is-true (equal data out))))
(test identity-template-eq (clunit:deftest identity-template-eq (hssg.template)
"Applying the identity template does not produce a new object" "Applying the identity template does not produce a new object"
(let* ((data '((:foo . "foo") (:bar . "bar"))) (let ((out (hssg:apply-template 'hssg:identity-template foo-bar-data)))
(out (hssg:apply-template 'hssg:identity-template data))) (clunit:assert-eq foo-bar-data out out)))
(is-true (eq data out))))
(test anonymous-template (clunit:deftest anonymous-template (hssg.template)
"Defines an anonous template" "Defines an anonous template"
(let* ((data '((:foo . "foo") (:bar . "bar"))) (let* ((template (hssg:template (foo)
(template (hssg:template (foo)
(:foo (string-upcase foo)) (:foo (string-upcase foo))
(:baz "baz"))) (:baz "baz")))
(out (hssg:apply-template template data))) (out (hssg:apply-template template foo-bar-data)))
(hssg:let-metadata out ((foo :foo) (hssg:let-metadata out ((foo :foo)
(bar :bar) (bar :bar)
(baz :baz)) (baz :baz))
(is-every string-equal (let ((clunit:*clunit-equality-test* #'string-equal))
(foo "FOO") (clunit:assert-equality* "FOO" foo foo)
(bar "bar") (clunit:assert-equality* "bar" bar bar)
(baz "baz"))))) (clunit:assert-equality* "baz" baz baz)))))
(test template-chaining (clunit:deftest template-chaining (hssg.template)
"Chaining two templates produces a new template" "Chaining two templates produces a new template"
(let* ((data '((:foo . "foo"))) (let* ((t1 (hssg:template ()
(t1 (hssg:template ()
(:bar "bar"))) (:bar "bar")))
(t2 (hssg:template (foo) (t2 (hssg:template (foo)
(:foo (string-upcase foo)) (:foo (string-upcase foo))
@ -76,26 +77,24 @@
(t3 (hssg:template (bar) (t3 (hssg:template (bar)
(:bar (string-upcase bar)))) (:bar (string-upcase bar))))
(template (hssg:chain-templates t1 t2 t3)) (template (hssg:chain-templates t1 t2 t3))
(out (hssg:apply-template template data))) (out (hssg:apply-template template foo-data)))
(hssg:let-metadata out ((foo :foo) (hssg:let-metadata out ((foo :foo)
(bar :bar) (bar :bar)
(baz :baz)) (baz :baz))
(is-every string-equal (let ((clunit:*clunit-equality-test* #'string-equal))
(foo "FOO") (clunit:assert-equality* "FOO" foo foo)
(bar "BAR") (clunit:assert-equality* "bar" bar bar)
(baz "baz"))))) (clunit:assert-equality* "baz" baz baz)))))
(clunit:deftest initial-data (hssg.template)
(test initial-data
"Providing a tamplate with initial data produces a new template" "Providing a tamplate with initial data produces a new template"
(let* ((data '((:foo . "foo"))) (let* ((template (hssg:template-with-data (hssg:template () (:baz "baz"))
(template (hssg:template-with-data (hssg:template () (:baz "baz"))
'((:bar . "bar")))) '((:bar . "bar"))))
(out (hssg:apply-template template data))) (out (hssg:apply-template template foo-data)))
(hssg:let-metadata out ((foo :foo) (hssg:let-metadata out ((foo :foo)
(bar :bar) (bar :bar)
(baz :baz)) (baz :baz))
(is-every string-equal (let ((clunit:*clunit-equality-test* #'string-equal))
(foo "foo") (clunit:assert-equality* "foo" foo foo)
(bar "bar") (clunit:assert-equality* "bar" bar bar)
(baz "baz"))))) (clunit:assert-equality* "baz" baz baz)))))