Skip to content

Commit

Permalink
Merge pull request #38 from jecisc/keep-right-identation-on-error
Browse files Browse the repository at this point in the history
keep-right-identation-on-error
  • Loading branch information
jecisc committed Mar 16, 2020
2 parents 25119e0 + 269f723 commit 172a181
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/TinyLogger-Tests/TinyLoggerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,37 @@ No time : End: This is a new test
stream close ]
]

{ #category : #test }
TinyLoggerTest >> testExecuteRecordedAsKeepRightIndentation [
| contents stream |
self skipInPharo6.
logger
timestampFormatBlock: [ :s | s nextPutAll: 'No time' ];
removeAllLoggers;
addStdoutLogger.
stream := '' writeStream.
[ Stdio stub stdout willReturn: stream.
TinyCurrentLogger
value: logger
during: [ [ Object new execute: [ Error signal ] recordedAs: 'This is a new test' ]
on: Error
do: [ "nothing" ].
Object new execute: [ 'test' record ] recordedAs: 'This is a new test' ].
contents := Stdio stdout contents asString.
"Ensure we have the right indentation."
self
assert: contents withUnixLineEndings
equals:
'No time : Begin: This is a new test
No time : End with error: This is a new test
No time : Begin: This is a new test
No time : test
No time : End: This is a new test
' withUnixLineEndings ]
ensure: [ Stdio recoverFromGHMutation.
stream close ]
]

{ #category : #test }
TinyLoggerTest >> testFileLoggers [
logger
Expand Down
6 changes: 5 additions & 1 deletion src/TinyLogger/TinyLogger.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ TinyLogger >> execute: aBlock recordedAs: aString [
self increaseDepthLevel.
self record: 'Begin: ' , aString.
self increaseDepthLevel.
aBlock cull: aString.
[ aBlock cull: aString ]
ifCurtailed: [ "If there is an error, we ensure we keep the right indentation and we print an end of action with error."
self decreaseDepthLevel.
self record: 'End with error: ' , aString.
self decreaseDepthLevel ].
self decreaseDepthLevel.
self record: 'End: ' , aString.
self decreaseDepthLevel
Expand Down

0 comments on commit 172a181

Please sign in to comment.