diff --git a/config.properties b/config.properties index 6fbb2647..97f2523d 100644 --- a/config.properties +++ b/config.properties @@ -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. @@ -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 diff --git a/src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/InterpreterController.java b/src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/InterpreterController.java index 6b2ee2b4..79b390bc 100644 --- a/src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/InterpreterController.java +++ b/src/main/java/org/openmainframeproject/cobolcheck/features/interpreter/InterpreterController.java @@ -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 currentStatement = new ArrayList<>(); + currentStatement.add(cobolLine); + this.currentDataStructure = updateCurrentDataStructure(currentStatement, currentDataStructure); updateNumericFields(cobolLine); } } diff --git a/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParser.java b/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParser.java index c5158291..cbd3d50e 100644 --- a/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParser.java +++ b/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParser.java @@ -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); } /** diff --git a/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParserController.java b/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParserController.java index 33fec07c..7953bdcc 100644 --- a/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParserController.java +++ b/src/main/java/org/openmainframeproject/cobolcheck/features/testSuiteParser/TestSuiteParserController.java @@ -30,7 +30,7 @@ public class TestSuiteParserController { private List 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"; @@ -241,13 +241,15 @@ public List 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(" ."); @@ -281,13 +283,6 @@ public List getEndEvaluateLine(){ return lines; } - public List getContinueLine(){ - List lines = new ArrayList<>(); - lines.add(mockGenerator.getContinueLine()); - CobolGenerator.addStartAndEndTags(lines); - return lines; - } - public void logUnusedMocks(){ testSuiteErrorLog.logUnusedMocks(mockRepository.getMocks()); } @@ -302,7 +297,6 @@ public void logUnusedMocks(){ */ public List getBoilerplateCodeFromCopybooks(String copybookFilename) throws IOException { List 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)); diff --git a/src/test/java/org/openmainframeproject/cobolcheck/ExpanderTest.java b/src/test/java/org/openmainframeproject/cobolcheck/ExpanderTest.java index bb141a30..eec031ca 100644 --- a/src/test/java/org/openmainframeproject/cobolcheck/ExpanderTest.java +++ b/src/test/java/org/openmainframeproject/cobolcheck/ExpanderTest.java @@ -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 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 + @@ -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 + @@ -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 + @@ -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 + @@ -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 + @@ -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 + @@ -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 + diff --git a/src/test/java/org/openmainframeproject/cobolcheck/MockIT.java b/src/test/java/org/openmainframeproject/cobolcheck/MockIT.java index 19991449..825d5082 100644 --- a/src/test/java/org/openmainframeproject/cobolcheck/MockIT.java +++ b/src/test/java/org/openmainframeproject/cobolcheck/MockIT.java @@ -288,8 +288,8 @@ public void it_inserts_call_mocks_without_commas_correctly() throws IOException " " + 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 + @@ -415,9 +415,9 @@ public void it_inserts_call_mocks_without_commas_correctly() throws IOException " " + 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 + @@ -600,8 +600,8 @@ public void it_inserts_call_mocks_without_commas_correctly() throws IOException " " + 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 + @@ -698,9 +698,9 @@ public void it_inserts_call_mocks_without_commas_correctly() throws IOException " " + 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 + diff --git a/vs-code-extension/Cobol-check/config.properties b/vs-code-extension/Cobol-check/config.properties index e8d74cd5..3780658f 100644 --- a/vs-code-extension/Cobol-check/config.properties +++ b/vs-code-extension/Cobol-check/config.properties @@ -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. @@ -63,6 +63,14 @@ cobolcheck.test.program.path = ./ #--------------------------------------------------------------------------------------------------------------------- cobolcheck.test.program.name = CC##99.CBL +#--------------------------------------------------------------------------------------------------------------------- +# 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 + #--------------------------------------------------------------------------------------------------------------------- # Path for the generated testsuite parse error log # Default: ./ @@ -147,7 +155,7 @@ application.source.filename.suffix = CBL,cbl,COB,cob # If application copybook filenames have a suffix, specify it here without the period or dot # e.g. application.copybook.filename.suffix = CBL #--------------------------------------------------------------------------------------------------------------------- -application.copybook.filename.suffix = CBL,cbl,COB,cob +application.copybook.filename.suffix = CBL,cbl,COB,cob,CPY,cpy #--------------------------------------------------------------------------------------------------------------------- # Optional override of system default Locale for log messages and exception messages.