From 7749529aeb06eae7c56136e1a5fab0865d934200 Mon Sep 17 00:00:00 2001 From: Alberto Lerda Date: Wed, 25 Oct 2023 21:35:53 +0100 Subject: [PATCH] feat: test, even on CI --- .github/workflows/ci.yml | 33 +++++++++++++++++++++++++++++++++ Dockerfile | 2 +- html2clwho.asd | 12 +++++++++++- run-tests.sh | 6 ++++++ test.lisp | 23 +++++++++++++++++++++++ 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100755 run-tests.sh create mode 100644 test.lisp 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/run-tests.sh b/run-tests.sh new file mode 100755 index 0000000..31771f3 --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +sbcl --non-interactive \ + --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))