TestResult.st
changeset 0 9365d5753f11
child 6 78bb1397e43d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TestResult.st	Wed Oct 25 17:51:59 2000 +0200
@@ -0,0 +1,134 @@
+'From Smalltalk/X, Version:4.1.1 on 24-oct-2000 at 08:10:32 pm'                 !
+
+"{ Package: 'stx:goodies/sunit' }"
+
+Object subclass:#TestResult
+	instanceVariableNames:'runCount failures errors'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'SUnit'
+!
+
+!TestResult class methodsFor:'Exceptions'!
+
+error
+       ^self exError
+
+    "Modified: / 21.6.2000 / 10:07:16 / Sames"
+!
+
+exError
+	"Change for Dialect"
+	^Error
+
+    "Modified: / 21.6.2000 / 10:10:45 / Sames"
+!
+
+failure
+       ^TestFailure
+
+    "Modified: / 21.6.2000 / 10:07:03 / Sames"
+!
+
+signalErrorWith: aString 
+	self error sunitSignalWith: aString
+
+    "Modified: / 21.6.2000 / 10:11:07 / Sames"
+!
+
+signalFailureWith: aString 
+	self failure sunitSignalWith: aString
+
+    "Modified: / 21.6.2000 / 10:11:20 / Sames"
+! !
+
+!TestResult class methodsFor:'Init / Release'!
+
+new
+	^super new initialize
+
+    "Modified: / 21.6.2000 / 10:11:50 / Sames"
+! !
+
+!TestResult methodsFor:'Accessing'!
+
+correctCount
+	^self runCount - self failureCount - self errorCount
+
+    "Modified: / 21.6.2000 / 10:07:48 / Sames"
+!
+
+defects
+	^self errors, self failures
+
+    "Modified: / 21.6.2000 / 10:07:56 / Sames"
+!
+
+errorCount
+	^self errors size!
+
+errors
+	errors isNil ifTrue: [errors := OrderedCollection new].
+	^errors!
+
+failureCount
+	^self failures size
+
+    "Modified: / 21.6.2000 / 10:08:34 / Sames"
+!
+
+failures
+	failures isNil ifTrue: [failures := OrderedCollection new].
+	^failures!
+
+runCount
+	^runCount! !
+
+!TestResult methodsFor:'Init / Release'!
+
+initialize
+	runCount := 0! !
+
+!TestResult methodsFor:'Printing'!
+
+printOn: aStream
+	aStream
+		nextPutAll: self runCount printString;
+		nextPutAll: ' run, ';
+		nextPutAll: self failureCount printString;
+		nextPutAll: ' failed, ';
+		nextPutAll: self errorCount printString;
+		nextPutAll:' error'.
+	self errorCount ~= 1
+		ifTrue: [aStream nextPut: $s].
+
+    "Created: / 21.6.2000 / 10:09:12 / Sames"
+! !
+
+!TestResult methodsFor:'Running'!
+
+runCase: aTestCase
+	runCount := runCount + 1.
+	[[aTestCase runCase] 
+		sunitOn: self class failure
+		do: 
+			[:signal | 
+			self failures add: aTestCase.
+			signal sunitExitWith: nil]]
+			sunitOn: self class error
+			do:
+				[:signal |
+				self errors add: aTestCase.
+				signal sunitExitWith: nil]
+
+    "Modified: / 21.6.2000 / 10:10:06 / Sames"
+! !
+
+!TestResult methodsFor:'Testing'!
+
+hasPassed
+	^self runCount = self correctCount!
+
+isFailure: aTestCase
+	^self failures includes: aTestCase! !
+