Skip to content

Commit

Permalink
Fix using expander not updating data structure in InterpreterController
Browse files Browse the repository at this point in the history
Signed-off-by: Rune Christensen <[email protected]>
  • Loading branch information
Rune-Christensen authored and Rune Christensen committed Oct 19, 2023
1 parent 55f3a2c commit 67a7859
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 47 deletions.
9 changes: 5 additions & 4 deletions config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ cobolcheck.stub.comment.tag = null
cobolcheck.decimalPointIsComma = false

#---------------------------------------------------------------------------------------------------------------------
# If the source program contains rules as the first line follwed by CBL, the given value will be appended
# If the source program contains rules as the first line followed by CBL, the given value will be appended
# to this.
# If no CBL is found in source, it will be added along with the given value
# default is null, which will make no changes.
Expand All @@ -64,9 +64,10 @@ cobolcheck.test.program.path = ./
cobolcheck.test.program.name = CC##99.CBL

#---------------------------------------------------------------------------------------------------------------------
# If the given value is true, then the test with unmocked calls will be echoed and test summary
# will contain the number of unmocked calls.
# Default: true
# Indicates whether or not report should be thrown, if COBOL Check encounters an unmocked call
# When false, no action is taken, when encountering unmocked calls.
# When true, COBOL Check will report the unmocked calls, and the test summary will contain the number of unmocked calls.
# Default: false
#---------------------------------------------------------------------------------------------------------------------
cobolcheck.test.unmockcall.display = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ private void updateLineRepository(CobolLine line) throws IOException {
extractedCopyBook = lineRepository.addExpandedCopyDB2Statements(reader.readStatementAsOneLine());
for (int i = 0; i < extractedCopyBook.size(); i++) {
CobolLine cobolLine = new CobolLine(extractedCopyBook.get(i), tokenExtractor);
List<CobolLine> currentStatement = new ArrayList<>();
currentStatement.add(cobolLine);
this.currentDataStructure = updateCurrentDataStructure(currentStatement, currentDataStructure);
updateNumericFields(cobolLine);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1125,11 +1125,11 @@ boolean fieldIsANumericDataType(String fieldNameForExpect) {
}
}
}

return numericFields.dataTypeOf(fieldNameForExpect) == DataType.PACKED_DECIMAL
|| (numericFields.dataTypeOf(fieldNameForExpect) == DataType.FLOATING_POINT)
|| (numericFields.dataTypeOf(fieldNameForExpect) == DataType.BINARY)
|| (numericFields.dataTypeOf(fieldNameForExpect) == DataType.DISPLAY_NUMERIC);
DataType fieldNameDataType = numericFields.dataTypeOf(fieldNameForExpect);
return fieldNameDataType== DataType.PACKED_DECIMAL
|| (fieldNameDataType == DataType.FLOATING_POINT)
|| (fieldNameDataType == DataType.BINARY)
|| (fieldNameDataType == DataType.DISPLAY_NUMERIC);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class TestSuiteParserController {
private List<String> parsedTestSuiteLines;

// The boilerplate copybooks for cobol-check test code inserted into Working-Storage and Procedure.
// The names are a throwback to the proof-of-concept project, cobol-unit-test. Might change in future.
// The names are a throwback to the proof-of-concept project, cobol-unit-test. Might change in the future.
private static final String workingStorageCopybookFilename = "CCHECKWS.CPY";
private static final String procedureDivisionResultCopybookFilename = "CCHECKRESULTPD.CPY";
private static final String procedureDivisionParagraphCopybookFilename = "CCHECKPARAGRAPHSPD.CPY";
Expand Down Expand Up @@ -241,13 +241,15 @@ public List<String> generateCobolLinesForUnmockedCalls() {
cobolLines.add(" UT-PROCESS-UNMOCK-CALL.");
if(Config.getDisplayUnMockedCalls()) {
String line1 = " Add 1 to %sNUMBER-UNMOCK-CALL";
String line2 = " display \"Call not mocked in testcase \" %1$sTEST-CASE-NAME \" in testsuite \" %1$sTEST-SUITE-NAME";
String line3 = " display \"All used calls should be mocked, to ensure the unit test has control over input data\"";
String line2 = " display \"Call not mocked in testcase: \" %1$sTEST-CASE-NAME ";
String line3 = " display \" in testsuite: \" %1$sTEST-SUITE-NAME";
String line4 = " display \"All used calls should be mocked, to ensure the unit test has control over input data\"";

String testCodePrefix = Config.getTestCodePrefix();
cobolLines.add(String.format(line1, testCodePrefix));
cobolLines.add(String.format(line2, testCodePrefix));
cobolLines.add(line3);
cobolLines.add(String.format(line3, testCodePrefix));
cobolLines.add(line4);
}
cobolLines.add(" CONTINUE");
cobolLines.add(" .");
Expand Down Expand Up @@ -281,13 +283,6 @@ public List<String> getEndEvaluateLine(){
return lines;
}

public List<String> getContinueLine(){
List<String> lines = new ArrayList<>();
lines.add(mockGenerator.getContinueLine());
CobolGenerator.addStartAndEndTags(lines);
return lines;
}

public void logUnusedMocks(){
testSuiteErrorLog.logUnusedMocks(mockRepository.getMocks());
}
Expand All @@ -302,7 +297,6 @@ public void logUnusedMocks(){
*/
public List<String> getBoilerplateCodeFromCopybooks(String copybookFilename) throws IOException {
List<String> lines = new ArrayList<>();
boolean isComma = Config.isDecimalPointComma();
String path = Constants.COBOLCHECK_COPYBOOK_DIRECTORY + copybookFilename;
InputStream is = this.getClass().getResourceAsStream(path);
BufferedReader secondarySourceBufferedReader = new BufferedReader(new InputStreamReader(is));
Expand Down
59 changes: 45 additions & 14 deletions src/test/java/org/openmainframeproject/cobolcheck/ExpanderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,37 @@ public void it_inserts_code_correctly_when_there_are_some_unmock_calls_and_confi
Config.changeProperty("cobolcheck.test.unmockcall.display", "true");
}

@Test
public void variable_before_exec_sql_include_is_evaluated_as_text() throws IOException {
String s1 = " ID DIVISION.";
String s2 = " PROGRAM-ID. TEST.";
String s3 = " ENVIRONMENT DIVISION.";
String s4 = " DATA DIVISION.";
String s5 = " WORKING-STORAGE SECTION.";
String s6 = " 01 WS-FIELD-1 PIC X(80).";
String s7 = " EXEC SQL INCLUDE SQLCA END-EXEC. ";
String s8 = " PROCEDURE DIVISION.";
String s9 = " 000-START SECTION.";
String s10 = " MOVE \"Value1\" to WS-FIELD-1";
String s11 = " EXIT SECTION";
String s12 = " .";

String t1 = " TestSuite \"Basic test\"";
String t2 = " TestCase \"Basic test\"";
String t3 = " PERFORM 000-START";
String t4 = " EXPECT WS-FIELD-1 TO BE \"Value1\"";

Mockito.when(mockedInterpreterReader.readLine()).thenReturn(s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, null);
Mockito.when(mockedParserReader.readLine()).thenReturn(t1, t2, t3, t4, null);

generator = new Generator(interpreterController, writerController, testSuiteParserController);

List<String> actual = Utilities.getTrimmedList(Utilities.removeBoilerPlateCode(writer.toString(), boilerPlateTags));
String[] actualArray = actual.toArray(new String[0]);

assertEquals(" MOVE WS-FIELD-1 TO UT-ACTUAL", actualArray[49]);
}

private String expected1 =
" WORKING-STORAGE SECTION. " + Constants.NEWLINE +
" *EXEC SQL INCLUDE TEXEM END-EXEC. " + Constants.NEWLINE +
Expand Down Expand Up @@ -307,8 +338,8 @@ public void it_inserts_code_correctly_when_there_are_some_unmock_calls_and_confi
" " + Constants.NEWLINE +
" UT-PROCESS-UNMOCK-CALL. " + Constants.NEWLINE +
" Add 1 to UT-NUMBER-UNMOCK-CALL " + Constants.NEWLINE +
" display \"Call not mocked in testcase \" UT-TEST-CASE-NAME \" in " + Constants.NEWLINE +
" - \" testsuite \" UT-TEST-SUITE-NAME " + Constants.NEWLINE +
" display \"Call not mocked in testcase: \" UT-TEST-CASE-NAME " + Constants.NEWLINE +
" display \" in testsuite: \" UT-TEST-SUITE-NAME " + Constants.NEWLINE +
" display \"All used calls should be mocked, to ensure the unit " + Constants.NEWLINE +
" - \"test has control over input data\" " + Constants.NEWLINE +
" CONTINUE " + Constants.NEWLINE +
Expand Down Expand Up @@ -350,8 +381,8 @@ public void it_inserts_code_correctly_when_there_are_some_unmock_calls_and_confi
" " + Constants.NEWLINE +
" UT-PROCESS-UNMOCK-CALL. " + Constants.NEWLINE +
" Add 1 to UT-NUMBER-UNMOCK-CALL " + Constants.NEWLINE +
" display \"Call not mocked in testcase \" UT-TEST-CASE-NAME \" in " + Constants.NEWLINE +
" - \" testsuite \" UT-TEST-SUITE-NAME " + Constants.NEWLINE +
" display \"Call not mocked in testcase: \" UT-TEST-CASE-NAME " + Constants.NEWLINE +
" display \" in testsuite: \" UT-TEST-SUITE-NAME " + Constants.NEWLINE +
" display \"All used calls should be mocked, to ensure the unit " + Constants.NEWLINE +
" - \"test has control over input data\" " + Constants.NEWLINE +
" CONTINUE " + Constants.NEWLINE +
Expand Down Expand Up @@ -397,8 +428,8 @@ public void it_inserts_code_correctly_when_there_are_some_unmock_calls_and_confi
" " + Constants.NEWLINE +
" UT-PROCESS-UNMOCK-CALL. " + Constants.NEWLINE +
" Add 1 to UT-NUMBER-UNMOCK-CALL " + Constants.NEWLINE +
" display \"Call not mocked in testcase \" UT-TEST-CASE-NAME \" in " + Constants.NEWLINE +
" - \" testsuite \" UT-TEST-SUITE-NAME " + Constants.NEWLINE +
" display \"Call not mocked in testcase: \" UT-TEST-CASE-NAME " + Constants.NEWLINE +
" display \" in testsuite: \" UT-TEST-SUITE-NAME " + Constants.NEWLINE +
" display \"All used calls should be mocked, to ensure the unit " + Constants.NEWLINE +
" - \"test has control over input data\" " + Constants.NEWLINE +
" CONTINUE " + Constants.NEWLINE +
Expand Down Expand Up @@ -443,9 +474,9 @@ public void it_inserts_code_correctly_when_there_are_some_unmock_calls_and_confi
" " + Constants.NEWLINE +
" UT-PROCESS-UNMOCK-CALL. " + Constants.NEWLINE +
" Add 1 to UT-NUMBER-UNMOCK-CALL " + Constants.NEWLINE +
" display \"Call not mocked in testcase \" UT-TEST-CASE-NAME \" in " + Constants.NEWLINE +
" - \" testsuite \" UT-TEST-SUITE-NAME " + Constants.NEWLINE +
" display \"All used calls should be mocked, to ensure the unit " + Constants.NEWLINE +
" display \"Call not mocked in testcase: \" UT-TEST-CASE-NAME " + Constants.NEWLINE +
" display \" in testsuite: \" UT-TEST-SUITE-NAME " + Constants.NEWLINE +
" display \"All used calls should be mocked, to ensure the unit " + Constants.NEWLINE +
" - \"test has control over input data\" " + Constants.NEWLINE +
" CONTINUE " + Constants.NEWLINE +
" . " + Constants.NEWLINE +
Expand Down Expand Up @@ -489,8 +520,8 @@ public void it_inserts_code_correctly_when_there_are_some_unmock_calls_and_confi
" " + Constants.NEWLINE +
" UT-PROCESS-UNMOCK-CALL. " + Constants.NEWLINE +
" Add 1 to UT-NUMBER-UNMOCK-CALL " + Constants.NEWLINE +
" display \"Call not mocked in testcase \" UT-TEST-CASE-NAME \" in " + Constants.NEWLINE +
" - \" testsuite \" UT-TEST-SUITE-NAME " + Constants.NEWLINE +
" display \"Call not mocked in testcase: \" UT-TEST-CASE-NAME " + Constants.NEWLINE +
" display \" in testsuite: \" UT-TEST-SUITE-NAME " + Constants.NEWLINE +
" display \"All used calls should be mocked, to ensure the unit " + Constants.NEWLINE +
" - \"test has control over input data\" " + Constants.NEWLINE +
" CONTINUE " + Constants.NEWLINE +
Expand Down Expand Up @@ -539,9 +570,9 @@ public void it_inserts_code_correctly_when_there_are_some_unmock_calls_and_confi
" " + Constants.NEWLINE +
" UT-PROCESS-UNMOCK-CALL. " + Constants.NEWLINE +
" Add 1 to UT-NUMBER-UNMOCK-CALL " + Constants.NEWLINE +
" display \"Call not mocked in testcase \" UT-TEST-CASE-NAME \" in " + Constants.NEWLINE +
" - \" testsuite \" UT-TEST-SUITE-NAME " + Constants.NEWLINE +
" display \"All used calls should be mocked, to ensure the unit " + Constants.NEWLINE +
" display \"Call not mocked in testcase: \" UT-TEST-CASE-NAME " + Constants.NEWLINE +
" display \" in testsuite: \" UT-TEST-SUITE-NAME " + Constants.NEWLINE +
" display \"All used calls should be mocked, to ensure the unit " + Constants.NEWLINE +
" - \"test has control over input data\" " + Constants.NEWLINE +
" CONTINUE " + Constants.NEWLINE +
" . " + Constants.NEWLINE +
Expand Down
Loading

0 comments on commit 67a7859

Please sign in to comment.