-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from jecisc/20-assert-x-isEmpty--assertEmpty--co
20-assert-x-isEmpty--assertEmpty--co
- Loading branch information
Showing
3 changed files
with
217 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
src/Chanel-Tests/ChanelTestEmptyAssertionsCleanerTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
" | ||
A ChanelTestEmptyAssertionsCleanerTest is a test class for testing the behavior of ChanelTestEmptyAssertionsCleaner | ||
" | ||
Class { | ||
#name : #ChanelTestEmptyAssertionsCleanerTest, | ||
#superclass : #ChanelAbstractCleanerTest, | ||
#category : #'Chanel-Tests' | ||
} | ||
|
||
{ #category : #running } | ||
ChanelTestEmptyAssertionsCleanerTest >> setUp [ | ||
super setUp. | ||
class := self createDefaultTestClass | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testAssertEmpty [ | ||
self assert: 'self assert: #() isEmpty' isRewrittenAs: 'self assertEmpty: #()' | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testAssertEmpty2 [ | ||
self assert: 'self deny: #() isNotEmpty' isRewrittenAs: 'self assertEmpty: #()' | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testAssertEmpty2NotReplacedForPharo7 [ | ||
self deny: 'self deny: #() isNotEmpty' isRewrittenForPharo: 7 | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testAssertEmptyNotReplacedForPharo7 [ | ||
self deny: 'self assert: #() isEmpty' isRewrittenForPharo: 7 | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testDenyEmpty [ | ||
self assert: 'self deny: #() isEmpty' isRewrittenAs: 'self denyEmpty: #()' | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testDenyEmpty2 [ | ||
self assert: 'self assert: #() isNotEmpty' isRewrittenAs: 'self denyEmpty: #()' | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testDenyEmpty2NotReplacedForPharo7 [ | ||
self deny: 'self assert: #() isNotEmpty' isRewrittenForPharo: 7 | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testDenyEmptyNotReplacedForPharo7 [ | ||
self deny: 'self deny: #() isEmpty' isRewrittenForPharo: 7 | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testDoesNotRemoveExtensions [ | ||
class | ||
compile: | ||
('{1} | ||
{2}' format: {self selector . 'self assert: #() isEmpty'}) | ||
classified: self extensionProtocol. | ||
|
||
self runCleaner. | ||
|
||
self | ||
assert: (class >> self selector) sourceCode | ||
equals: | ||
('{1} | ||
{2}' format: {self selector . 'self assertEmpty: #()'}). | ||
|
||
self assert: (class >> self selector) protocol equals: self extensionProtocol | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testDoesNotReplaceInTraits [ | ||
| trait | | ||
trait := self createDefaultTrait. | ||
|
||
class setTraitComposition: trait. | ||
|
||
trait | ||
compile: | ||
('{1} | ||
{2}' format: {self selector . 'self assert: #() isEmpty'}). | ||
|
||
self runCleaner. | ||
|
||
self | ||
assert: (trait >> self selector) sourceCode | ||
equals: | ||
('{1} | ||
{2}' format: {self selector . 'self assert: #() isEmpty'}). | ||
|
||
self assert: (trait localSelectors includes: self selector). | ||
self deny: (class localSelectors includes: self selector) | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testReplacementOnClassSide [ | ||
class class | ||
compile: | ||
('{1} | ||
{2}' format: {self selector . 'self assert: #() isEmpty'}). | ||
|
||
self runCleaner. | ||
|
||
self | ||
assert: (class class >> self selector) sourceCode | ||
equals: | ||
('{1} | ||
{2}' format: {self selector . 'self assertEmpty: #()'}) | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testShouldNotReplaceIfNotATestCase [ | ||
"We only replace the assertion of TestCase because other objects are much poorer in term of assertions." | ||
|
||
class := self createDefaultClass. | ||
|
||
class | ||
compile: | ||
('{1} | ||
{2}' format: {self selector . 'self assert: #() isEmpty'}). | ||
|
||
self runCleaner. | ||
|
||
self | ||
assert: (class >> self selector) sourceCode | ||
equals: | ||
('{1} | ||
{2}' format: {self selector . 'self assert: #() isEmpty'}) | ||
] | ||
|
||
{ #category : #tests } | ||
ChanelTestEmptyAssertionsCleanerTest >> testWithNothingToReplace [ | ||
| oldMethod | | ||
class | ||
compile: | ||
('{1} | ||
{2}' format: {self selector . 'self assert: 3 equals: 2'}). | ||
|
||
oldMethod := class >> self selector. | ||
self runCleaner. | ||
|
||
self | ||
assert: (class >> self selector) sourceCode | ||
equals: | ||
('{1} | ||
{2}' format: {self selector . 'self assert: 3 equals: 2'}). | ||
|
||
self assert: class >> self selector identicalTo: oldMethod | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
" | ||
Description | ||
-------------------- | ||
I am a cleaner replacing the invocation of #assert: with #isEmpty or #isNotEmpty by #assertEmpty: or #denyEmpty: in Pharo >= 8. | ||
The reason is that it gives better logs in case of failure. | ||
" | ||
Class { | ||
#name : #ChanelTestEmptyAssertionsCleaner, | ||
#superclass : #ChanelMethodRewriterCleaner, | ||
#category : #Chanel | ||
} | ||
|
||
{ #category : #testing } | ||
ChanelTestEmptyAssertionsCleaner class >> isAvailableForPharo: anInteger [ | ||
^ anInteger >= 8 | ||
] | ||
|
||
{ #category : #accessing } | ||
ChanelTestEmptyAssertionsCleaner class >> priority [ | ||
^ 1100 | ||
] | ||
|
||
{ #category : #cleaning } | ||
ChanelTestEmptyAssertionsCleaner >> rewriter [ | ||
^ RBParseTreeRewriter new | ||
replace: '`@receiver assert: `@arg isEmpty' with: '`@receiver assertEmpty: `@arg'; | ||
replace: '`@receiver deny: `@arg isEmpty' with: '`@receiver denyEmpty: `@arg'; | ||
replace: '`@receiver assert: `@arg isNotEmpty' with: '`@receiver denyEmpty: `@arg'; | ||
replace: '`@receiver deny: `@arg isNotEmpty' with: '`@receiver assertEmpty: `@arg'; | ||
yourself | ||
] | ||
|
||
{ #category : #cleaning } | ||
ChanelTestEmptyAssertionsCleaner >> scope [ | ||
^ self configuration definedTestCases | ||
] |