Skip to content

Commit

Permalink
refactored tracking logic
Browse files Browse the repository at this point in the history
  • Loading branch information
skim committed Jul 2, 2011
1 parent 54d507e commit 07b2f4b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 60 deletions.
46 changes: 21 additions & 25 deletions src/lib/Koan.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ Object subclass: Koan [
]

tracker: newTracker [
tracker := newTracker
]

tracker [
^tracker
tracker := newTracker.
]

fillMeIn [
Expand Down Expand Up @@ -91,94 +87,94 @@ Object subclass: Koan [
]

expectToBeTrue: expression [
(self tracker status)
tracker status
ifFalse: [ ^false ].
(expression)
expression
ifFalse: [
Transcript cr;
show: self zenMessage, ' It is false, but SHOULD be true.';
cr; cr.
self tracker status: false.
tracker status: false.
]
ifTrue: [
self tracker status: true.
tracker status: true.
].
]

expectToBeFalse: expression [
(self tracker status)
tracker status
ifFalse: [ ^false ].
(expression)
expression
ifTrue: [
Transcript cr;
show: self zenMessage, ' It is true, but SHOULD be false.';
cr; cr.
self tracker status: false.
tracker status: false.
]
ifFalse: [
self tracker status: true.
tracker status: true.
].
]

expect: expectedValue toEqual: actualValue [
(self tracker status)
tracker status
ifFalse: [ ^false ].
(expectedValue = actualValue)
ifFalse: [
self diff value: 'Expected value should equal actual value.'
value: expectedValue
value: actualValue.
self tracker status: false.
tracker status: false.
]
ifTrue: [
self tracker status: true.
tracker status: true.
].
]

expect: expectedValue toNotEqual: actualValue [
(self tracker status)
tracker status
ifFalse: [ ^false ].
(expectedValue = actualValue)
ifTrue: [
self diff value: 'Expected value should not equal actual value.'
value: expectedValue
value: actualValue.
self tracker status: false.
tracker status: false.
]
ifFalse: [
self tracker status: true.
tracker status: true.
].
]

expect: expectedValue toBeLike: actualValue [
(self tracker status)
tracker status
ifFalse: [ ^false ].
(expectedValue class = actualValue class)
ifFalse: [
self diff value: 'Expected value is not like actual value.'
value: expectedValue
value: actualValue.
self tracker status: false.
tracker status: false.
]
ifTrue: [
self tracker status: true.
tracker status: true.
].
]

expect: blockExpression toRaise: expectedException [
| actualException |
(self tracker status)
tracker status
ifFalse: [ ^false ].
actualException := blockExpression on: Exception do: [ :signal | signal return: signal class ].
(expectedException = actualException)
ifFalse: [
self diff value: 'Expected exception was not given.'
value: expectedException
value: actualException.
self tracker status: false.
tracker status: false.
]
ifTrue: [
self tracker status: true.
tracker status: true.
].
]
]
6 changes: 6 additions & 0 deletions src/lib/Tracker.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Object subclass: Tracker [
|status|

Tracker class >> create [
^self new
status: true;
yourself
]

status [
^status
]
Expand Down
65 changes: 30 additions & 35 deletions src/lib/Zen.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ Object subclass: Zen [

initialize [
passed := 0.
tracker := Tracker new.
tracker status: true.
]

tracker [
^tracker
tracker := Tracker create.
]

runKoans [
Expand Down Expand Up @@ -47,23 +42,23 @@ Object subclass: Zen [
).

koans do: [ :koan |
(self tracker status) ifFalse: [^nil].
tracker status ifFalse: [^nil].
self perform: koan.
].

(self tracker status) ifTrue: [self displayEndMessage: 0].
tracker status ifTrue: [self displayEndMessage: 0].
]

testAssert [
currentTest := TestAssert create: (self tracker).
currentTest := TestAssert create: tracker.
self tally: #testTruth.
self tally: #testEquality.
self tally: #testStringEquality.
self tally: #testNotEqual.
]

testBasic [
currentTest := TestBasic create: (self tracker).
currentTest := TestBasic create: tracker.
self tally: #testDeclarationAndAssignment.
self tally: #testEqualSignIsNotAnAssignmentOperator.
self tally: #testMultipleStatementsInASingleLine.
Expand All @@ -74,15 +69,15 @@ Object subclass: Zen [
]

testNil [
currentTest := TestNil create: (self tracker).
currentTest := TestNil create: tracker.
self tally: #testNilIsAnObject.
self tally: #testNilIsTheSameInstance.
self tally: #testUndefinedObjectInstancesAreNotTheSame.
self tally: #testNilChecking.
]

testObject [
currentTest := TestObject create: (self tracker).
currentTest := TestObject create: tracker.
self tally: #testEverythingIsAnObject.
self tally: #testSomeObjectsCanBeConvertedToStrings.
self tally: #testNilObjectCannotBeConvertedToString.
Expand All @@ -94,7 +89,7 @@ Object subclass: Zen [
]

testMessage [
currentTest := TestMessage create: (self tracker).
currentTest := TestMessage create: tracker.
self tally: #testUnaryMessage.
self tally: #testBinaryMessage.
self tally: #testKeywordMessage.
Expand All @@ -108,7 +103,7 @@ Object subclass: Zen [
]

testNumber [
currentTest := TestNumber create: (self tracker).
currentTest := TestNumber create: tracker.
self tally: #testDifferentNumbers.
self tally: #testNumberParts.
self tally: #testSigns.
Expand All @@ -120,7 +115,7 @@ Object subclass: Zen [
]

testString [
currentTest := TestString create: (self tracker).
currentTest := TestString create: tracker.
self tally: #testStringsCanOnlyBeCreatedUsingSingleQuotes.
self tally: #testUseSingleQuotesInStrings.
self tally: #testStringConcatenation.
Expand All @@ -134,7 +129,7 @@ Object subclass: Zen [
]

testCharacter [
currentTest := TestCharacter create: (self tracker).
currentTest := TestCharacter create: tracker.
self tally: #testCharactersCanBeCompared.
self tally: #testCharacterAsciiValue.
self tally: #testUnprintableCharacters.
Expand All @@ -148,7 +143,7 @@ Object subclass: Zen [
]

testSymbol [
currentTest := TestSymbol create: (self tracker).
currentTest := TestSymbol create: tracker.
self tally: #testSymbolsStartWithHash.
self tally: #testSymbolsInheritFromString.
self tally: #testSymbolsCanBeCompared.
Expand All @@ -160,7 +155,7 @@ Object subclass: Zen [
]

testArray [
currentTest := TestArray create: (self tracker).
currentTest := TestArray create: tracker.
self tally: #testCreatingAnEmptyArray.
self tally: #testCreatingAnArrayWithSpecifiedSize.
self tally: #testCreatingAnArrayWithUpToFiveInitialValues.
Expand All @@ -173,7 +168,7 @@ Object subclass: Zen [
]

testOrderedCollection [
currentTest := TestOrderedCollection create: (self tracker).
currentTest := TestOrderedCollection create: tracker.
self tally: #testActsLikeAnExpandableArray.
self tally: #testCreatingAnOrderedCollectionWithUpToFiveInitialValues.
self tally: #testCreatingAnOrderedCollectionFromAConstantArray.
Expand All @@ -184,29 +179,29 @@ Object subclass: Zen [
]

testSortedCollection [
currentTest := TestSortedCollection create: (self tracker).
currentTest := TestSortedCollection create: tracker.
self tally: #testDefaultSortCriteria.
self tally: #testSpecifySortCriteria.
self tally: #testComparingSortedCollections.
]

testBag [
currentTest := TestBag create: (self tracker).
currentTest := TestBag create: tracker.
self tally: #testAddingMultiplesCopiesToCollection.
self tally: #testCollectionIsNotIndexable.
self tally: #testComparingBags.
]

testAssociation [
currentTest := TestAssociation create: (self tracker).
currentTest := TestAssociation create: tracker.
self tally: #testCreatingAssociationThreeDifferentWays.
self tally: #testAssociationKeysCanBeAnyObject.
self tally: #testComparingAssociations.
self tally: #testAssociationsActLikeSingletons.
]

testDictionary [
currentTest := TestDictionary create: (self tracker).
currentTest := TestDictionary create: tracker.
self tally: #testCreatingANewDictionary.
self tally: #testAddingKeysAndValuesUsingAssociations.
self tally: #testAddingAssociationsUsingAtPut.
Expand All @@ -221,7 +216,7 @@ Object subclass: Zen [
]

testSet [
currentTest := TestSet create: (self tracker).
currentTest := TestSet create: tracker.
self tally: #testDuplicateObjectsNotAllowed.
self tally: #testAddingSets.
self tally: #testSubtractingSets.
Expand All @@ -230,7 +225,7 @@ Object subclass: Zen [
]

testBlock [
currentTest := TestBlock create: (self tracker).
currentTest := TestBlock create: tracker.
self tally: #testBlockCreation.
self tally: #testSendingValueMessageExecutesBlocks.
self tally: #testBlocksReturnAnyKindOfValue.
Expand All @@ -246,7 +241,7 @@ Object subclass: Zen [
]

testCollectionsRevisited [
currentTest := TestCollectionsRevisited create: (self tracker).
currentTest := TestCollectionsRevisited create: tracker.
self tally: #testDo.
self tally: #testConform.
self tally: #testSelect.
Expand All @@ -260,14 +255,14 @@ Object subclass: Zen [
]

testIteration [
currentTest := TestIteration create: (self tracker).
currentTest := TestIteration create: tracker.
self tally: #testWhileTrue.
self tally: #testWhileFalse.
self tally: #testTimesRepeat.
]

testBoolean [
currentTest := TestBoolean create: (self tracker).
currentTest := TestBoolean create: tracker.
self tally: #testTrueIsTreatedAsTrue.
self tally: #testFalseIsTreatedAsFalse.
self tally: #testNilIsNotTreatedAsABoolean.
Expand All @@ -279,14 +274,14 @@ Object subclass: Zen [
]

testException [
currentTest := TestException create: (self tracker).
currentTest := TestException create: tracker.
self tally: #testHaltAndError.
self tally: #testSignal.
self tally: #testCatchingExceptionsWithOnDo.
]

testRegex [
currentTest := TestRegex create: (self tracker).
currentTest := TestRegex create: tracker.
self tally: #testSearchRegex.
self tally: #testUsingPerlSyntax.
self tally: #testUsingTilde.
Expand Down Expand Up @@ -320,7 +315,7 @@ Object subclass: Zen [
]

testClass [
currentTest := TestClass create: (self tracker).
currentTest := TestClass create: tracker.
self tally: #testName.
self tally: #testPragmas.
self tally: #testInstanceVariableCollection.
Expand All @@ -332,17 +327,17 @@ Object subclass: Zen [
]

testClassHierarchy [
currentTest := TestClassHierarchy create: (self tracker).
currentTest := TestClassHierarchy create: tracker.
]

testMetaclass [
currentTest := TestMetaclass create: (self tracker).
currentTest := TestMetaclass create: tracker.
]

tally: testName [
(self tracker status) ifFalse: [^nil].
tracker status ifFalse: [^nil].
currentTest perform: testName.
(self tracker status)
tracker status
ifTrue: [ passed:= (passed + 1). ]
ifFalse: [
self displayClass: currentTest class test: testName.
Expand Down

0 comments on commit 07b2f4b

Please sign in to comment.