Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Zach Beane
zacl
Commits
93f66aaf
Commit
93f66aaf
authored
Dec 12, 2016
by
Zach Beane
Browse files
Add some initial tests.
parent
0e9a5755
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests.lisp
0 → 100644
View file @
93f66aaf
;;;; tests.lisp
(
defpackage
#:zacl-tests
(
:use
#:cl
#:fiveam
)
(
:import-from
#:usocket
#:socket-listen
#:get-local-port
#:socket-close
)
(
:import-from
#:net.aserve
#:publish
#:with-http-response
#:with-http-body
#:*html-stream*
)
(
:export
#:run-tests
))
(
in-package
#:zacl-tests
)
(
defun
guesstimate-free-port
()
(
let*
((
socket
(
socket-listen
"localhost"
0
))
(
port
(
get-local-port
socket
)))
(
socket-close
socket
)
port
))
(
defvar
*test-port*
nil
)
(
defvar
*test-host*
"localhost"
)
(
defvar
*test-server*
nil
)
(
defun
make-test-url
(
path
)
(
format
nil
"http://~A:~A~A"
*test-host*
*test-port*
path
))
(
defun
call-with-wserver
(
fun
)
(
let*
((
*test-port*
(
guesstimate-free-port
))
(
*test-server*
(
net.aserve:start
:port
*test-port*
:host
*test-host*
)))
(
unwind-protect
(
funcall
fun
*test-server*
)
(
net.aserve:shutdown
:server
*test-server*
))))
(
defmacro
with-wserver
((
server
)
&body
body
)
`
(
call-with-wserver
(
lambda
(
,
server
)
,@
body
)))
(
def-suite
zacl-tests
)
(
in-suite
zacl-tests
)
(
test
make-a-process
(
let
((
process
(
mp:make-process
:name
"bob"
)))
(
is
(
equalp
"bob"
(
mp:process-name
process
)))
(
mp:process-kill
process
)))
(
test
utf8-enabled
(
is
(
=
(
length
"€"
)
1
)))
(
test
utf8-encoding
(
with-wserver
(
server
)
(
let
((
test-string
"Hey €¥© Now"
))
(
publish
:server
server
:path
"/utf8"
:function
#'
(
lambda
(
req
ent
)
(
with-http-response
(
req
ent
:content-type
"text/html; charset=utf-8"
)
(
with-http-body
(
req
ent
:external-format
:utf-8
)
(
format
*html-stream*
test-string
)))))
(
is
(
string=
test-string
(
net.aserve.client:do-http-request
(
make-test-url
"/utf8"
)
:external-format
:utf-8
))))))
(
test
buffer-output
(
is
(
equalp
#(
42
)
(
excl:with-output-to-buffer
(
s
)
(
write-byte
42
s
)))))
zacl-tests.asd
0 → 100644
View file @
93f66aaf
;;;; zacl-tests.asd
(
asdf:defsystem
#:zacl-tests
:serial
t
:depends-on
(
#:zacl
#:fiveam
#:aserve
)
:components
((
:file
"tests"
)))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment