Skip to content

Commit

Permalink
feat(tests): initial setup for tests
Browse files Browse the repository at this point in the history
This is an initial version of automated tests for Homestead, which will
be very useful as the project is getting more complex and it’s hard to
keep track of everything manually.

I don’t fully understand how everything works yet, but it’s now running
on CI in Github Actions. I got a lot of inspiration from this repo:
renatoathaydes/lisp-site-gen.

Also today, in Moscow, Alexei Navalny was buried. He was only 47 years
old. It feels like such a tragic mistake that he is now dead, and the
person who killed him is still president. I watched the live stream of
the religious service and the burial, and it was extremely emotional to
see how many people showed up, despite the risk. How many people changed
“No to war”. How many more people could not be there. There’s a lot of
us, and that makes me feel warm.
  • Loading branch information
goshatch committed Mar 2, 2024
1 parent 3bffce2 commit d386b9c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### Adapted from: https://github.com/neil-lindquist/CI-Utils/blob/master/config-examples/.github/workflows/ci.yml
name: CI

# Github Actions allows for running jobs on a wide variety of events
on:
push: # Commits pushed to Github
pull_request: # Pull request is update
workflow_dispatch: # Manually dispatched from Github's UI

jobs:
test:
name: "sbcl on ubuntu"
runs-on: ubuntu-latest

env:
LISP: sbcl-bin
steps:
- uses: actions/checkout@v2
- uses: 40ants/setup-lisp@v4
with:
asdf-system: homestead
- uses: 40ants/run-tests@v2
with:
asdf-system: homestead
12 changes: 11 additions & 1 deletion homestead.asd
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,14 @@
(:file "templates" :depends-on ("util"))
(:file "node" :depends-on ("templates"))
(:file "main" :depends-on ("util" "node")))))
:description "A static website generator")
:description "A static website generator"
:in-order-to ((test-op (test-op "homestead-tests"))))

(defsystem "homestead-tests"
:depends-on (#:homestead #:fiveam)
:serial t
:components ((:module "tests"
:components ((:file "all")
(:file "test-util" :depends-on ("all")))))
:perform (test-op (o c)
(symbol-call :homestead/tests :run-all!)))
13 changes: 13 additions & 0 deletions tests/all.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(defpackage homestead/tests
(:use :cl :fiveam)
(:export :all-tests))

(in-package :homestead/tests)

(def-suite all-tests :description "Top-level test suite for all tests.")

(defun run-all! ()
(let ((ok (run! 'all-tests)))
(if ok
(format t "✅ All tests passed")
(error "❌ At least one suite failed"))))
20 changes: 20 additions & 0 deletions tests/test-util.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(defpackage homestead/tests/util
(:use :cl :fiveam)
(:export :util-test-suite :|util-test-suite|))

(in-package :homestead/tests/util)

(def-suite
util-test-suite
:description "Util test suite"
:in homestead/tests:all-tests)
(in-suite util-test-suite)

(test join
(let ((list '("a" "b")))
(is (string= (homestead/util:join list) "a, b"))
(is (string= (homestead/util:join list " | ") "a | b"))))

(test slurp
(let ((missing-file "/tmp/bob.txt"))
(is (equal '() (homestead/util:slurp missing-file)))))

0 comments on commit d386b9c

Please sign in to comment.