Skip to content

Commit

Permalink
Preserve linenumbers from original source to enable a more robust met…
Browse files Browse the repository at this point in the history
…hod to generate code coverage reports

Signed-off-by: Brian Wildt <[email protected]>
  • Loading branch information
WildtBrian committed Sep 9, 2024
1 parent 65237f7 commit e120dc1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public String interpretNextLine() {
}

// Current line might change from when it was originally read
return reader.getCurrentLine().getUnNumberedString();
return reader.getCurrentLine().getOriginalString();
}

public void closeReader() {
Expand Down Expand Up @@ -606,7 +606,7 @@ public void removeSectionOrParagraphLines(){
public void addSectionOrParagraphLine(){
if(Interpreter.shouldLineBeStubbed(reader.getCurrentLine(), reader.getState()))
sectionOrParagraph.addLine(StringHelper.stubLine(reader.getCurrentLine().getUnNumberedString(), stubTag));
else sectionOrParagraph.addLine(reader.getCurrentLine().getUnNumberedString());
else sectionOrParagraph.addLine(reader.getCurrentLine().getOriginalString());
}

public void addSectionOrParagraphLine(String line){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,6 @@ public class CobolGenerator {



static List<String> generateSectionLines(String identifier, List<String> commentLines, List<String> bodyLines){
List<String> lines = new ArrayList<>();
lines.add(String.format(SECTION_HEADER_FORMAT, identifier));
if (commentLines != null)
lines.addAll(commentLines);
if (bodyLines != null) {
lines.addAll(bodyLines);
// Check if the last line in bodyLines ends with a period
if (!bodyLines.get(bodyLines.size() - 1).endsWith(".")) {
lines.add(ENDING_PERIOD);
}
} else {
// If bodyLines is null, add ENDING_PERIOD
lines.add(ENDING_PERIOD);
}
return lines;
}

static List<String> generateParagraphLines(String identifier, List<String> commentLines, List<String> bodyLines){
List<String> lines = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ private String tryInsertEndEvaluateAtMockedCompomentEnd(String sourceLine) throw
}
}
return sourceLine;

}


/**
* Writes the given line to the output file. If a multiline statement has been read, this will
* be written instead (this statement will include the line). Comments out lines and statements
Expand Down Expand Up @@ -248,6 +250,10 @@ private void writeWhenOtherSectionOrParagraph(String sourceLine) throws IOExcep
private void echoingSourceLineToOutput(String sourceLine){
try{
if(interpreter.isInsideSectionOrParagraphMockBody()){
// Avoid giving mocked section ending period line numbers, as they would be duplicates
if (sourceLine.length() > 6 && sourceLine.substring(6).trim().equals(".")) {
sourceLine = " " + sourceLine.substring(6);
}
interpreter.addSectionOrParagraphLine();
}
sourceLine = tryInsertEndEvaluateAtMockedCompomentEnd(sourceLine);
Expand Down

0 comments on commit e120dc1

Please sign in to comment.