Skip to content

Commit

Permalink
Added license, improved docs, added development section to README
Browse files Browse the repository at this point in the history
  • Loading branch information
cddr committed May 1, 2013
1 parent aaacf69 commit 22dd28a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ccl.*
*.gz
docs/
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SCL ?= scl
CCL ?= ccl

TEST_SCRIPT = "run-tests.lisp"
GENDOCS = "generate-docs.lisp"

clean:
@$(MAKE) -wC tests clean
Expand Down Expand Up @@ -38,4 +39,11 @@ test-allegro:
test-ccl:
@-$(CCL) --no-init --load $(TEST_SCRIPT)

docs-sbcl:
@-$(SBCL) --noinform --load $(GENDOCS)

docs-ccl:
mkdir -p docs && @-$(CCL) --no-init --load $(GENDOCS)


test: test-openmcl test-sbcl test-cmucl test-clisp
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ A simple set of macros for mocking time

The respective clocks can be nested arbitrarily inside one-another.

## Development

Development of delorean is hosted on github at https://github.com/cddr/delorean.

To my knowledge, there is currently 1 user (i.e. me) so I'm just hacking directly
on master. If you start to find it useful, let me know and we can formalize the
release process a little but I don't foresee lots of changes. It's a pretty simple
solution to a small problem.

Check out the Makefile for the details of how to build and test the software. It's
shamelessly copied from cffi (Luís Oliveira is awesome). It also includes a target
to build documentation using atdoc (David Lichteblau is also awesome).

## Bugs?

What bugs? No really, if you find a bug, let me know by raising a github issue.
25 changes: 25 additions & 0 deletions delorean.asd
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
;; Copyright (c) 2013 Andy Chambers
;; All rights reserved.

;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are
;; met:

;; o Redistributions of source code must retain the above copyright notice,
;; this list of conditions and the following disclaimer.

;; o Redistributions in binary form must reproduce the above copyright
;; notice, this list of conditions and the following disclaimer in the
;; documentation and/or other materials provided with the distribution.

;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
;; HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

(defsystem :delorean
:description "Delorean is a time machine for unit tests"
Expand Down
13 changes: 9 additions & 4 deletions delorean.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
(:export
:with-frozen-clock
:with-shifted-clock
:with-scaled-clock)
:with-scaled-clock
:frozen-clock :shifted-clock :scaled-clock)
(:documentation "A set of macros loosely based on travisjeffery's timecop
library with the purpose of making it easier to test time-sensitive code"))

Expand All @@ -24,7 +25,7 @@

(defclass frozen-clock (mock-clock)
((frozen-time :initarg :frozen-time :accessor frozen-time))
(:documentation "Arranges for (now) to return `frozen-time' in perpetuity"))
(:documentation "A clock which allows time to be frozen in perpetuity"))

(defmethod local-time:clock-now ((self frozen-clock))
(frozen-time self))
Expand All @@ -40,7 +41,8 @@ Within body (and any code called by body), calling (now) will always return `tim


(defclass shifted-clock (mock-clock)
((shifted-time :initarg :shifted-time :accessor shifted-time)))
((shifted-time :initarg :shifted-time :accessor shifted-time))
(:documentation "A clock which allows time to be shifted to the specified time"))

(defmethod local-time:clock-now ((self shifted-clock))
(local-time:universal-to-timestamp
Expand All @@ -49,14 +51,16 @@ Within body (and any code called by body), calling (now) will always return `tim
(local-time:timestamp-to-universal (created-at self))))))

(defmacro with-shifted-clock (to &body body)
"Teleports to the time indicated by `to' before executing `body'"
`(let* ((local-time:*clock*
(make-instance 'shifted-clock
:shifted-time ,to)))
,@body))


(defclass scaled-clock (mock-clock)
((scale :initarg :scale :accessor scale)))
((scale :initarg :scale :accessor scale))
(:documentation "A clock which allows time to proceed faster or slower than normal"))

(defmethod local-time:clock-now ((self scaled-clock))
(local-time:universal-to-timestamp
Expand All @@ -66,6 +70,7 @@ Within body (and any code called by body), calling (now) will always return `tim
(local-time:timestamp-to-universal (created-at self)))))))

(defmacro with-scaled-clock (scale &body body)
"Accelerates (or decelarates) time by a factor indicated by `scale'"
`(let ((local-time:*clock*
(make-instance 'scaled-clock :scale ,scale)))
,@body))
Expand Down
23 changes: 23 additions & 0 deletions generate-docs.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

(format t "~&;;; -------------- Generating delorean docs -------------------~%")

(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname))))
(if (probe-file "~/quicklisp/")
(load quicklisp-init)
(progn
(load "quicklisp.lisp")
(funcall (intern (format nil "~a" 'install)
:quicklisp-quickstart)))))

(ql:quickload :delorean)
(ql:quickload :atdoc)

(atdoc:generate-html-documentation
'(:delorean)
(merge-pathnames #p"docs/" *load-truename*)
:index-title "Delorean -- API Reference"
:heading "Delorean -- A time machine for lisp unit tests"
:single-page-p t
:include-internal-symbols-p nil)

(quit)

0 comments on commit 22dd28a

Please sign in to comment.