Skip to content

Commit

Permalink
Merge pull request #238 from Gleethos/master
Browse files Browse the repository at this point in the history
Fix #237, where code blocks are missing their source code
  • Loading branch information
renatoathaydes authored Nov 14, 2022
2 parents 413e588 + 348002d commit bc95a47
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class HtmlReportCreator extends AbstractHtmlCreator<SpecData>

private writeBlockRowsFromCode( MarkupBuilder builder, cssClass, blockKind,
BlockCode code, text, int failureLineNumber ) {
def statements = code.statements
def statements = ( blockKind == 'where' ? [] : code.statements )
def lineNumbers = code.lineNumbers

if ( text ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ class SpecSourceCodeCollector implements AutoCloseable {
return // don't add the text to the code
}
}

if ( label != 'where' ) { // the where statement must not be added to the code in the report
specCode.addStatement( method, code, statement.lineNumber )
}
// All statements must be added to the code in the report
specCode.addStatement( method, code, statement.lineNumber )
}

private String lookupCode( Statement statement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,12 @@ class VividASTVisitor extends ClassCodeVisitorSupport {
void visitStatement( Statement node ) {
if ( visitStatements && node instanceof BlockStatement ) {
def stmts = ( node as BlockStatement ).statements
def waitForNextBlock = false
if ( stmts ) for ( statement in stmts ) {
if ( waitForNextBlock && !statement.statementLabel ) {
continue // skip statements in this block
} else {
waitForNextBlock = false
if ( stmts )
for ( statement in stmts ) {
codeCollector.add( statement )
}

codeCollector.add( statement )

if ( statement.statementLabel == 'where' ) {
waitForNextBlock = true
}
}
visitStatements = false
}

super.visitStatement( node )
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templateReportCreator/spec-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Time: $totalTime
%>
* ${block.kind} ${block.text}
<%
if ( block.sourceCode ) {
if ( block.sourceCode && block.kind != 'Where:' ) {
out << "\n```\n"
block.sourceCode.each { codeLine ->
out << codeLine << '\n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class VividAstInspectorSpec extends Specification {
blocks[ 1 ].statements.isEmpty()
blocks[ 2 ].statements.isEmpty()
blocks[ 3 ].statements == [ 'x == y' ]
blocks[ 4 ].statements.isEmpty() // where statements are not captured
blocks[ 4 ].statements == [ "x | y", "'a' | 'a'", "'b' | 'c'" ]

and: 'The blocks should have the expected label and text'
blocks[ 0 ].label == 'given'
Expand Down Expand Up @@ -282,8 +282,8 @@ class VividAstInspectorSpec extends Specification {
and: 'The inspector should be able to provide the source code for each block'
blocks[ 0 ].statements == [ 'x < y' ]

and: 'The where block is not captured'
blocks[ 1 ].statements.isEmpty()
and: 'The where block is captured'
blocks[ 1 ].statements == ['x | y', '20 | 30', '100 | 2000']

and: 'The cleanup block is captured'
blocks[ 2 ].statements == [ 'x = null' ]
Expand Down

0 comments on commit bc95a47

Please sign in to comment.