Skip to content

Commit

Permalink
Finish Log Parsing (including Colors)
Browse files Browse the repository at this point in the history
Co-authored-by: SebastianWagner2 <sebastian.wagner@student.hpi.uni-potsdam.de>
  • Loading branch information
Benjamin-Frost and SebastianWagner2 committed Jun 11, 2021
1 parent 9150d14 commit 5f3174e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
constants
ansiCodeDictonary

^ Dictionary newFrom: {
'[31m' -> (Dictionary newFrom: { 'prefix' -> 'FAIL'. 'color' -> (ATDDTestingEntity colorDictionary at: #error) }).
'[32m' -> (Dictionary newFrom: { 'prefix' -> 'PASS'. 'color' -> (ATDDTestingEntity colorDictionary at: #successful) })
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
updating
isSmalltalkCILog: aString

^ aString includesSubstring: 'Run hpi-swa/setup-smalltalkCI'
^ aString includesSubstring: 'Run hpi-swa/setup-smalltalkCI'
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
updating
parseAnsiCodeOf: aString

|parsedLine|
| parsedLine prefixColorDictonary match |

parsedLine := aString.
(parsedLine includesSubstring: '[32')
ifTrue: [parsedLine := parsedLine asText addAttribute: (TextColor color: Color green)]
ifFalse: [
(parsedLine includesSubstring: '[31')
ifTrue: [parsedLine := parsedLine asText addAttribute: (TextColor color: Color red)]
ifFalse: [
(parsedLine includesSubstring: '[34')
ifTrue: [parsedLine := parsedLine asText addAttribute: (TextColor color: Color blue)]
]
].
parsedLine := parsedLine copyReplaceAll: '[0m' with: ''.
parsedLine := parsedLine copyReplaceAll: '[1m' with: ''.
parsedLine := parsedLine copyReplaceAll: '[31m' with: ''.
parsedLine := parsedLine copyReplaceAll: '[32m' with: ''.
parsedLine := parsedLine copyReplaceAll: '[34m' with: ''.
parsedLine := parsedLine copyReplaceAll: '✗' with: '[FAIL]'. "This question mark is a cross"
parsedLine := parsedLine copyReplaceAll: '✓' with: '[PASS]'. "This question mark is a check mark"
^ parsedLine
"Set default values"
parsedLine := aString.
match := (parsedLine allRegexMatches: '#\w* \(\d*ms\)') at: 1 ifAbsent: [ nil ].

self class ansiCodeDictonary keysAndValuesDo: [ :aKey :aDictionary |
match ifNotNil: [
(parsedLine includesSubstring: aKey) ifTrue: [ prefixColorDictonary := aDictionary ]
]
].

"Remove all Ansi Codes"
parsedLine := parsedLine copyWithRegex: '\[\d+m' matchesReplacedWith: ''.
parsedLine := match ifNil: [ parsedLine ].

prefixColorDictonary ifNotNil: [
parsedLine :=
' [' asText,
((prefixColorDictonary at: 'prefix') asText addAttribute: (TextColor color: (prefixColorDictonary at: 'color'))),
'] ' asText,
parsedLine asText
]
ifNil: [ parsedLine := parsedLine asText ].

^ parsedLine
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@ parseSmalltalkCILog: aString
parsedLine := ''.

aString linesDo: [ :line |
"start of logging"
(line includesSubstring: 'Running suite "Squeak')
ifTrue: [ shouldIncludeLine := true ]. "start of logging"
ifTrue: [ shouldIncludeLine := true ].

"Remove timestamp"
(line isEmpty)
ifTrue: [ parsedLine := line]
ifFalse: [parsedLine := line allButFirst: 28]. "Remove timestamp"
parsedLine := parsedLine, Character cr. "Add new Line"
ifTrue: [ parsedLine := line ]
ifFalse: [ parsedLine := line allButFirst: 28 ].

"Parse Ansi Codes + Add new line (CR)"
parsedLine := self parseAnsiCodeOf: parsedLine.
parsedLine := parsedLine, Character cr asText.

(shouldIncludeLine)
ifTrue: [log append: parsedLine].
(shouldIncludeLine) ifTrue: [log append: parsedLine].

"end of logging"
(line matchesRegex: '.*Executed \d* Tests with \d* Failures and \d* Errors.*')
ifTrue: [shouldIncludeLine := false]. "end of logging"
ifTrue: [shouldIncludeLine := false].
].

^ log
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"class" : {
"ansiCodeDictonary" : "BF 6/11/2021 20:40",
"isAbstract" : "ls 7/25/2019 08:44",
"parser" : "sw 5/21/2021 20:55",
"targetName" : "sw 5/21/2021 20:55" },
Expand All @@ -8,11 +9,11 @@
"colorForSelectedHistory" : "ClassTest 5/29/2021 19:12",
"history" : "ClassTest 5/29/2021 19:12",
"historyInfoForSelectedHistory" : "ng 5/23/2021 09:15",
"isSmalltalkCILog:" : "BF 6/11/2021 12:57",
"isSmalltalkCILog:" : "BF 6/11/2021 21:10",
"jobNames" : "ng 5/26/2021 14:18",
"jobNames:" : "ng 5/26/2021 14:18",
"parseAnsiCodeOf:" : "ng 6/11/2021 19:30",
"parseSmalltalkCILog:" : "ng 6/11/2021 19:27",
"parseAnsiCodeOf:" : "BF 6/11/2021 21:15",
"parseSmalltalkCILog:" : "BF 6/11/2021 19:48",
"selectedJob:" : "ng 5/26/2021 14:54",
"updateJobLogForId:" : "BF 6/11/2021 13:43",
"updateJobs" : "ClassTest 5/29/2021 19:12" } }

0 comments on commit 5f3174e

Please sign in to comment.