[PATCH] sunit: Add >>#assert:equals: from Pharo for the Phexample

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] sunit: Add >>#assert:equals: from Pharo for the Phexample

Holger Freyther
The above selector is needed for Phexample and in general very
nice to debug failures as the result and expectation is immediately
visible in the debugger.

2013-05-11  Holger Hans Peter Freyther  <[hidden email]>

        * packages/sunit/SUnit.st: Add #assert:equals: and
        #comparingStringBetween:and: from Pharo to the TestCase.
---
 packages/sunit/ChangeLog |    5 +++++
 packages/sunit/SUnit.st  |   18 ++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/packages/sunit/ChangeLog b/packages/sunit/ChangeLog
index 56a52cf..bdb12a7 100644
--- a/packages/sunit/ChangeLog
+++ b/packages/sunit/ChangeLog
@@ -1,3 +1,8 @@
+2013-05-11  Holger Hans Peter Freyther  <[hidden email]>
+
+ * packages/sunit/SUnit.st: Add #assert:equals: and
+ #comparingStringBetween:and: from Pharo to the TestCase.
+
 2012-08-03  Holger Hans Peter Freyther  <[hidden email]>
 
  * packages/sunit/SUnit.st: Use testSelector printString as
diff --git a/packages/sunit/SUnit.st b/packages/sunit/SUnit.st
index 58b3ab0..38a872b 100644
--- a/packages/sunit/SUnit.st
+++ b/packages/sunit/SUnit.st
@@ -847,6 +847,13 @@ When you are writing a test case method, send #assert: aBoolean when you want to
  exception sunitSignalWith: aString]
     ]
 
+    assert: actual equals: expected [
+        <category: 'Accessing'>
+ ^ self
+ assert: expected = actual
+ description: [self comparingStringBetween: actual and: expected]
+    ]
+
     deny: aBoolean [
  <category: 'Accessing'>
  self assert: aBoolean not
@@ -1085,6 +1092,17 @@ When you are writing a test case method, send #assert: aBoolean when you want to
  testSelector := aSymbol
     ]
 
+    comparingStringBetween: actual and: expected [
+        <category: 'Private'>
+        ^ String streamContents: [:stream |
+                stream
+                    nextPutAll: 'Got ';
+                    nextPutAll: actual printString;
+                    nextPutAll: ' instead of ';
+                    nextPutAll: expected printString;
+                    nextPutAll: '.']
+    ]
+
     addDependentToHierachy: anObject [
  "an empty method. for Composite compability with TestSuite"
 
--
1.7.10.4


_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] sunit: Add >>#assert:equals: from Pharo for the Phexample

Paolo Bonzini-2
Il 17/06/2013 10:09, Holger Hans Peter Freyther ha scritto:

> The above selector is needed for Phexample and in general very
> nice to debug failures as the result and expectation is immediately
> visible in the debugger.
>
> 2013-05-11  Holger Hans Peter Freyther  <[hidden email]>
>
> * packages/sunit/SUnit.st: Add #assert:equals: and
> #comparingStringBetween:and: from Pharo to the TestCase.
> ---
>  packages/sunit/ChangeLog |    5 +++++
>  packages/sunit/SUnit.st  |   18 ++++++++++++++++++
>  2 files changed, 23 insertions(+)
>
> diff --git a/packages/sunit/ChangeLog b/packages/sunit/ChangeLog
> index 56a52cf..bdb12a7 100644
> --- a/packages/sunit/ChangeLog
> +++ b/packages/sunit/ChangeLog
> @@ -1,3 +1,8 @@
> +2013-05-11  Holger Hans Peter Freyther  <[hidden email]>
> +
> + * packages/sunit/SUnit.st: Add #assert:equals: and
> + #comparingStringBetween:and: from Pharo to the TestCase.
> +
>  2012-08-03  Holger Hans Peter Freyther  <[hidden email]>
>  
>   * packages/sunit/SUnit.st: Use testSelector printString as
> diff --git a/packages/sunit/SUnit.st b/packages/sunit/SUnit.st
> index 58b3ab0..38a872b 100644
> --- a/packages/sunit/SUnit.st
> +++ b/packages/sunit/SUnit.st
> @@ -847,6 +847,13 @@ When you are writing a test case method, send #assert: aBoolean when you want to
>   exception sunitSignalWith: aString]
>      ]
>  
> +    assert: actual equals: expected [
> +        <category: 'Accessing'>
> + ^ self
> + assert: expected = actual
> + description: [self comparingStringBetween: actual and: expected]
> +    ]
> +
>      deny: aBoolean [
>   <category: 'Accessing'>
>   self assert: aBoolean not
> @@ -1085,6 +1092,17 @@ When you are writing a test case method, send #assert: aBoolean when you want to
>   testSelector := aSymbol
>      ]
>  
> +    comparingStringBetween: actual and: expected [
> +        <category: 'Private'>
> +        ^ String streamContents: [:stream |
> +                stream
> +                    nextPutAll: 'Got ';
> +                    nextPutAll: actual printString;
> +                    nextPutAll: ' instead of ';
> +                    nextPutAll: expected printString;
> +                    nextPutAll: '.']
> +    ]
> +
>      addDependentToHierachy: anObject [
>   "an empty method. for Composite compability with TestSuite"
>  
>

Please apply!

Paolo

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