Skip to content

Commit

Permalink
Merge pull request #77 from DurieuxPol/fix/logger
Browse files Browse the repository at this point in the history
Updated file logger
  • Loading branch information
guillep authored Feb 14, 2024
2 parents aee676f + 89a9d76 commit 2e3ec99
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/MuTalk-Model/MTAnalysisFileLogger.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Class {
#name : 'MTAnalysisFileLogger',
#superclass : 'MTAnalysisLogger',
#instVars : [
'fileStream'
'fileReference'
],
#category : 'MuTalk-Model-Logging',
#package : 'MuTalk-Model',
Expand All @@ -16,22 +16,27 @@ MTAnalysisFileLogger class >> toFileNamed: aString [

{ #category : 'initialize-release' }
MTAnalysisFileLogger >> initializeToFileNamed: aString [
fileStream := FileStream forceNewFileNamed: aString.

fileReference := aString asFileReference
]

{ #category : 'logging' }
MTAnalysisFileLogger >> logAnalysisStartFor: aMutationTestingAnalysis [
self writeLineToFile: 'The analysis is starting...'.
MTAnalysisFileLogger >> logAnalysisStartFor: aMutationTestingAnalysis [

self writeLineToFile: 'The analysis is starting...'
]

{ #category : 'logging' }
MTAnalysisFileLogger >> logStartBuildingMutantionsFor: aCompiledMethod using: aMutantOperator [
self writeLineToFile: 'Generating mutations for '
, (self methodNameOf: aCompiledMethod) , ' With operator:' , aMutantOperator description
MTAnalysisFileLogger >> logStartBuildingMutantionsFor: aCompiledMethod using: aMutantOperator [

self writeLineToFile:
'Generating mutations for ' , (self methodNameOf: aCompiledMethod)
, ' With operator:' , aMutantOperator description
]

{ #category : 'logging' }
MTAnalysisFileLogger >> logStartEvaluating: aMethodMutation [

| logStream |
logStream := WriteStream on: String new.
logStream
Expand All @@ -44,14 +49,18 @@ MTAnalysisFileLogger >> logStartEvaluating: aMethodMutation [
]

{ #category : 'private' }
MTAnalysisFileLogger >> methodNameOf: aCompiledMethod [
^aCompiledMethod methodClass name asString , '>>' , aCompiledMethod selector printString
MTAnalysisFileLogger >> methodNameOf: aCompiledMethod [

^ aCompiledMethod methodClass name asString , '>>'
, aCompiledMethod selector printString
]

{ #category : 'private' }
MTAnalysisFileLogger >> writeLineToFile: aString [
[fileStream closed
ifTrue: [fileStream open].
fileStream setToEnd; nextPutAll: aString; cr]
ensure: [fileStream close]
MTAnalysisFileLogger >> writeLineToFile: aString [

fileReference writeStreamDo: [ :stream |
stream
setToEnd;
nextPutAll: aString;
cr ]
]
23 changes: 23 additions & 0 deletions src/MuTalk-Tests/MTAnalysisFileLoggerTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Class {
#name : 'MTAnalysisFileLoggerTest',
#superclass : 'TestCase',
#category : 'MuTalk-Tests',
#package : 'MuTalk-Tests'
}

{ #category : 'tests' }
MTAnalysisFileLoggerTest >> testLogFileExists [

| analysis logFileName logFile |
logFileName := 'logFileForTest.txt'.
logFile := logFileName asFileReference.
analysis := MTAnalysis new
classesToMutate: { MTAuxiliarClassForMTAnalysis };
testClasses: { MTAuxiliarClassForMTAnalysisTest };
logger: (MTAnalysisFileLogger toFileNamed: logFileName).

analysis run.

self assert: logFile exists.
logFile delete
]

0 comments on commit 2e3ec99

Please sign in to comment.