Add reader tests
This commit is contained in:
parent
21626840cd
commit
8523d63f6c
8 changed files with 156 additions and 6 deletions
19
TODO.rst
19
TODO.rst
|
@ -12,16 +12,15 @@ Cleanup
|
||||||
=======
|
=======
|
||||||
|
|
||||||
- A proper public interface to the various artifact classes
|
- A proper public interface to the various artifact classes
|
||||||
|
- Expose reader interface to public
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
=======
|
=======
|
||||||
|
|
||||||
- Reader
|
|
||||||
- Test the reader system in general
|
|
||||||
- Test the Lisp reader implementation
|
|
||||||
- Artifacts
|
- Artifacts
|
||||||
- Come up with a proper artifacts interface
|
- Come up with a proper artifacts interface
|
||||||
- Test the individual artifact implementations (function `WRITE-ARTIFACT`)
|
- Test the individual artifact implementations (function `WRITE-ARTIFACT`)
|
||||||
|
- Update reader tests to public interface once it is done
|
||||||
|
|
||||||
|
|
||||||
Blog
|
Blog
|
||||||
|
@ -46,3 +45,17 @@ Cleanup
|
||||||
- How much of each artifact's internals need to be exposed? Make accessor
|
- How much of each artifact's internals need to be exposed? Make accessor
|
||||||
functions? Constructor functions over `MAKE-INSTANCE`?
|
functions? Constructor functions over `MAKE-INSTANCE`?
|
||||||
- Static page metadata without binding (see comment in definition)
|
- Static page metadata without binding (see comment in definition)
|
||||||
|
|
||||||
|
Testing
|
||||||
|
=======
|
||||||
|
|
||||||
|
Everything
|
||||||
|
|
||||||
|
|
||||||
|
CommonMark reader
|
||||||
|
#################
|
||||||
|
|
||||||
|
Testing
|
||||||
|
=======
|
||||||
|
|
||||||
|
Everything
|
||||||
|
|
5
hssg.asd
5
hssg.asd
|
@ -56,4 +56,7 @@
|
||||||
:components ((:module "hssg"
|
:components ((:module "hssg"
|
||||||
:components ((:file "package")
|
:components ((:file "package")
|
||||||
(:file "main")
|
(:file "main")
|
||||||
(:file "template")))))))
|
(:file "template")
|
||||||
|
(:file "reader")
|
||||||
|
(:module "readers"
|
||||||
|
:components ((:file "lisp")))))))))
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
(defpackage #:hssg.reader
|
(defpackage #:hssg.reader
|
||||||
(:documentation "Interface to the various content readers.")
|
(:documentation "Interface to the various content readers.")
|
||||||
(:use :cl)
|
(:use :cl)
|
||||||
(:export get-reader register-reader with-readers))
|
(:export get-reader register-reader unregister-reader with-readers))
|
||||||
|
|
||||||
(defpackage #:hssg.artifact
|
(defpackage #:hssg.artifact
|
||||||
(:documentation "Helper package, defines the artifact protocl.")
|
(:documentation "Helper package, defines the artifact protocl.")
|
||||||
|
|
|
@ -37,6 +37,14 @@
|
||||||
(declare (type string type))
|
(declare (type string type))
|
||||||
(push (cons type reader) *file-readers*))
|
(push (cons type reader) *file-readers*))
|
||||||
|
|
||||||
|
(defun unregister-reader (type)
|
||||||
|
(declare (type string type))
|
||||||
|
(flet ((matches-type-p (entry)
|
||||||
|
(string-equal type (car entry))))
|
||||||
|
(setf *file-readers*
|
||||||
|
(remove-if #'matches-type-p
|
||||||
|
*file-readers*))))
|
||||||
|
|
||||||
(defmacro with-readers ((&rest reader-spec) &body body)
|
(defmacro with-readers ((&rest reader-spec) &body body)
|
||||||
"Evaluate the BODY expressions with temporarily registered readers. Each
|
"Evaluate the BODY expressions with temporarily registered readers. Each
|
||||||
reader specification is a list of to elements of the form (TYPE READER). The
|
reader specification is a list of to elements of the form (TYPE READER). The
|
||||||
|
|
|
@ -20,4 +20,4 @@
|
||||||
(defpackage #:hssg/test
|
(defpackage #:hssg/test
|
||||||
(:documentation "Main test package")
|
(:documentation "Main test package")
|
||||||
(:use #:cl #:fiveam)
|
(:use #:cl #:fiveam)
|
||||||
(:export test-all all-tests))
|
(:export test-all all-tests hssg))
|
||||||
|
|
70
test/hssg/reader.lisp
Normal file
70
test/hssg/reader.lisp
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
;;;; 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/reader
|
||||||
|
(:use #:cl))
|
||||||
|
(in-package #:hssg/test/reader)
|
||||||
|
|
||||||
|
(defun dummy-reader (pathname)
|
||||||
|
"A dummy reader which does nothing useful."
|
||||||
|
(declare (ignore pathname))
|
||||||
|
'())
|
||||||
|
|
||||||
|
(fiveam:def-suite hssg/reader
|
||||||
|
:description "Tests for the reader interface"
|
||||||
|
:in hssg/test:hssg)
|
||||||
|
|
||||||
|
(fiveam:in-suite hssg/reader)
|
||||||
|
|
||||||
|
(fiveam:test retrieve-reader
|
||||||
|
"A registered reader can be retrieved by its type"
|
||||||
|
(let ((hssg.reader::*file-readers* `(("foo" . ,#'dummy-reader))))
|
||||||
|
(fiveam:is-true (eq #'dummy-reader (hssg.reader:get-reader "foo")))))
|
||||||
|
|
||||||
|
(fiveam:test retrieve-missing-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"))))
|
||||||
|
|
||||||
|
(fiveam:test add-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))))
|
||||||
|
|
||||||
|
(fiveam:test remove-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))))
|
||||||
|
|
||||||
|
(fiveam:test temporary-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")))
|
49
test/hssg/readers/lisp.lisp
Normal file
49
test/hssg/readers/lisp.lisp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
;;;; 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/reader/lisp
|
||||||
|
(:use #:cl))
|
||||||
|
(in-package #:hssg/test/reader/lisp)
|
||||||
|
|
||||||
|
(fiveam:def-suite hssg/reader/lisp
|
||||||
|
:description "Tests for the Lisp reader"
|
||||||
|
:in hssg/test:hssg)
|
||||||
|
|
||||||
|
(fiveam:in-suite hssg/reader/lisp)
|
||||||
|
|
||||||
|
(fiveam:test lisp-reader-is-registered
|
||||||
|
"The Lisp reader is registered by default"
|
||||||
|
(fiveam:is-true (eq (hssg.reader:get-reader "lisp") #'hssg.reader.lisp::read-lisp-metadata)))
|
||||||
|
|
||||||
|
(fiveam:test lisp-reader-can-read-files
|
||||||
|
"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")))
|
||||||
|
(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)))))
|
||||||
|
|
||||||
|
(fiveam:test lisp-reader-does-not-pollute
|
||||||
|
"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")))))
|
7
test/hssg/sample-files/metadata.lisp
Normal file
7
test/hssg/sample-files/metadata.lisp
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
(defun throwaway-function ()
|
||||||
|
"This function must not leak out of this file"
|
||||||
|
"foo")
|
||||||
|
|
||||||
|
`((:foo . ,(throwaway-function))
|
||||||
|
(:bar . "bar")
|
||||||
|
(:baz . "baz"))
|
Loading…
Add table
Reference in a new issue