From 2290a2139e49b1be134d971a0f7134e0266fc984 Mon Sep 17 00:00:00 2001 From: mreyes Date: Mon, 24 Jun 2024 17:22:06 -0300 Subject: [PATCH 1/8] :wrench: add assertion message with regex expressions --- source/Bell-SUnit/LoggingAsserter.class.st | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/Bell-SUnit/LoggingAsserter.class.st b/source/Bell-SUnit/LoggingAsserter.class.st index e446b51..bfe31fe 100644 --- a/source/Bell-SUnit/LoggingAsserter.class.st +++ b/source/Bell-SUnit/LoggingAsserter.class.st @@ -28,6 +28,20 @@ LoggingAsserter >> assertLogRecordsMatch: expectedLogEntries [ testCase assert: ( record printString includesSubstring: expectedLogEntry ) ] ] +{ #category : #asserting } +LoggingAsserter >> assertLogRecordsMatchRegexes: regexExpressions [ + + memoryLogger recordings with: regexExpressions do: [ :record :regexExpression | + | regexWithTimestamp | + + regexWithTimestamp := '\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d+(\+|-)(\d+\:\d+) <1s>' expandMacrosWith: + regexExpression. + testCase assert: ( record printString matchesRegex: regexWithTimestamp ) + description: + ( '<1s> does not match <2s>' expandMacrosWith: record printString with: regexWithTimestamp ) + ] +] + { #category : #initialization } LoggingAsserter >> initializeOn: aTestCase [ From a8d8ae7283792d724d81efc8403b75e141eb01d0 Mon Sep 17 00:00:00 2001 From: mreyes Date: Mon, 24 Jun 2024 17:22:06 -0300 Subject: [PATCH 2/8] :wrench: add assertion message with regex expressions --- source/Bell-SUnit/LoggingAsserter.class.st | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/Bell-SUnit/LoggingAsserter.class.st b/source/Bell-SUnit/LoggingAsserter.class.st index e446b51..bfe31fe 100644 --- a/source/Bell-SUnit/LoggingAsserter.class.st +++ b/source/Bell-SUnit/LoggingAsserter.class.st @@ -28,6 +28,20 @@ LoggingAsserter >> assertLogRecordsMatch: expectedLogEntries [ testCase assert: ( record printString includesSubstring: expectedLogEntry ) ] ] +{ #category : #asserting } +LoggingAsserter >> assertLogRecordsMatchRegexes: regexExpressions [ + + memoryLogger recordings with: regexExpressions do: [ :record :regexExpression | + | regexWithTimestamp | + + regexWithTimestamp := '\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d+(\+|-)(\d+\:\d+) <1s>' expandMacrosWith: + regexExpression. + testCase assert: ( record printString matchesRegex: regexWithTimestamp ) + description: + ( '<1s> does not match <2s>' expandMacrosWith: record printString with: regexWithTimestamp ) + ] +] + { #category : #initialization } LoggingAsserter >> initializeOn: aTestCase [ From 125aeeae7661a80a4a05b9012892ec20c38eb491 Mon Sep 17 00:00:00 2001 From: mreyes Date: Tue, 25 Jun 2024 16:53:08 -0300 Subject: [PATCH 3/8] :wrench: change regexes for gemstone compatibility --- source/Bell-SUnit/LoggingAsserter.class.st | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Bell-SUnit/LoggingAsserter.class.st b/source/Bell-SUnit/LoggingAsserter.class.st index bfe31fe..ad06384 100644 --- a/source/Bell-SUnit/LoggingAsserter.class.st +++ b/source/Bell-SUnit/LoggingAsserter.class.st @@ -34,7 +34,7 @@ LoggingAsserter >> assertLogRecordsMatchRegexes: regexExpressions [ memoryLogger recordings with: regexExpressions do: [ :record :regexExpression | | regexWithTimestamp | - regexWithTimestamp := '\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}\.\d+(\+|-)(\d+\:\d+) <1s>' expandMacrosWith: + regexWithTimestamp := '\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}(\.\d+)?(\+|-)(\d+\:\d+) <1s>' expandMacrosWith: regexExpression. testCase assert: ( record printString matchesRegex: regexWithTimestamp ) description: From 43c9f468f69189449928869f0a21139e950fe581 Mon Sep 17 00:00:00 2001 From: mreyes Date: Tue, 25 Jun 2024 16:55:13 -0300 Subject: [PATCH 4/8] :wrench: delete unnecessary stop calls for loggers --- source/Bell-SUnit/LoggingAsserter.class.st | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/Bell-SUnit/LoggingAsserter.class.st b/source/Bell-SUnit/LoggingAsserter.class.st index ad06384..1ded727 100644 --- a/source/Bell-SUnit/LoggingAsserter.class.st +++ b/source/Bell-SUnit/LoggingAsserter.class.st @@ -59,9 +59,4 @@ LoggingAsserter >> runMemoryLoggerDuring: aBlockClosure [ LoggingAsserter >> stopLoggers [ memoryLogger reset. - - StandardStreamLogger onStandardOutput stop. - StandardStreamLogger onStandardError stop. - StandardErrorStructuredLogger onStandardOutput stop. - StandardErrorStructuredLogger onStandardError stop ] From 24c7d68a48f2805ecc0d4e5c99b6b5789277fc7c Mon Sep 17 00:00:00 2001 From: mreyes Date: Wed, 26 Jun 2024 12:26:06 -0300 Subject: [PATCH 5/8] :wrench: move timestamp regex validation from bell to hyperspace --- source/Bell-SUnit/LoggingAsserter.class.st | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/source/Bell-SUnit/LoggingAsserter.class.st b/source/Bell-SUnit/LoggingAsserter.class.st index 1ded727..5567c04 100644 --- a/source/Bell-SUnit/LoggingAsserter.class.st +++ b/source/Bell-SUnit/LoggingAsserter.class.st @@ -31,15 +31,12 @@ LoggingAsserter >> assertLogRecordsMatch: expectedLogEntries [ { #category : #asserting } LoggingAsserter >> assertLogRecordsMatchRegexes: regexExpressions [ - memoryLogger recordings with: regexExpressions do: [ :record :regexExpression | - | regexWithTimestamp | - - regexWithTimestamp := '\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}(\.\d+)?(\+|-)(\d+\:\d+) <1s>' expandMacrosWith: - regexExpression. - testCase assert: ( record printString matchesRegex: regexWithTimestamp ) - description: - ( '<1s> does not match <2s>' expandMacrosWith: record printString with: regexWithTimestamp ) - ] + memoryLogger recordings with: regexExpressions do: [ :record :regexExpression | + testCase + assert: ( record printString matchesRegex: regexExpression ) + description: + ( '<1s> does not match <2s>' expandMacrosWith: record printString with: regexExpression ) + ] ] { #category : #initialization } From e0366d7540f86091c95945a9ffb71cf2f5576b5f Mon Sep 17 00:00:00 2001 From: mreyes Date: Wed, 26 Jun 2024 12:27:33 -0300 Subject: [PATCH 6/8] :wrench: add regex assertion tests to LogRecordTest suite --- .../Bell-Logging-Tests/LogRecordTest.class.st | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/source/Bell-Logging-Tests/LogRecordTest.class.st b/source/Bell-Logging-Tests/LogRecordTest.class.st index 4510c99..01150f5 100644 --- a/source/Bell-Logging-Tests/LogRecordTest.class.st +++ b/source/Bell-Logging-Tests/LogRecordTest.class.st @@ -18,6 +18,14 @@ LogRecordTest >> runMemoryLoggerDuring: aBlock assertingLogRecordsMatch: expecte assertLogRecordsMatch: expectedLogEntries ] +{ #category : #private } +LogRecordTest >> runMemoryLoggerDuring: aBlock assertingLogRecordsMatchRegexes: expectedLogEntries [ + + loggingAsserter + runMemoryLoggerDuring: aBlock; + assertLogRecordsMatchRegexes: expectedLogEntries +] + { #category : #running } LogRecordTest >> setUp [ @@ -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 [ From 8e17bbe8504f5cb81bc80409b705c3382c0923b3 Mon Sep 17 00:00:00 2001 From: mreyes Date: Wed, 26 Jun 2024 15:35:50 -0300 Subject: [PATCH 7/8] :wrench: add regex dependency --- rowan/components/Dependent-SUnit-Extensions.ston | 4 +++- rowan/projects/Regex.ston | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 rowan/projects/Regex.ston 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 From 20149c87ce994fd099b91dfcd55447cfbc12f3bf Mon Sep 17 00:00:00 2001 From: mreyes Date: Thu, 27 Jun 2024 17:37:13 -0300 Subject: [PATCH 8/8] :wrench: rename parameters from log records assertions --- source/Bell-Logging-Tests/LogRecordTest.class.st | 8 ++++---- source/Bell-SUnit/LoggingAsserter.class.st | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/Bell-Logging-Tests/LogRecordTest.class.st b/source/Bell-Logging-Tests/LogRecordTest.class.st index 01150f5..a149395 100644 --- a/source/Bell-Logging-Tests/LogRecordTest.class.st +++ b/source/Bell-Logging-Tests/LogRecordTest.class.st @@ -11,19 +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: expectedLogEntries [ +LogRecordTest >> runMemoryLoggerDuring: aBlock assertingLogRecordsMatchRegexes: aRegexCollection [ loggingAsserter runMemoryLoggerDuring: aBlock; - assertLogRecordsMatchRegexes: expectedLogEntries + assertLogRecordsMatchUsing: aRegexCollection ] { #category : #running } diff --git a/source/Bell-SUnit/LoggingAsserter.class.st b/source/Bell-SUnit/LoggingAsserter.class.st index 5567c04..cb342b8 100644 --- a/source/Bell-SUnit/LoggingAsserter.class.st +++ b/source/Bell-SUnit/LoggingAsserter.class.st @@ -22,16 +22,16 @@ 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 >> assertLogRecordsMatchRegexes: regexExpressions [ +LoggingAsserter >> assertLogRecordsMatchUsing: aRegexCollection [ - memoryLogger recordings with: regexExpressions do: [ :record :regexExpression | + memoryLogger recordings with: aRegexCollection do: [ :record :regexExpression | testCase assert: ( record printString matchesRegex: regexExpression ) description: