Skip to content
Permalink
Browse files

Fixed several code critics on the `Tests` package

  • Loading branch information
gcotelli committed Jul 20, 2019
1 parent 4dbc8c3 commit 11aa94185a19aa9a708de299976d74561dcc5173
@@ -17,10 +17,10 @@ BecomeTest >> testBecome [
a become: b.

self
assert: a = 'cd';
assert: b = 'ab';
assert: c = 'cd';
assert: d = 'ab'.
assert: a equals: 'cd';
assert: b equals: 'ab';
assert: c equals: 'cd';
assert: d equals: 'ab'.



@@ -39,10 +39,10 @@ BecomeTest >> testBecomeForward [
a becomeForward: b.

self
assert: a = 'cd';
assert: b = 'cd';
assert: c = 'cd';
assert: d = 'cd'.
assert: a equals: 'cd';
assert: b equals: 'cd';
assert: c equals: 'cd';
assert: d equals: 'cd'.



@@ -64,8 +64,8 @@ BecomeTest >> testBecomeForwardCopyIdentityHash [

self
assert: a == b;
assert: a identityHash = identityHashOfA;
assert: b identityHash = identityHashOfA.
assert: a identityHash equals: identityHashOfA;
assert: b identityHash equals: identityHashOfA.


]
@@ -86,8 +86,8 @@ BecomeTest >> testBecomeForwardDontCopyIdentityHash [

self
assert: a == b;
assert: a identityHash = identityHashOfB;
assert: b identityHash = identityHashOfB.
assert: a identityHash equals: identityHashOfB;
assert: b identityHash equals: identityHashOfB.


]
@@ -105,9 +105,9 @@ BecomeTest >> testBecomeForwardHash [
a becomeForward: b.

self
assert: a hash = hb;
assert: b hash = hb;
assert: c hash = hb.
assert: a hash equals: hb;
assert: b hash equals: hb;
assert: c hash equals: hb.



@@ -128,8 +128,8 @@ BecomeTest >> testBecomeForwardIdentityHash [
a becomeForward: b.

self
assert: a identityHash = ha;
assert: b identityHash = ha.
assert: a identityHash equals: ha;
assert: b identityHash equals: ha.


]
@@ -149,10 +149,10 @@ BecomeTest >> testBecomeHash [
a become: b.

self
assert: a hash = hb;
assert: b hash = ha;
assert: c hash = hb;
assert: d hash = ha.
assert: a hash equals: hb;
assert: b hash equals: ha;
assert: c hash equals: hb;
assert: d hash equals: ha



@@ -172,8 +172,8 @@ BecomeTest >> testBecomeIdentityHash [
a become: b.

self
assert: a identityHash = c identityHash;
assert: b identityHash = d identityHash;
deny: a identityHash = b identityHash.
assert: a identityHash equals: c identityHash;
assert: b identityHash equals: d identityHash;
deny: a identityHash equals: b identityHash.

]
@@ -85,7 +85,7 @@ ChangeSetClassChangesTest >> testAddInstanceVariable [
instanceVariableNames: 'zzz'
classVariableNames: ''
poolDictionaries: ''
category: 'DeleteMe-1'.
package: 'DeleteMe-1'.
saveClassDefinition := (Smalltalk globals classNamed: #JunkClass) oldDefinition.
self
assert:
@@ -97,7 +97,7 @@ ChangeSetClassChangesTest >> testAddInstanceVariable [
instanceVariableNames: 'zzz aaa'
classVariableNames: ''
poolDictionaries: ''
category: 'DeleteMe-1'. "Assert that the class definition has changed"
package: 'DeleteMe-1'. "Assert that the class definition has changed"
self deny: (self
isDefinition: (Smalltalk globals classNamed: #JunkClass) oldDefinition
equivalentTo: saveClassDefinition).
@@ -134,14 +134,14 @@ ChangeSetClassChangesTest >> testAddInstanceVariableAddsNewChangeRecord [
instanceVariableNames: 'zzz'
classVariableNames: ''
poolDictionaries: ''
category: 'DeleteMe-1'. "Forget about JunkClass in the change set"
package: 'DeleteMe-1'. "Forget about JunkClass in the change set"
ChangeSet current removeClassChanges: 'JunkClass'. "Redefine the class, adding one instance variable"
Object
subclass: #JunkClass
instanceVariableNames: 'zzz aaa'
classVariableNames: ''
poolDictionaries: ''
category: 'DeleteMe-1'. "A change record should now exist in the change set"
package: 'DeleteMe-1'. "A change record should now exist in the change set"
self
assert:
(self
@@ -166,15 +166,15 @@ ChangeSetClassChangesTest >> testChangeClassCategory [
instanceVariableNames: 'zzz'
classVariableNames: ''
poolDictionaries: ''
category: 'DeleteMe-1'.
package: 'DeleteMe-1'.
saveClassDefinition := (Smalltalk globals classNamed: #JunkClass) oldDefinition.
self assert: saveClassDefinition = (ChangeSet current fatDefForClass: (Smalltalk globals classNamed: #JunkClass)). "Redefine the class, changing only the class category"
self assert: saveClassDefinition equals: (ChangeSet current fatDefForClass: (Smalltalk globals classNamed: #JunkClass)). "Redefine the class, changing only the class category"
Object
subclass: #JunkClass
instanceVariableNames: 'zzz'
classVariableNames: ''
poolDictionaries: ''
category: 'DeleteMe-2'. "Assert that the class definition has changed"
package: 'DeleteMe-2'. "Assert that the class definition has changed"
self deny: (self isDefinition: (Smalltalk globals classNamed: #JunkClass) definition equivalentTo: saveClassDefinition).
self
deny:
@@ -207,21 +207,21 @@ ChangeSetClassChangesTest >> testChangeClassCategoryAddsNewChangeRecord [
no change records pertaining to it in the change set."

self deny: (Smalltalk hasClassNamed: 'JunkClass').
self assert: (ChangeSet current changeRecorderFor: (Smalltalk globals classNamed: #JunkClass)) thisName = 'nil'. "Remove bogus change records created as side effect of preceding assert"
self assert: (ChangeSet current changeRecorderFor: (Smalltalk globals classNamed: #JunkClass)) thisName equals: 'nil'. "Remove bogus change records created as side effect of preceding assert"
ChangeSet current removeClassChanges: 'nil'. "Define a class and save its definition"
Object
subclass: #JunkClass
instanceVariableNames: 'zzz'
classVariableNames: ''
poolDictionaries: ''
category: 'DeleteMe-1'. "Forget about JunkClass in the change set"
package: 'DeleteMe-1'. "Forget about JunkClass in the change set"
ChangeSet current removeClassChanges: 'JunkClass'. "Redefine the class, changing only the class category"
Object
subclass: #JunkClass
instanceVariableNames: 'zzz'
classVariableNames: ''
poolDictionaries: ''
category: 'DeleteMe-2'. "A change record should now exist in the change set"
package: 'DeleteMe-2'. "A change record should now exist in the change set"
self
assert:
(self
@@ -1,11 +1,11 @@
Class {
#name : #EphemeronTests,
#name : #EphemeronTest,
#superclass : #TestCase,
#category : #'Tests-Finalization'
}

{ #category : #tests }
EphemeronTests >> testEphemeronAreNotFinalizedIfCollected [
EphemeronTest >> testEphemeronAreNotFinalizedIfCollected [

| finalized theKey ephemeron |
Smalltalk supportsQueueingFinalization ifFalse: [ ^ self skip ].
@@ -23,43 +23,47 @@ EphemeronTests >> testEphemeronAreNotFinalizedIfCollected [
]

{ #category : #tests }
EphemeronTests >> testEphemeronIsNotRemovedFromRegistryUponFinalizationIfKeyIsReferenced [
EphemeronTest >> testEphemeronIsNotRemovedFromRegistryUponFinalizationIfKeyIsReferenced [

| finalized theKey registry |

Smalltalk supportsQueueingFinalization ifFalse: [ ^ self skip ].

finalized := false.
theKey := ObjectFinalizer receiver: [ finalized := true ] selector: #value.

registry := EphemeronRegistry new.
registry at: theKey put: nil.

registry at: theKey put: nil.
"Nil theKey to remove all strong references to it. Then Garbage collect to force mourning"
Smalltalk garbageCollect.

self assert: registry size equals: 1.

self
assert: registry size equals: 1;
assert: finalized
]

{ #category : #tests }
EphemeronTests >> testEphemeronIsRemovedFromRegistryUponFinalization [
EphemeronTest >> testEphemeronIsRemovedFromRegistryUponFinalization [

| finalized theKey registry |

Smalltalk supportsQueueingFinalization ifFalse: [ ^ self skip ].

finalized := false.
theKey := ObjectFinalizer receiver: [ finalized := true ] selector: #value.

registry := EphemeronRegistry new.
registry at: theKey put: nil.

"Nil theKey to remove all strong references to it. Then Garbage collect to force mourning"
registry at: theKey put: nil. "Nil theKey to remove all strong references to it. Then Garbage collect to force mourning"
theKey := nil.
Smalltalk garbageCollect.

self assertEmpty: registry
self
assertEmpty: registry;
assert: finalized
]

{ #category : #tests }
EphemeronTests >> testEphemeronKeyIsFinalizedWhenKeyIsNotHoldStrongly [
EphemeronTest >> testEphemeronKeyIsFinalizedWhenKeyIsNotHoldStrongly [

| finalized theKey ephemeron |
Smalltalk supportsQueueingFinalization ifFalse: [ ^ self skip ].
@@ -77,7 +81,7 @@ EphemeronTests >> testEphemeronKeyIsFinalizedWhenKeyIsNotHoldStrongly [
]

{ #category : #tests }
EphemeronTests >> testEphemeronKeyIsNotFinalizedWhenKeyIsHoldStrongly [
EphemeronTest >> testEphemeronKeyIsNotFinalizedWhenKeyIsHoldStrongly [

| finalized theKey ephemeron |
Smalltalk supportsQueueingFinalization ifFalse: [ ^ self skip ].
@@ -94,7 +98,7 @@ EphemeronTests >> testEphemeronKeyIsNotFinalizedWhenKeyIsHoldStrongly [
]

{ #category : #tests }
EphemeronTests >> testInterconnectedEphemeronsAreCollectedIfKeysAreNotReferencedFromTheOutside [
EphemeronTest >> testInterconnectedEphemeronsAreCollectedIfKeysAreNotReferencedFromTheOutside [

| finalized1 finalized2 theKey theValue ephemeron1 ephemeron2 |
Smalltalk supportsQueueingFinalization ifFalse: [ ^ self skip ].
@@ -114,7 +118,7 @@ EphemeronTests >> testInterconnectedEphemeronsAreCollectedIfKeysAreNotReferenced
]

{ #category : #tests }
EphemeronTests >> testInterconnectedEphemeronsAreNotCollectedIfAKeyIsReferencedFromTheOutside [
EphemeronTest >> testInterconnectedEphemeronsAreNotCollectedIfAKeyIsReferencedFromTheOutside [

| finalized1 finalized2 theKey theValue ephemeron1 ephemeron2 |
Smalltalk supportsQueueingFinalization ifFalse: [ ^ self skip ].
@@ -135,7 +139,7 @@ EphemeronTests >> testInterconnectedEphemeronsAreNotCollectedIfAKeyIsReferencedF
]

{ #category : #tests }
EphemeronTests >> testInterconnectedEphemeronsAreNotCollectedIfTheOtherKeyIsReferencedFromTheOutside [
EphemeronTest >> testInterconnectedEphemeronsAreNotCollectedIfTheOtherKeyIsReferencedFromTheOutside [

| finalized1 finalized2 theKey theValue ephemeron1 ephemeron2 |
Smalltalk supportsQueueingFinalization ifFalse: [ ^ self skip ].
@@ -11,14 +11,14 @@ MOPTraitTest >> testClass [
"methodClass could call
-> methodClassOrTrait"

self assert: (Trait1>>#c) methodClass = Trait1.
self assert: (Trait2>>#c) methodClass = Trait2.
self assert: (MOPTestClassC>>#c) methodClass = MOPTestClassC.
self assert: (MOPTestClassC>>#c2) methodClass = MOPTestClassC.
self assert: (MOPTestClassD>>#c) methodClass = MOPTestClassD.
self assert: (MOPTestClassD>>#c2) methodClass = MOPTestClassD.
self assert: (MOPTestClassD>>#c3) methodClass = MOPTestClassD.
self assert: (MOPTestClassA>>#c2) methodClass = MOPTestClassA.
self assert: (Trait1>>#c) methodClass equals: Trait1.
self assert: (Trait2>>#c) methodClass equals: Trait2.
self assert: (MOPTestClassC>>#c) methodClass equals: MOPTestClassC.
self assert: (MOPTestClassC>>#c2) methodClass equals: MOPTestClassC.
self assert: (MOPTestClassD>>#c) methodClass equals: MOPTestClassD.
self assert: (MOPTestClassD>>#c2) methodClass equals: MOPTestClassD.
self assert: (MOPTestClassD>>#c3) methodClass equals: MOPTestClassD.
self assert: (MOPTestClassA>>#c2) methodClass equals: MOPTestClassA.

]

@@ -28,13 +28,13 @@ MOPTraitTest >> testOrigin [

| aliasedMethod |

self assert: (MOPTestClassC>>#c) origin = MOPTestClassC.
self assert: (MOPTestClassA>>#c) origin = Trait3.
self assert: (Trait3>>#c2) origin = Trait2.
self assert: (MOPTestClassA>>#c2) origin = Trait2.
self assert: (MOPTestClassB>>#c) origin = Trait1.
self assert: (MOPTestClassD>>#c3) origin = Trait2.
self assert: (MOPTestClassD>>#c2) origin = Trait2.
self assert: (MOPTestClassC>>#c) origin equals: MOPTestClassC.
self assert: (MOPTestClassA>>#c) origin equals: Trait3.
self assert: (Trait3>>#c2) origin equals: Trait2.
self assert: (MOPTestClassA>>#c2) origin equals: Trait2.
self assert: (MOPTestClassB>>#c) origin equals: Trait1.
self assert: (MOPTestClassD>>#c3) origin equals: Trait2.
self assert: (MOPTestClassD>>#c2) origin equals: Trait2.

aliasedMethod := MOPTestClassD >>#c3.
self assert: aliasedMethod origin == aliasedMethod originMethod methodClass.
@@ -45,9 +45,9 @@ MOPTraitTest >> testSelector [
"The selector of a compiled method should be its name.
An aliased method should have the name of its alias name."

self assert: (MOPTestClassA>>#c) selector = #c.
self assert: (MOPTestClassC>>#c) selector = #c.
self assert: (Trait3>>#c) selector = #c.
self assert: (Trait3>>#c2) selector = #c2.
self assert: (MOPTestClassD>>#c3) selector = #c3.
self assert: (MOPTestClassA>>#c) selector equals: #c.
self assert: (MOPTestClassC>>#c) selector equals: #c.
self assert: (Trait3>>#c) selector equals: #c.
self assert: (Trait3>>#c2) selector equals: #c2.
self assert: (MOPTestClassD>>#c3) selector equals: #c3.
]
@@ -1,11 +1,11 @@
Class {
#name : #ObjectFinalizerTests,
#name : #ObjectFinalizerTest,
#superclass : #TestCase,
#category : #'Tests-Finalization'
}

{ #category : #tests }
ObjectFinalizerTests >> testFinalizationOfMultipleResources [
ObjectFinalizerTest >> testFinalizationOfMultipleResources [
"Test that finalizers for multiple resources registered will be ran when
object is finalized"
| objToFinalize resource1 resource2 resourceCleanBlock |

0 comments on commit 11aa941

Please sign in to comment.
You can’t perform that action at this time.