diff --git a/hssg.asd b/hssg.asd index f84c11d..b55eb8f 100644 --- a/hssg.asd +++ b/hssg.asd @@ -48,7 +48,7 @@ :author "HiPhish " :license "AGPL-3.0-or-later" :version "0.0.0" - :depends-on ("hssg" "fiveam") + :depends-on ("hssg" "clunit2") :serial t :perform (test-op (o s) (symbol-call :hssg/test :test-all)) diff --git a/test/hssg/artifacts/compound.lisp b/test/hssg/artifacts/compound.lisp index 17e0aba..48ca8ae 100644 --- a/test/hssg/artifacts/compound.lisp +++ b/test/hssg/artifacts/compound.lisp @@ -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 .(in-package #:hssg.artifact) (defpackage #:hssg/test/artifact/compound (:use #:cl)) (in-package #:hssg/test/artifact/compound) -(fiveam:def-suite hssg/artifact/compound - :description "Compound artifact implementation tests") -(fiveam:in-suite hssg/artifact/compound) +;;; "Compound artifact implementation tests") +(clunit:defsuite hssg.artifact.compound (hssg/test:hssg)) ;;; --------------------------------------------------------------------------- @@ -22,25 +40,29 @@ (incf (counter-count (dummy-counter dummy))) :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" - (let ((counter (make-counter))) - (let ((artifact (hssg:make-compound-artifact - (make-instance 'dummy-artifact :counter counter) - (make-instance 'dummy-artifact :counter counter) - (make-instance 'dummy-artifact :counter counter)))) - (hssg:write-artifact artifact)) - (fiveam:is (= 3 (counter-count counter))))) + (let ((artifact (hssg:make-compound-artifact + (make-instance 'dummy-artifact :counter counter) + (make-instance 'dummy-artifact :counter counter) + (make-instance 'dummy-artifact :counter counter)))) + (hssg:write-artifact artifact)) + (let ((count (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" - (let ((counter (make-counter))) - (let ((compound (hssg:make-compound-artifact)) - (dummy1 (make-instance 'dummy-artifact :counter counter)) - (dummy2 (make-instance 'dummy-artifact :counter counter))) - (hssg:compound-artifact-push compound dummy1) - (hssg:compound-artifact-push compound dummy2) - (hssg:write-artifact compound)) - (fiveam:is (= 2 (counter-count counter))))) + (let ((compound (hssg:make-compound-artifact)) + (dummy1 (make-instance 'dummy-artifact :counter counter)) + (dummy2 (make-instance 'dummy-artifact :counter counter))) + (hssg:compound-artifact-push compound dummy1) + (hssg:compound-artifact-push compound dummy2) + (hssg:write-artifact compound)) + (clunit:assert-eql 2 (counter-count counter))) + +(hssg/test:test-all) diff --git a/test/hssg/main.lisp b/test/hssg/main.lisp index 2c2941c..deca352 100644 --- a/test/hssg/main.lisp +++ b/test/hssg/main.lisp @@ -20,11 +20,7 @@ (in-package #:hssg/test) (defun test-all () - (run! 'all-tests)) + (clunit:run-suite 'all-tests)) -(def-suite all-tests - :description "The root suite of all tests.") - -(def-suite hssg - :description "Parent suite of tests for the HSSG core" - :in hssg/test:all-tests) +(clunit:defsuite all-tests ()) +(clunit:defsuite hssg (all-tests)) diff --git a/test/hssg/package.lisp b/test/hssg/package.lisp index 8bf24c6..a0944d4 100644 --- a/test/hssg/package.lisp +++ b/test/hssg/package.lisp @@ -19,5 +19,5 @@ ;;;; along with CL-HSSG If not, see .(in-package #:hssg.artifact) (defpackage #:hssg/test (:documentation "Main test package") - (:use #:cl #:fiveam) + (:use #:cl) (:export test-all all-tests hssg)) diff --git a/test/hssg/reader.lisp b/test/hssg/reader.lisp index f3a4513..53b1fb7 100644 --- a/test/hssg/reader.lisp +++ b/test/hssg/reader.lisp @@ -26,45 +26,37 @@ (declare (ignore pathname)) '()) -(fiveam:def-suite hssg/reader - :description "Tests for the reader interface" - :in hssg/test:hssg) +;; "Tests for the reader interface" +(clunit:defsuite hssg.reader (hssg/test:hssg)) -(fiveam:in-suite hssg/reader) - -(fiveam:test retrieve-reader - "A registered reader can be retrieved by its type" +(clunit:deffixture hssg.reader (@body) + "Installs the dummy \"foo\" 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" - (let ((hssg.reader::*file-readers* '())) - (fiveam:signals (error) - (hssg.reader:get-reader "foo")))) + (clunit:assert-condition error + (hssg.reader:get-reader "bar"))) -(fiveam:test add-reader +(clunit:deftest add-reader (hssg.reader) "A new reader can be added by file type" - (let ((original hssg.reader::*file-readers*)) - (unwind-protect - (progn - (hssg.reader:register-reader "foo" #'dummy-reader) - (fiveam:is-true (eq #'dummy-reader (hssg.reader:get-reader "foo")))) - (setf hssg.reader::*file-readers* original)))) + (hssg.reader:register-reader "bar" #'dummy-reader) + (let ((reader (hssg.reader:get-reader "bar"))) + (clunit:assert-eq #'dummy-reader reader reader))) -(fiveam:test remove-reader +(clunit:deftest remove-reader (hssg.reader) "An added reader can be removed" - (let ((original hssg.reader::*file-readers*)) - (unwind-protect - (progn - (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)))) + (hssg.reader:register-reader "bar" #'dummy-reader) + (hssg.reader:unregister-reader "bar") + (clunit:assert-condition error (hssg.reader:get-reader "bar"))) -(fiveam:test temporary-reader +(clunit:deftest temporary-reader (hssg.reader) "Register a reader for the duration of the body expressions only" - (hssg.reader:with-readers (("foo" #'dummy-reader)) - (fiveam:is-true (eq #'dummy-reader (hssg.reader:get-reader "foo")))) - (fiveam:signals (error) - (hssg.reader:get-reader "foo"))) + (hssg.reader:with-readers (("bar" #'dummy-reader)) + (clunit:assert-eq #'dummy-reader (hssg.reader:get-reader "bar"))) + (clunit:assert-condition error (hssg.reader:get-reader "bar"))) diff --git a/test/hssg/readers/lisp.lisp b/test/hssg/readers/lisp.lisp index 1129494..63f47a0 100644 --- a/test/hssg/readers/lisp.lisp +++ b/test/hssg/readers/lisp.lisp @@ -21,29 +21,29 @@ (:use #:cl)) (in-package #:hssg/test/reader/lisp) -(fiveam:def-suite hssg/reader/lisp - :description "Tests for the Lisp reader" - :in hssg/test:hssg) +;; "Tests for the Lisp reader" +(clunit:defsuite hssg.reader.lisp (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" - (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" - (let* ((reader (hssg.reader:get-reader "lisp")) - (data (funcall reader "test/hssg/sample-files/metadata.lisp"))) + (let ((data (funcall reader "test/hssg/sample-files/metadata.lisp"))) (hssg:let-metadata data ((foo :foo) (bar :bar) (baz :baz)) - (fiveam:is-true (string-equal "foo" foo)) - (fiveam:is-true (string-equal "bar" bar)) - (fiveam:is-true (string-equal "baz" baz))))) + (let ((clunit:*clunit-equality-test* #'string-equal)) + (clunit:assert-equality* "foo" foo foo) + (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" - (let* ((reader (hssg.reader:get-reader "lisp"))) - (funcall reader "test/hssg/sample-files/metadata.lisp") - (fiveam:is-true (null (find-symbol "THROWAWAY-FUNCTION"))))) + (funcall reader "test/hssg/sample-files/metadata.lisp") + (clunit:assert-false (find-symbol "THROWAWAY-FUNCTION"))) diff --git a/test/hssg/template.lisp b/test/hssg/template.lisp index 066024d..12f829a 100644 --- a/test/hssg/template.lisp +++ b/test/hssg/template.lisp @@ -17,58 +17,59 @@ ;;;; ;;;; You should have received a copy of the GNU Affero General Public License ;;;; along with CL-HSSG If not, see .(in-package #:hssg.artifact) -(in-package #:hssg/test) +(defpackage #:hssg/test.template + (:use :cl)) +(in-package #:hssg/test.template) -(def-suite hssg/template - :description "Tests for the HTML template engine" - :in hssg) +;; "Tests for the HTML template engine" +(clunit:defsuite hssg.template (hssg/test: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" - (let ((data '((:foo . "foo") (:bar . "bar")))) - (hssg:let-metadata data ((foo :foo) - (bar :bar) - (baz :baz) - (qux :qux "qux")) - (is-every equal - (foo "foo") - (bar "bar") - (baz nil) - (qux "qux"))))) + (hssg:let-metadata foo-bar-data ((foo :foo) + (bar :bar) + (baz :baz) + (qux :qux "qux")) + (clunit:assert-equal "foo" foo foo) + (clunit:assert-equal "bar" bar bar) + (clunit:assert-equal nil baz baz) + (clunit:assert-equal "qux" qux qux))) -(test identity-template-unchanged +(clunit:deftest identity-template-unchanged (hssg.template) "The identity template returns its input unchanged" - (let* ((data '((:foo . "foo") (:bar . "bar"))) - (out (hssg:apply-template 'hssg:identity-template data))) - (is-true (equal data out)))) + (let ((out (hssg:apply-template 'hssg:identity-template foo-bar-data))) + (clunit:assert-equal foo-bar-data out out))) -(test identity-template-eq +(clunit:deftest identity-template-eq (hssg.template) "Applying the identity template does not produce a new object" - (let* ((data '((:foo . "foo") (:bar . "bar"))) - (out (hssg:apply-template 'hssg:identity-template data))) - (is-true (eq data out)))) + (let ((out (hssg:apply-template 'hssg:identity-template foo-bar-data))) + (clunit:assert-eq foo-bar-data out out))) -(test anonymous-template +(clunit:deftest anonymous-template (hssg.template) "Defines an anonous template" - (let* ((data '((:foo . "foo") (:bar . "bar"))) - (template (hssg:template (foo) + (let* ((template (hssg:template (foo) (:foo (string-upcase foo)) (:baz "baz"))) - (out (hssg:apply-template template data))) + (out (hssg:apply-template template foo-bar-data))) (hssg:let-metadata out ((foo :foo) (bar :bar) (baz :baz)) - (is-every string-equal - (foo "FOO") - (bar "bar") - (baz "baz"))))) + (let ((clunit:*clunit-equality-test* #'string-equal)) + (clunit:assert-equality* "FOO" foo foo) + (clunit:assert-equality* "bar" bar bar) + (clunit:assert-equality* "baz" baz baz))))) -(test template-chaining +(clunit:deftest template-chaining (hssg.template) "Chaining two templates produces a new template" - (let* ((data '((:foo . "foo"))) - (t1 (hssg:template () + (let* ((t1 (hssg:template () (:bar "bar"))) (t2 (hssg:template (foo) (:foo (string-upcase foo)) @@ -76,26 +77,24 @@ (t3 (hssg:template (bar) (:bar (string-upcase bar)))) (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) (bar :bar) (baz :baz)) - (is-every string-equal - (foo "FOO") - (bar "BAR") - (baz "baz"))))) + (let ((clunit:*clunit-equality-test* #'string-equal)) + (clunit:assert-equality* "FOO" foo foo) + (clunit:assert-equality* "bar" bar bar) + (clunit:assert-equality* "baz" baz baz))))) - -(test initial-data +(clunit:deftest initial-data (hssg.template) "Providing a tamplate with initial data produces a new template" - (let* ((data '((:foo . "foo"))) - (template (hssg:template-with-data (hssg:template () (:baz "baz")) + (let* ((template (hssg:template-with-data (hssg:template () (:baz "baz")) '((:bar . "bar")))) - (out (hssg:apply-template template data))) + (out (hssg:apply-template template foo-data))) (hssg:let-metadata out ((foo :foo) (bar :bar) (baz :baz)) - (is-every string-equal - (foo "foo") - (bar "bar") - (baz "baz"))))) + (let ((clunit:*clunit-equality-test* #'string-equal)) + (clunit:assert-equality* "foo" foo foo) + (clunit:assert-equality* "bar" bar bar) + (clunit:assert-equality* "baz" baz baz)))))