Skip to content

Commit

Permalink
feat: test, even on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
albertolerda committed Oct 25, 2023
1 parent b99cb37 commit 03eb789
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 2 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ COPY --from=builder /root/common-lisp/core .

EXPOSE 3333

CMD [ "sbcl", "--core", "core" ]
ENTRYPOINT [ "sbcl", "--core", "core" ]
12 changes: 11 additions & 1 deletion html2clwho.asd
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 33 additions & 0 deletions load-deps.lisp
Original file line number Diff line number Diff line change
@@ -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))))

7 changes: 7 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -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))'
23 changes: 23 additions & 0 deletions test.lisp
Original file line number Diff line number Diff line change
@@ -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></html>" "(:html)"))

(def-test some-classes ()
(is-html "<div class=\"col-md-4\"></div>" "(:div :class \"col-md-4\")"))

(def-test some-content ()
(is-html "<div><span>Hello</span></div>" "(: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))

0 comments on commit 03eb789

Please sign in to comment.