From b19b9f2ba733790b1d8194aa9f3bba04a8e1df3f Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Tue, 8 Mar 2022 12:28:45 -0600 Subject: updated examples --- README.md | 6 +++--- examples.lisp | 26 +++++++++++++++++++------- package.lisp | 6 ++++++ testiere.lisp | 18 ++++-------------- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 0b4e457..cc6a244 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ during interactive development! A work in progress. But here is the basic idea: - (defun+ fibble (x y &key (z 10)) + (defun/t fibble (x y &key (z 10)) "Hey, a docstring." :tests (= (1 2) 13) @@ -81,7 +81,7 @@ For example (defvar *count*) - (defun+ increment-count () + (defun/t increment-count () "Increments the *count* variable." :tests (:with-bindings ((*count* 4)) @@ -98,7 +98,7 @@ questions. Useful for mocking. (defun just-a-function () (print "Just a function.")) - (defun+ call-just-a-function () + (defun/t call-just-a-function () "Calls JUST-A-FUNCTION." :tests (:with-stubs ((just-a-function () (print "TEMP JUST-A-FUNCTION."))) diff --git a/examples.lisp b/examples.lisp index df3de19..9ceb234 100644 --- a/examples.lisp +++ b/examples.lisp @@ -1,17 +1,16 @@ (defpackage :testiere.examples (:use #:cl) (:import-from #:testiere - #:defun+ - #:defmethod+)) + #:defun/t)) (in-package :testiere.examples) -(defun+ fibble (x y &key (z 10)) +(defun/t fibble (x y &key (z 10)) "Hey, a docstring." :tests (= (1 2) 13) (>= (1 2 :z 1) -5) - (:outputp (0 0 :z 0) (lambda (result) (equalp result 0))) + (:outputp (0 10 :z 0) (lambda (result) (equalp result 10))) (:fails ("strings" "ain't" :z "numbers")) :end (+ x y z)) @@ -19,24 +18,37 @@ (defvar *count*) -(defun+ increment-count () +(defun/t increment-count () "Increments the *count* variable." :tests (:with-bindings ((*count* 4)) (:afterp () (lambda () (= *count* 5))) - (= () 6) + (= () 6) (:outputp () (lambda (x) (= x 7)))) :end (incf *count*)) +(defun/t other-increment-count (&optional (amount 1)) + "Also increments the *count* variable by an optional amount." + :tests + (:with-bindings ((*count* 10)) + (= () 11)) + (:with-bindings ((*count* 0)) + (= (10) 10) + (:afterp (2) (lambda () (= *count* 12)))) + :end + (incf *count* amount)) + (defun just-a-function () (print "Just a function.")) -(defun+ call-just-a-function () +(defun/t call-just-a-function () "Calls JUST-A-FUNCTION." :tests (:with-stubs ((just-a-function () (print "TEMP JUST-A-FUNCTION."))) (equal () "TEMP JUST-A-FUNCTION.")) :end (just-a-function)) + + diff --git a/package.lisp b/package.lisp index 04ecb26..9763e9b 100644 --- a/package.lisp +++ b/package.lisp @@ -6,3 +6,9 @@ (:export #:defun/t)) + + + + + + diff --git a/testiere.lisp b/testiere.lisp index 9f253a7..003647c 100644 --- a/testiere.lisp +++ b/testiere.lisp @@ -68,22 +68,12 @@ (progn ,@tests (defun ,name ,lambda-list ,@function-body)) (error (e) - (format t "~a~%Not defining ~a" e ',name)))))) + (invoke-debugger e) + ))))) + + -(defun parse-defmethod (args) - (match args - ((guard (list* qualifier lambda-list body) - (and (not (listp qualifier)) - (listp lambda-list))) - (list (list qualifier lambda-list) body)) - ((list* lambda-list body) - (list (list lambda-list) body)) - (_ (error "Malformed DEFMETHOD: ~a " args)))) -(defmacro defmethod+ (name &rest args) - "Like regular DEFMETHOD, but with embedded unit tests. If those - test would fail, the method fails to be defined. " - (ERROR "Not yet implemented")) -- cgit v1.2.3