diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3c0ceea --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: 👷 Testing + +on: + push: + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + container: + image: containers.common-lisp.net/cl-docker-images/sbcl:latest + + env: + GITHUB_ACTION: true + QUICKLISP_SETUP: /github/home/quicklisp/setup.lisp + GITHUB_WORKSPACE: + + steps: + - uses: actions/checkout@v4 + + - name: prepare quicklisp + shell: bash + run: | + install-quicklisp && \ + if [ ! -f ${{ env.QUICKLISP_SETUP }} ]; then \ + echo "Did not find Quicklisp setup file where expected: ${QUICKLISP_SETUP}"; \ + find / -name 'quicklisp' -type d ; \ + fi + + - name: test + shell: bash + run: | + ./run-tests.sh diff --git a/Dockerfile b/Dockerfile index ac0c890..f35886b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,4 +23,4 @@ COPY --from=builder /root/common-lisp/core . EXPOSE 3333 -CMD [ "sbcl", "--core", "core" ] +ENTRYPOINT [ "sbcl", "--core", "core" ] diff --git a/html2clwho.asd b/html2clwho.asd index 92774eb..661839f 100644 --- a/html2clwho.asd +++ b/html2clwho.asd @@ -4,4 +4,14 @@ :author "Alberto Lerda" :licence "Public Domain" :depends-on ("plump" "hunchentoot" "cl-who") - :components ((:file "html2clwho"))) + :components ((:file "html2clwho")) + :in-order-to ((test-op (test-op "html2clwho/tests")))) + +(asdf:defsystem "html2clwho/tests" + :depends-on ("html2clwho" "fiveam") + :components ((:file "test")) + :perform (test-op (o c) (symbol-call :html2clwho.test :run-tests))) + + +;; test-op should signal a condition +;; https://asdf.common-lisp.dev/asdf.html#test_002dop diff --git a/load-deps.lisp b/load-deps.lisp new file mode 100644 index 0000000..162bde2 --- /dev/null +++ b/load-deps.lisp @@ -0,0 +1,33 @@ +(in-package :common-lisp-user) + +(require :asdf) + +(declaim (optimize (speed 3) (space 3) (safety 3))) + +(asdf:load-system "asdf") + +(asdf:initialize-source-registry '(:source-registry (:tree :here) :inherit-configuration)) + +;;; try to find Quicklisp -- this is a mess because it isn't consistently installed in the +;;; same location. +(if (uiop:find-package* '#:ql nil) + (format t "~&Quicklisp pre-loaded into image.~%") + (let ((ql-filename (uiop:getenv "QUICKLISP_SETUP")) + loaded) + (if ql-filename + (if (probe-file ql-filename) + (let ((result (load ql-filename :if-does-not-exist nil))) + (when result + (format t "~&Have loaded quicklisp setup file ~a.~%" ql-filename) + (setf loaded t))) + (format t "Quicklisp not installed where expected: ~a~%" ql-filename))) + (unless loaded + (let* ((fallback-name "/root/quicklisp/setup.lisp") + (result (load fallback-name :if-does-not-exist nil))) + (when result + (format t "~&Have loaded quicklisp setup file from /root.~%") + (setf loaded t)))) + (unless loaded + (format t "~&Unable to find quicklisp.~%") + (uiop:quit 1 t)))) + diff --git a/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000..36eb0f4 --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +sbcl --non-interactive \ + --load 'load-deps.lisp' \ + --eval '(ql:quickload :html2clwho/tests)' \ + --eval '(asdf:load-system :html2clwho)' \ + --eval '(uiop:quit (if (html2clwho.test::run-tests) 0 1))' diff --git a/test.lisp b/test.lisp new file mode 100644 index 0000000..fe7f1ce --- /dev/null +++ b/test.lisp @@ -0,0 +1,23 @@ +(defpackage :html2clwho.test + (:use :cl :html2clwho :fiveam)) +(in-package :html2clwho.test) + +(def-suite html2clwho-suite :description "Build sexp from html") +(in-suite html2clwho-suite) + +(defun is-html (str sexp) + (is (equal (string-trim '(#\Newline) (html2clwho::build-sexp str)) sexp))) + +(def-test empty-tag () + (is-html "" "(:html)")) + +(def-test some-classes () + (is-html "
" "(:div :class \"col-md-4\")")) + +(def-test some-content () + (is-html "
Hello
" "(:div +(:span \"Hello\"))")) + +;; https://stackoverflow.com/questions/54889460/asdftest-system-from-a-makefile-doesnt-return-an-error-return-code +(defun run-tests () + (run! 'html2clwho-suite))