Skip to content

Commit

Permalink
#execute:recordedAs: now return the return of the block
Browse files Browse the repository at this point in the history
Fixes #39
  • Loading branch information
jecisc committed Oct 11, 2021
1 parent af8d35e commit 16eaa82
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/TinyLogger-Tests/TinyLoggerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,25 @@ No time : End: This is a new test
stream close ]
]

{ #category : #test }
TinyLoggerTest >> testExecuteRecordedAsReturnBlockContent [
| contents stream bool |
self skipInPharo6.
bool := false.
logger
removeAllLoggers;
addStdoutLogger.
stream := '' writeStream.
[ Stdio stub stdout willReturn: stream.
bool := logger execute: [ true ] recordedAs: 'This is a new test'.
contents := Stdio stdout contents asString.
self assert: bool.
self assert: (contents includesSubstring: 'Begin: This is a new test').
self assert: (contents includesSubstring: 'End: This is a new test') ]
ensure: [ Stdio recoverFromGHMutation.
stream close ]
]

{ #category : #test }
TinyLoggerTest >> testFileLoggers [
logger
Expand Down
2 changes: 1 addition & 1 deletion src/TinyLogger/Object.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Extension { #name : #Object }

{ #category : #'*TinyLogger' }
Object >> execute: aBlock recordedAs: aString [
TinyCurrentLogger value execute: aBlock recordedAs: aString
^ TinyCurrentLogger value execute: aBlock recordedAs: aString
]

{ #category : #'*TinyLogger' }
Expand Down
6 changes: 4 additions & 2 deletions src/TinyLogger/TinyLogger.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,19 @@ TinyLogger >> ensureTranscriptLogger [

{ #category : #'public API' }
TinyLogger >> execute: aBlock recordedAs: aString [
| result |
self increaseDepthLevel.
self record: 'Begin: ' , aString.
self increaseDepthLevel.
[ aBlock cull: aString ]
[ result := 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
self decreaseDepthLevel.
^ result
]

{ #category : #'accessing - loggers' }
Expand Down

0 comments on commit 16eaa82

Please sign in to comment.