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

Regex support #16

Merged
merged 9 commits into from
Jun 28, 2024
4 changes: 3 additions & 1 deletion rowan/components/Dependent-SUnit-Extensions.ston
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
RwSimpleProjectLoadComponentV2 {
#name : 'Dependent-SUnit-Extensions',
#condition : 'sunit',
#projectNames : [ ],
#projectNames : [
'Regex'
],
#componentNames : [
'Deployment'
],
Expand Down
10 changes: 10 additions & 0 deletions rowan/projects/Regex.ston
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RwLoadSpecificationV2 {
#specName: 'Regex',
#projectName : 'Regex',
#gitUrl : 'https://github.com/ba-st-dependencies/Regex.git',
#revision : 'v1',
#projectSpecFile : 'rowan/project.ston',
#componentNames : [
'Deployment'
]
}
34 changes: 32 additions & 2 deletions source/Bell-Logging-Tests/LogRecordTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ Class {
}

{ #category : #private }
LogRecordTest >> runMemoryLoggerDuring: aBlock assertingLogRecordsMatch: expectedLogEntries [
LogRecordTest >> runMemoryLoggerDuring: aBlock assertingLogRecordsMatch: anExpectedLogEntryCollection [

loggingAsserter
runMemoryLoggerDuring: aBlock;
assertLogRecordsMatch: expectedLogEntries
assertLogRecordsMatch: anExpectedLogEntryCollection
]

{ #category : #private }
LogRecordTest >> runMemoryLoggerDuring: aBlock assertingLogRecordsMatchRegexes: aRegexCollection [

loggingAsserter
runMemoryLoggerDuring: aBlock;
assertLogRecordsMatchUsing: aRegexCollection
]

{ #category : #running }
Expand Down Expand Up @@ -47,6 +55,28 @@ LogRecordTest >> testEmitCombinedEvents [
'[ERROR] Starting app... [FAILED]' )
]

{ #category : #tests }
LogRecordTest >> testEmitCombinedEventsWithRegex [

self
runMemoryLoggerDuring: [
self
should: [
LogRecord emitInfo: 'Starting app' during: [
LogRecord emitInfo: 'Setting up data'.
LogRecord emitWarning: 'Missing data, using default.'.
Error signal
]
]
raise: Error
]
assertingLogRecordsMatchRegexes:
#( '.+ \[INFO].+\.{0,3}'
'.+ \[INFO].+\.{0,1}'
'.+ \[WARNING].+\.{0,1}'
'.+ \[ERROR].+( \[FAILED\])?\.{0,1}' )
]

{ #category : #tests }
LogRecordTest >> testEmitDebug [

Expand Down
20 changes: 13 additions & 7 deletions source/Bell-SUnit/LoggingAsserter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,23 @@ LoggingAsserter class >> on: aTestCase [
]

{ #category : #asserting }
LoggingAsserter >> assertLogRecordsMatch: expectedLogEntries [
LoggingAsserter >> assertLogRecordsMatch: anExpectedLogEntryCollection [

memoryLogger recordings with: expectedLogEntries do: [ :record :expectedLogEntry |
memoryLogger recordings with: anExpectedLogEntryCollection do: [ :record :expectedLogEntry |
testCase assert: ( record printString includesSubstring: expectedLogEntry ) ]
]

{ #category : #asserting }
LoggingAsserter >> assertLogRecordsMatchUsing: aRegexCollection [

memoryLogger recordings with: aRegexCollection do: [ :record :regexExpression |
testCase
assert: ( record printString matchesRegex: regexExpression )
description:
( '<1s> does not match <2s>' expandMacrosWith: record printString with: regexExpression )
]
]

{ #category : #initialization }
LoggingAsserter >> initializeOn: aTestCase [

Expand All @@ -45,9 +56,4 @@ LoggingAsserter >> runMemoryLoggerDuring: aBlockClosure [
LoggingAsserter >> stopLoggers [

memoryLogger reset.

StandardStreamLogger onStandardOutput stop.
StandardStreamLogger onStandardError stop.
StandardErrorStructuredLogger onStandardOutput stop.
StandardErrorStructuredLogger onStandardError stop
]