Skip to content

Commit

Permalink
Suppressed stacktrace message! Better output message
Browse files Browse the repository at this point in the history
  • Loading branch information
skim committed Jun 21, 2011
1 parent 3d80e42 commit 0169ccc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 36 deletions.
18 changes: 11 additions & 7 deletions src/lib/Koan.st
@@ -1,6 +1,10 @@
Object subclass: Koan [
| tracker |

ZenMessages := #(
'Do not lose hope.'
).

Koan class >> create: newTracker [
^self new
tracker: newTracker;
Expand All @@ -19,12 +23,14 @@ Object subclass: Koan [
^'FILL ME IN'.
]

collections [
^{Array . WeakArray . ArrayedCollection . OrderedCollection . SortedCollection . HashCollection . IdentityDictionary . Dictionary . IdentitySet . Set . Bag}
zenMessageCollection [
^#(
'Do not lose hope.'
)
]

zenMessage [
^'@dhh > Whoops!'
^self zenMessageCollection at: (Random between: 1 and: self zenMessageCollection size)
]

className: value [
Expand All @@ -45,14 +51,12 @@ Object subclass: Koan [
(value class = False)
ifTrue: [ ^'false' ].
(value class = UndefinedObject)
ifTrue: [
^'nil (an instance of UndefinedObject)'
].
ifTrue: [ ^'nil (an instance of UndefinedObject)' ].
(value class = Character)
ifTrue: [
^'$', value asString, ' ', (self anInstanceOf: value)
].
(self collections includes: (value class))
((value isKindOf: Collection) & (value class ~~ String) & (value class ~~ Symbol))
ifTrue: [
message := value displayString replacingRegex: ((self className: value), ' ') with: ''.
^message, (self anInstanceOf: value)
Expand Down
72 changes: 43 additions & 29 deletions src/lib/Zen.st
Expand Up @@ -16,33 +16,42 @@ Object subclass: Zen [
]

runKoans [
self testAssert.
self testBasic.
self testNil.
self testObject.
self testMessage.
self testNumber.
self testString.
self testCharacter.
self testSymbol.
self testArray.
self testOrderedCollection.
self testSortedCollection.
self testBag.
self testAssociation.
self testDictionary.
self testSet.
self testBlock.
self testCollectionsRevisited.
self testIteration.
self testBoolean.
self testException.
self testRegex.
self testClass.
self testClassHierarchy.
self testMetaclass. "metaprogramming"

self displayEndMessage: 0.
| koans |

koans := #(
#testAssert
#testBasic
#testNil
#testObject
#testMessage
#testNumber
#testString
#testCharacter
#testSymbol
#testArray
#testOrderedCollection
#testSortedCollection
#testBag
#testAssociation
#testDictionary
#testSet
#testBlock
#testCollectionsRevisited
#testIteration
#testBoolean
#testException
#testRegex
#testClass
#testClassHierarchy
#testMetaclass
).

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

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

testAssert [
Expand Down Expand Up @@ -331,18 +340,23 @@ Object subclass: Zen [
]

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

displayClass: klass test: testName [
Transcript show: klass name asString, '#', testName asString, ' needs your attention.';
| klassName |

klassName := klass name asString.
Transcript show: klassName, '#', testName asString, ' has damaged your karma.';
cr;
show: '(in src/koans/', klassName, '.st)';
cr; cr.
]

Expand Down

0 comments on commit 0169ccc

Please sign in to comment.