Hi all,

while toying with Grease and playing with the now removed ColorTest I noticed 
that it is using the concept of expected failures and that it was added in 
Pharo and that our copy of Pharo is lacking it.

I have started merging the SUnit changes back. The first patch is a 
preparation, patch adds new selectors, patch three changes the meaning of 
passed and failures and patch four is done by me as Pharo added new features 
but no unit tests for SUnit.


 SUnit.st      |  109 
++++++++++++++++++++++++++++++++++++++++++++++------------
 SUnitTests.st |   33 +++++++++++++++++
 2 files changed, 120 insertions(+), 22 deletions(-)


feedback is welcome, i will continue to merge in the other changes as well...
From 96e5d85741095cb45602b05df8514c630f821cb9 Mon Sep 17 00:00:00 2001
From: Holger Hans Peter Freyther <[email protected]>
Date: Thu, 15 Apr 2010 13:01:37 +0200
Subject: [PATCH 1/4] SUnit: Initialize errors, failures and passed in the initialize method

This is needed to help merging the Pharo changes on SUnit as
the passed and errors selector were redefined to collect the
information from two other selectors.
---
 packages/sunit/SUnit.st |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/packages/sunit/SUnit.st b/packages/sunit/SUnit.st
index e21e9ca..004627e 100644
--- a/packages/sunit/SUnit.st
+++ b/packages/sunit/SUnit.st
@@ -300,7 +300,6 @@ This is a Collecting Parameter for the running of a bunch of tests. TestResult i
 
     errors [
 	<category: 'Accessing'>
-	errors isNil ifTrue: [errors := Set new].
 	^errors
     ]
 
@@ -311,13 +310,11 @@ This is a Collecting Parameter for the running of a bunch of tests. TestResult i
 
     failures [
 	<category: 'Accessing'>
-	failures isNil ifTrue: [failures := Set new].
 	^failures
     ]
 
     passed [
 	<category: 'Accessing'>
-	passed isNil ifTrue: [passed := OrderedCollection new].
 	^passed
     ]
 
@@ -334,9 +331,9 @@ This is a Collecting Parameter for the running of a bunch of tests. TestResult i
     tests [
 	<category: 'Accessing'>
 	^(OrderedCollection new: self runCount)
-	    addAll: self passed;
-	    addAll: self errors;
-	    addAll: self failures;
+	    addAll: passed;
+	    addAll: errors;
+	    addAll: failures;
 	    yourself
     ]
 
@@ -372,7 +369,9 @@ This is a Collecting Parameter for the running of a bunch of tests. TestResult i
 
     initialize [
 	<category: 'Init / Release'>
-	
+	errors := Set new.
+	failures := Set new.
+	passed := OrderedCollection new.
     ]
 
     runCase: aTestCase [
@@ -385,16 +384,16 @@ This is a Collecting Parameter for the running of a bunch of tests. TestResult i
 		true] sunitOn: self class failure
 			do: 
 			    [:signal | 
-			    self failures add: aTestCase.
+			    failures add: aTestCase.
 			    signal sunitExitWith: false]] 
 			sunitOn: self class error
 			do: 
 			    [:signal | 
-			    (self errors includes: aTestCase) ifFalse: [aTestCase logError: signal].
-			    self errors add: aTestCase.
+			    (errors includes: aTestCase) ifFalse: [aTestCase logError: signal].
+			    errors add: aTestCase.
 			    signal sunitExitWith: false].
 	aTestCase logPolicy flush.
-	testCasePassed ifTrue: [self passed add: aTestCase]
+	testCasePassed ifTrue: [passed add: aTestCase]
     ]
 
     printOn: aStream [
-- 
1.7.0

From ebd75620fcaa7a8a91c39c20e367174a4d492894 Mon Sep 17 00:00:00 2001
From: Holger Hans Peter Freyther <[email protected]>
Date: Thu, 15 Apr 2010 13:27:24 +0200
Subject: [PATCH 2/4] SUnit: Add new selectors from Pharo for handling (un)expected failures/success

Add new selectors to handle expected failures and unexpected
success on test cases. The code is not yet used.

This is coming from the Pharo1.0-10508-rc2dev10.01.2 image.
---
 packages/sunit/SUnit.st |   63 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/packages/sunit/SUnit.st b/packages/sunit/SUnit.st
index 004627e..f187c8d 100644
--- a/packages/sunit/SUnit.st
+++ b/packages/sunit/SUnit.st
@@ -303,6 +303,57 @@ This is a Collecting Parameter for the running of a bunch of tests. TestResult i
 	^errors
     ]
 
+    expectedDefectCount [
+	<category: 'Accessing'>
+	^self expectedDefects size
+    ]
+
+    expectedDefects [
+	<category: 'Accessing'>
+	^errors , failures asOrderedCollection
+	    select: [:each | each shouldPass not]
+    ]
+
+    expectedPassCount [
+	<category: 'Accessing'>
+	^self expectedPasses size
+    ]
+
+    expectedPasses [
+	<category: 'Accessing'>
+	^passed select: [:each | each shouldPass]
+    ]
+
+    unexpectedErrorCount [
+	<category: 'Accessing'>
+	^self unexpectedErrors size
+    ]
+
+    unexpectedErrors [
+	<category: 'Accessing'>
+	^errors select: [:each | each shouldPass]
+    ]
+
+    unexpectedFailureCount [
+	<category: 'Accessing'>
+	^self unexpectedFailures size
+    ]
+
+    unexpectedFailures [
+	<category: 'Accessing'>
+	^failures select: [:each | each shouldPass]
+    ]
+
+    unexpectedPassCount [
+	<category: 'Accessing'>
+	^self unexpectedPasses size
+    ]
+
+    unexpectedPasses [
+	<category: 'Accessing'>
+	^passed select: [:each | each shouldPass not]
+    ]
+
     failureCount [
 	<category: 'Accessing'>
 	^self failures size
@@ -986,6 +1037,18 @@ When you are writing a test case method, send #assert: aBoolean when you want to
 	
     ]
 
+    expectedFailures [
+	<category: 'Testing'>
+	^Array new
+    ]
+
+    shouldPass [
+	"Unless the selector is in the list we get from #expectedFailures, we expect it to pass"
+
+	<category: 'Testing'>
+	^(self expectedFailures includes: testSelector) not
+    ]
+
     executeShould: aBlock inScopeOf: anExceptionalEvent [
 	<category: 'Private'>
 	^
-- 
1.7.0

From 186707162fcc23a82c2213cdf70b7474a713931d Mon Sep 17 00:00:00 2001
From: Holger Hans Peter Freyther <[email protected]>
Date: Thu, 15 Apr 2010 14:02:30 +0200
Subject: [PATCH 3/4] SUnit: Use the new selectors for (un)expected failure/success

Use the new selectors to handle unexpected success and
expected success on test cases. The change is coming from
the Pharo image.

Right now the plural handling for errors/failures is lost.
---
 packages/sunit/SUnit.st |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/packages/sunit/SUnit.st b/packages/sunit/SUnit.st
index f187c8d..49bd9d6 100644
--- a/packages/sunit/SUnit.st
+++ b/packages/sunit/SUnit.st
@@ -300,7 +300,7 @@ This is a Collecting Parameter for the running of a bunch of tests. TestResult i
 
     errors [
 	<category: 'Accessing'>
-	^errors
+	^self unexpectedErrors
     ]
 
     expectedDefectCount [
@@ -366,7 +366,7 @@ This is a Collecting Parameter for the running of a bunch of tests. TestResult i
 
     passed [
 	<category: 'Accessing'>
-	^passed
+	^self expectedPasses, self expectedDefects
     ]
 
     passedCount [
@@ -376,7 +376,7 @@ This is a Collecting Parameter for the running of a bunch of tests. TestResult i
 
     runCount [
 	<category: 'Accessing'>
-	^self passedCount + self failureCount + self errorCount
+	^passed size + failures size + errors size
     ]
 
     tests [
@@ -452,13 +452,16 @@ This is a Collecting Parameter for the running of a bunch of tests. TestResult i
 	aStream
 	    nextPutAll: self runCount printString;
 	    nextPutAll: ' run, ';
-	    nextPutAll: self passedCount printString;
-	    nextPutAll: ' passed, ';
-	    nextPutAll: self failureCount printString;
-	    nextPutAll: ' failed, ';
-	    nextPutAll: self errorCount printString;
-	    nextPutAll: ' error'.
-	self errorCount ~= 1 ifTrue: [aStream nextPut: $s]
+	    nextPutAll: self expectedPassCount printString;
+	    nextPutAll: ' passes, ';
+	    nextPutAll: self expectedDefectCount printString;
+	    nextPutAll: ' expected failures, ';
+	    nextPutAll: self unexpectedFailureCount printString;
+	    nextPutAll: ' failures, ';
+	    nextPutAll: self unexpectedErrorCount printString;
+	    nextPutAll: ' errors, ';
+	    nextPutAll: self unexpectedPassCount printString;
+	    nextPutAll: ' unexpected passes'
     ]
 ]
 
-- 
1.7.0

From 42f1a5f0a00d66d3809414ea4f8aa23986dcebe3 Mon Sep 17 00:00:00 2001
From: Holger Hans Peter Freyther <[email protected]>
Date: Thu, 15 Apr 2010 14:48:04 +0200
Subject: [PATCH 4/4] SUnit: Add a test case for expectedDefects and unexpectedPasses

---
 packages/sunit/SUnit.st      |    2 +-
 packages/sunit/SUnitTests.st |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/packages/sunit/SUnit.st b/packages/sunit/SUnit.st
index 49bd9d6..22080b1 100644
--- a/packages/sunit/SUnit.st
+++ b/packages/sunit/SUnit.st
@@ -885,7 +885,7 @@ When you are writing a test case method, send #assert: aBoolean when you want to
 
     defaultLogPolicyClass [
 	<category: 'Accessing'>
-	^TestCondensedLog
+	^TestVerboseLog
     ]
 
     resources [
diff --git a/packages/sunit/SUnitTests.st b/packages/sunit/SUnitTests.st
index 289001d..d1160a1 100644
--- a/packages/sunit/SUnitTests.st
+++ b/packages/sunit/SUnitTests.st
@@ -249,6 +249,24 @@ if the tests are hard to write, something is probably wrong with the design".'>
 	    errors: 1
     ]
 
+    testExpectedFailures [
+        <category: 'Testing'>
+        | result suite expected failed error |
+	suite := TestSuite new.
+	suite addTest: (expected := SUnitClientTest selector: #generateExpectedFailure).
+	suite addTest: (failed := SUnitClientTest selector: #generateUnexpectedSuccess).
+	result := suite run.
+	self assert: (result expectedDefects includes: expected).
+	self assert: (result unexpectedPasses includes: failed).
+
+	self
+	    assertForTestResult: result
+	    runCount: 2
+	    passed: 1
+	    failed: 1
+	    errors: 0
+    ]
+
     assertForTestResult: aResult runCount: aRunCount passed: aPassedCount failed: aFailureCount errors: anErrorCount [
 	<category: 'Private'>
 	self
@@ -430,6 +448,21 @@ will run.'>
 	<category: 'Running'>
 	hasSetup := true
     ]
+
+    expectedFailures [
+	<category: 'Private'>
+        ^#(#generateExpectedFailure #generateUnexpectedSuccess)
+    ]
+
+    generateExpectedFailure [
+	<category: 'Private'>
+        self assert: false
+    ]
+
+    generateUnexpectedSuccess [
+	<category: 'Private'>
+        self assert: true
+    ]
 ]
 
 
-- 
1.7.0

_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to