Skip to content

Commit

Permalink
Close #43: Fix tests and run in GitHub action
Browse files Browse the repository at this point in the history
* README.md: updated for GitHub Actions badge
* .github/workflows/build-and-test.yml: Added workflow
* hunchensocket-tests.asd: Extracted from main .asd file to appease ASDF
* hunchensocket-tests.lisp: Fix test for binary messages without temp files
* hunchensocket.asd: Extracted test system
* run-tests.lisp: Test run script for CI
  • Loading branch information
hanshuebner committed Oct 17, 2024
1 parent 9f80124 commit dcc0b38
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 36 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'Build and Test'
on:
- workflow_dispatch
- push

jobs:
install-quicklisp:
strategy:
matrix:
implementation: ['sbcl']
os: ['ubuntu-latest', 'macos-latest']
runs-on: '${{ matrix.os }}'
name: 'Install Common Lisp'
steps:
- uses: actions/checkout@v3
- name: 'Install MacPorts'
if: runner.os == 'macOS'
uses: melusina-org/setup-macports@v1

- uses: melusina-org/setup-common-lisp@v1
with:
implementation: '${{ matrix.implementation }}'

- uses: melusina-org/setup-quicklisp@v1
id: 'quicklisp'
with:
implementation: '${{ matrix.implementation }}'

- name: 'Validate installed implementation'
run: |
test -d '${{ steps.quicklisp.outputs.quicklisp-home }}'
test -d '${{ steps.quicklisp.outputs.quicklisp-local-projects }}'
- name: 'Run tests'
run: |
sbcl --load run-tests.lisp
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Build Status](https://travis-ci.org/joaotavora/hunchensocket.svg?branch=master)](https://travis-ci.org/joaotavora/hunchensocket)
![build and test](https://github.com/joaotavora/hunchensocket/actions/workflows/build-and-test.yml/badge.svg)

Hunchensocket - WebSockets for Hunchentoot
==========================================

Expand Down
9 changes: 9 additions & 0 deletions hunchensocket-tests.asd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(asdf:defsystem :hunchensocket-tests
:description "Tests for Hunchensocket"
:version #.(with-open-file (f "VERSION") (string (read f)))
:depends-on (:fiasco
:hunchensocket)
:serial t
:components
((:file "hunchensocket-tests")))

29 changes: 4 additions & 25 deletions hunchensocket-tests.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,13 @@
(push message received-messages))))

(defmethod binary-message-received ((resource mock-resource)
(client mock-client) file)
(client mock-client) data)
(is *expected-files*
"Didn't expect a binary file at all but got one")
(when *expected-files*
(let ((file-contents
(with-open-file (fstream file :direction :input
:element-type '(unsigned-byte 8))
(let ((seq (make-array (file-length fstream)
:element-type '(unsigned-byte 8)
:fill-pointer t)))
(setf (fill-pointer seq) (read-sequence seq fstream))
seq))))
(is (equalp (pop *expected-files*) file-contents))
(with-slots (received-files) client
(push file-contents received-files)))))
(is (equalp (pop *expected-files*) data))
(with-slots (received-files) client
(push data received-files))))

(defmacro with-resource-and-client ((res-sym client-sym)
(mock-input mock-output) &body body)
Expand Down Expand Up @@ -221,16 +213,3 @@
(let ((*max-total-size* 2048)
(*max-fragment-size* 128))
(test-fragmented-binaries #x02 #x00 #x00 #x80)))))













10 changes: 0 additions & 10 deletions hunchensocket.asd
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,3 @@
((:file "package")
(:file "hunchensocket")))

(asdf:defsystem :hunchensocket-tests
:description "Tests for Hunchensocket"
:version #.(with-open-file (f "VERSION") (string (read f)))
:depends-on (:fiasco
:hunchensocket)
:serial t
:components
((:file "hunchensocket-tests")))


10 changes: 10 additions & 0 deletions run-tests.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;; -*- Lisp -*-

(ql:quickload :hunchensocket-tests)
(handler-case
(unless (fiasco:run-package-tests :package :hunchensocket-tests)
(error "test(s) failed"))
(error (e)
(format t ";; ~A~%" e)
(sb-ext:exit :code 1)))
(sb-ext:exit :code 0)

0 comments on commit dcc0b38

Please sign in to comment.