Skip to content

Commit

Permalink
Merge pull request #16 from ba-st/regex-support
Browse files Browse the repository at this point in the history
Regex support
  • Loading branch information
gcotelli authored Jun 28, 2024
2 parents 37deb5b + 20149c8 commit d03b538
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
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
]

0 comments on commit d03b538

Please sign in to comment.