Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated file logger #77

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @DurieuxPol it should be better to put the delete in a tearDown method.
Otherwise, if the test fails for some reason, the system will remain dirty. (and the test will never pass then)

]
Loading