From 381a23bb7ab8dd206bcd430ce9c7ee9c53e52f13 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Mon, 4 Aug 2003 17:04:50 +0000 Subject: [PATCH] r5454: *** empty log message *** --- example.lisp | 40 ++++++++++++++---------------------- package.lisp | 13 ++++++------ printer.lisp | 37 +++------------------------------ suite.lisp | 4 ++-- test-case.lisp => tcase.lisp | 14 ++++++------- tests.lisp | 6 +++--- textui.lisp | 4 ++-- xlunit.asd | 4 ++-- 8 files changed, 40 insertions(+), 82 deletions(-) rename test-case.lisp => tcase.lisp (92%) diff --git a/example.lisp b/example.lisp index 3fc9e3a..837906b 100644 --- a/example.lisp +++ b/example.lisp @@ -2,7 +2,7 @@ ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; -;;;; ID: $Id: example.lisp,v 1.5 2003/08/04 16:13:58 kevin Exp $ +;;;; ID: $Id: example.lisp,v 1.6 2003/08/04 17:04:49 kevin Exp $ ;;;; Purpose: Example file for XLUnit ;;;; ;;;; ************************************************************************* @@ -13,48 +13,38 @@ (in-package #:xlunit-example) -;;; First we define some basic fixtures that we are going to need to -;;; perform our tests. A fixture is a place to hold data we need +;;; First we define some basic test-cases that we are going to need to +;;; perform our tests. A test-case is a place to hold data we need ;;; during testing. Often there are many test cases that use the same ;;; data. Each of these test cases is an instance of a test-case. -(defclass math-fixture (test-case) +(defclass math-test-case (test-case) ((numbera :accessor numbera) (numberb :accessor numberb)) - (:documentation "Test fixture for math testing")) + (:documentation "Test test-case for math testing")) -;;; Then we define a set-up method for the fixture. This method is run -;;; prior to perfoming any test with an instance of this fixture. It +;;; Then we define a set-up method for the test-case. This method is run +;;; prior to perfoming any test with an instance of this test-case. It ;;; should perform all initialization needed, and assume that it is starting ;;; with a pristine environment, well to a point, use your head here. -(defmethod set-up ((fix math-fixture)) - (setf (numbera fix) 2) - (setf (numberb fix) 3)) +(defmethod set-up ((tcase math-test-case)) + (setf (numbera tcase) 2) + (setf (numberb tcase) 3)) -;;; Then we define a teardown method, which should return the instance -;;; to it's original form and reset the environment. In this case -;;; there is little for us to do since the fixture is quite static. -;;; In other cases we may need to clear some database tables, or -;;; otherwise get rid of state built up while perofmring the test. -;;; Here we just return T. - -(defmethod tear-down ((fix math-fixture)) - t) - -(def-test-method test-addition ((test math-fixture)) +(def-test-method test-addition ((test math-test-case)) (let ((result (+ (numbera test) (numberb test)))) - (test-assert (= result 5)))) + (assert-true (= result 5)))) -(def-test-method test-subtraction ((test math-fixture)) +(def-test-method test-subtraction ((test math-test-case)) (let ((result (- (numberb test) (numbera test)))) (assert-equal result 1))) ;;; This method is meant to signal a failure -(def-test-method test-subtraction-2 ((test math-fixture)) +(def-test-method test-subtraction-2 ((test math-test-case)) (let ((result (- (numbera test) (numberb test)))) (assert-equal result 1))) ;;;; Finally we can run our test suite and see how it performs. -(textui-test-run (make-test-suite 'math-fixture)) +(textui-test-run (make-instance 'math-test-case)) diff --git a/package.lisp b/package.lisp index 6b58890..ffaa50d 100644 --- a/package.lisp +++ b/package.lisp @@ -2,10 +2,10 @@ ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; -;;;; ID: $Id: package.lisp,v 1.6 2003/08/04 16:13:58 kevin Exp $ +;;;; ID: $Id: package.lisp,v 1.7 2003/08/04 17:04:49 kevin Exp $ ;;;; Purpose: Package definition for XLUnit ;;;; -;;;; $Id: package.lisp,v 1.6 2003/08/04 16:13:58 kevin Exp $ +;;;; $Id: package.lisp,v 1.7 2003/08/04 17:04:49 kevin Exp $ ;;;; ************************************************************************* (in-package #:cl-user) @@ -17,8 +17,9 @@ ;; test-case.lisp #:test-case #:def-test-method - #:setup - #:teardown + #:set-up + #:tear-down + #:run #:run-test #:make-test @@ -44,8 +45,8 @@ #:summary ;; result.lisp - #:test-result - #:make-test-result + #:test-results + #:make-test-results #:was-successful ) (:documentation "This is the XLUnit Framework.")) diff --git a/printer.lisp b/printer.lisp index 729e083..c89bfff 100644 --- a/printer.lisp +++ b/printer.lisp @@ -2,7 +2,7 @@ ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; -;;;; ID: $Id: printer.lisp,v 1.3 2003/08/04 16:13:58 kevin Exp $ +;;;; ID: $Id: printer.lisp,v 1.4 2003/08/04 17:04:49 kevin Exp $ ;;;; Purpose: Printer functions for XLUnit ;;;; ;;;; ************************************************************************* @@ -58,38 +58,7 @@ (incf i)) failures))))) -#| -(defun result-printer (result seconds stream) - (format stream "~&Time: ~D~%~%" (coerce seconds 'float)) - (print-defects (errors result) "error" stream) - (print-defects (failures result) "failure" stream) - (if (was-successful result) - (format stream "OK (~D tests)~%" (run-count result)) - (progn - (format stream "~%FAILURES!!!~%") - (format stream "Tests run: ~D, Failures: ~D, Errors: ~D~%" - (run-count result) (failure-count result) - (error-count result))))) - -(defun print-defects (defects type stream) - (when defects - (let ((count (length defects))) - (if (= count 1) - (format stream "~&There was ~D ~A:~%" count type) - (format stream "~&There were ~D ~As:~%" count type)) - (dotimes (i count) - (let ((defect (nth i defects))) - (format stream "~&~D) ~A " i (class-name - (class-of (failed-test defect)))) - (apply #'format stream (simple-condition-format-control - (thrown-condition defect)) - (simple-condition-format-arguments - (thrown-condition defect))) - (fresh-line stream)))))) - -|# - (defgeneric summary (result)) -(defmethod summary ((result test-result)) +(defmethod summary ((result test-results)) (format nil "~D run, ~D erred, ~D failed" - (run-count result) (error-count result) (failure-count result))) + (run-tests result) (error-count result) (failure-count result))) diff --git a/suite.lisp b/suite.lisp index 42d4d61..85cfcc6 100644 --- a/suite.lisp +++ b/suite.lisp @@ -2,7 +2,7 @@ ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; -;;;; ID: $Id: suite.lisp,v 1.4 2003/08/04 16:42:27 kevin Exp $ +;;;; ID: $Id: suite.lisp,v 1.5 2003/08/04 17:04:49 kevin Exp $ ;;;; Purpose: Suite functions for XLUnit ;;;; ;;;; ************************************************************************* @@ -28,7 +28,7 @@ t) (defmethod run-on-test ((suite test-suite) - &key (result (make-instance 'test-result)) + &key (result (make-instance 'test-results)) (handle-errors t)) (setup-testsuite-named (slot-value suite 'name)) (dolist (test (tests suite)) diff --git a/test-case.lisp b/tcase.lisp similarity index 92% rename from test-case.lisp rename to tcase.lisp index 2d54a13..da0d8de 100644 --- a/test-case.lisp +++ b/tcase.lisp @@ -2,7 +2,7 @@ ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; -;;;; ID: $Id: test-case.lisp,v 1.2 2003/08/04 16:42:27 kevin Exp $ +;;;; ID: $Id: tcase.lisp,v 1.1 2003/08/04 17:04:49 kevin Exp $ ;;;; Purpose: Test fixtures for XLUnit ;;;; ;;;; ************************************************************************* @@ -57,13 +57,11 @@ that the setup method did for this instance.")) ) (defmethod run ((ob test-case)) - (run-on-test-result ob (make-instance 'test-results))) + (run-on-test-results ob (make-instance 'test-results))) - -(defmethod run-on-test-result ((test test-case) - &key (result (make-instance 'test-result)) - (handle-errors t)) +(defmethod run-on-test-results ((test test-case) result + &key (handle-errors t)) (start-test test result) (run-protected test result :handle-errors handle-errors) (end-test test result)) @@ -103,10 +101,10 @@ that the setup method did for this instance.")) #| (defmethod run-test ((test test-case) - &key (result (make-instance 'test-result)) + &key (result (make-instance 'test-results)) (handle-errors t)) "Perform the test represented by the given test-case or test-suite. -Returns a test-result object." +Returns a test-results object." (incf (run-count result)) (with-slots (failures errors) result (unwind-protect-if handle-errors diff --git a/tests.lisp b/tests.lisp index e5cfb41..9b51919 100644 --- a/tests.lisp +++ b/tests.lisp @@ -2,7 +2,7 @@ ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; -;;;; Id: $Id: tests.lisp,v 1.7 2003/08/04 16:13:58 kevin Exp $ +;;;; Id: $Id: tests.lisp,v 1.8 2003/08/04 17:04:50 kevin Exp $ ;;;; Purpose: Test suite for XLUnit ;;;; ;;;; ************************************************************************* @@ -45,7 +45,7 @@ (run-test test) (assert-equal (ws-log test) "setup test-method teardown "))) -(defmethod test-result ((self test-case-test)) +(defmethod test-results ((self test-case-test)) (assert-equal "1 run, 0 erred, 0 failed" (summary (run-test (make-test 'was-run 'test-method))))) @@ -70,7 +70,7 @@ (defmethod test-suite ((self test-case-test)) (let ((suite (make-test-suite "TestSuite")) - (result (make-test-result))) + (result (make-test-results))) (add-test (make-test 'was-run 'test-method) suite) (add-test (make-test 'was-run 'test-broken-method) suite) (run-test suite :result result) diff --git a/textui.lisp b/textui.lisp index 92dbfb3..ec617e0 100644 --- a/textui.lisp +++ b/textui.lisp @@ -2,7 +2,7 @@ ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; -;;;; ID: $Id: textui.lisp,v 1.1 2003/08/04 16:13:58 kevin Exp $ +;;;; ID: $Id: textui.lisp,v 1.2 2003/08/04 17:04:50 kevin Exp $ ;;;; Purpose: Text UI for Test Runner ;;;; ;;;; ************************************************************************* @@ -33,7 +33,7 @@ (result (make-instance 'test-results)) (start-time (get-internal-real-time))) (add-listener result test-runner) - (run-on-test-result ob result) + (run-on-test-results ob result) (print-results test-runner result (/ (- (get-internal-real-time) start-time) internal-time-units-per-second)))) diff --git a/xlunit.asd b/xlunit.asd index f6f3d44..67c0fdd 100644 --- a/xlunit.asd +++ b/xlunit.asd @@ -7,7 +7,7 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Aug 2003 ;;;; -;;;; $Id: xlunit.asd,v 1.3 2003/08/04 16:13:58 kevin Exp $ +;;;; $Id: xlunit.asd,v 1.4 2003/08/04 17:04:50 kevin Exp $ ;;;; ************************************************************************* (defpackage #:xlunit-system (:use #:asdf #:cl)) @@ -25,7 +25,7 @@ :components ((:file "package") (:file "assert") - (:file "test-case") + (:file "tcase") (:file "suite") (:file "listener") (:file "result") -- 2.34.1