diff --git a/rowan/components/Dependent-SUnit-Extensions.ston b/rowan/components/Dependent-SUnit-Extensions.ston index ac1f1fa..16498c4 100644 --- a/rowan/components/Dependent-SUnit-Extensions.ston +++ b/rowan/components/Dependent-SUnit-Extensions.ston @@ -1,7 +1,9 @@ RwSimpleProjectLoadComponentV2 { #name : 'Dependent-SUnit-Extensions', #condition : 'sunit', - #projectNames : [ ], + #projectNames : [ + 'Regex' + ], #componentNames : [ 'Deployment' ], diff --git a/rowan/projects/Regex.ston b/rowan/projects/Regex.ston new file mode 100644 index 0000000..c6e9c27 --- /dev/null +++ b/rowan/projects/Regex.ston @@ -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' + ] +} \ No newline at end of file diff --git a/source/Bell-Logging-Tests/LogRecordTest.class.st b/source/Bell-Logging-Tests/LogRecordTest.class.st index 4510c99..a149395 100644 --- a/source/Bell-Logging-Tests/LogRecordTest.class.st +++ b/source/Bell-Logging-Tests/LogRecordTest.class.st @@ -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 } @@ -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 [ diff --git a/source/Bell-SUnit/LoggingAsserter.class.st b/source/Bell-SUnit/LoggingAsserter.class.st index e446b51..cb342b8 100644 --- a/source/Bell-SUnit/LoggingAsserter.class.st +++ b/source/Bell-SUnit/LoggingAsserter.class.st @@ -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 [ @@ -45,9 +56,4 @@ LoggingAsserter >> runMemoryLoggerDuring: aBlockClosure [ LoggingAsserter >> stopLoggers [ memoryLogger reset. - - StandardStreamLogger onStandardOutput stop. - StandardStreamLogger onStandardError stop. - StandardErrorStructuredLogger onStandardOutput stop. - StandardErrorStructuredLogger onStandardError stop ]