Skip to content

Commit

Permalink
Merge branch '174-mocked-sections-and-paragraphs-cannot-handle-period…
Browse files Browse the repository at this point in the history
…s-in-bodies' of https://github.com/openmainframeproject/cobol-check into 174-mocked-sections-and-paragraphs-cannot-handle-periods-in-bodies
  • Loading branch information
issacto committed Jul 31, 2023
2 parents 36ec25c + 8aeed61 commit 0994d17
Show file tree
Hide file tree
Showing 22 changed files with 440 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Mock SQL tables
- Mock batch file I/O

## \[0.2.8\] 2023-05-16 - Unreleased
### Implemented
- Proper handling of END-EXEC without trailing period in WORKING-STORAGE

## \[0.2.7\] 2023-03-21 - Unreleased
### Implemented
- EXPECT now properly handles variable subscription without a space delimiter (EXPECT varibable(idx) TO BE 1)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ As of March 2022 we could use help with:

## Downloads

Version 0.2.7 pre-release is available!
Version 0.2.8 pre-release is available!

[//]: # (- Find the download on the project home page on the [Neo Pragma site](https://neopragma.com/projects/cobol-check/).)
- Find distributions here: [Cobol Check Ditributions](https://github.com/openmainframeproject/cobol-check/blob/main/build/distributions).
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id 'jacoco'
}

def productVersion = '0.2.7'
def productVersion = '0.2.8'
def productName = 'cobol-check'
group = 'org.openmainframeproject'
description = 'Unit testing framework for Cobol'
Expand Down
Binary file added build/distributions/cobol-check-0.2.8.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion scripts/windows_gnucobol_run_tests.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ rem
rem Assumptions:
rem
rem GnuCOBOL 3.+ is installed and on the path. Its executable or alias or symlink is named "cobc".
cobc -x %* && %~dpn1
cobc -x %* && "%~dpn1"
21 changes: 21 additions & 0 deletions src/main/cobol/RETURNCODE.CBL
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. RETURNCODE.
/****************************************************************
* Program to exercise different mock statements and edge cases.
*****************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 FILLER.
05 VALUE-1 PIC X(80).
05 VALUE-2 PIC X(80).

PROCEDURE DIVISION.

000-MAKE-CALL.
MOVE "arg1" to VALUE-1
MOVE "arg2" to VALUE-2
CALL 'PROG1'
.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private void processCommandLineArgumentArray(String[] args) {

public void loadArgProgramPaths(){
String applicationSourceDirectory = Config.getApplicationSourceDirectoryPathString();
boolean isProgramSpecified = false;
for (OptionKey optionKey : options.keySet()) {
if (optionKey.shortKey.equals(Constants.PROGRAMS_OPTION) || optionKey.longKey.equals(Constants.PROGRAMS_OPTION)) {
String programArgs = options.get(optionKey).argumentValue;
Expand All @@ -152,8 +153,13 @@ public void loadArgProgramPaths(){
newValue += "|";
}
options.get(optionKey).argumentValue = newValue.substring(0, newValue.length()-1);
if(!programArgs.equals("")) isProgramSpecified = true;
}
}
if(!isProgramSpecified){
// return error when no program is passed
throw new CommandLineArgumentException(Messages.get("ERR030"));
}
}

private OptionValue lookupOption(String requestedOption) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public List<String> getParsedTestSuiteLines(BufferedReader testSuiteReader,
numericFields = numericFieldsList;
String testSuiteToken = getNextTokenFromTestSuite(testSuiteReader);
while (testSuiteToken != null) {

if (!testSuiteToken.startsWith(Constants.QUOTE) && !testSuiteToken.startsWith(Constants.APOSTROPHE)) {
testSuiteToken = testSuiteToken.toUpperCase(Locale.ROOT);
}
Expand All @@ -184,6 +185,8 @@ public List<String> getParsedTestSuiteLines(BufferedReader testSuiteReader,
testSuiteToken = getNextTokenFromTestSuite(testSuiteReader);
continue;
}



boolean cobolTokenIsFieldName = (expectInProgress || expectQualifiedName || expectMockIdentifier
|| (expectMockArguments && !expectUsing));
Expand All @@ -200,6 +203,24 @@ public List<String> getParsedTestSuiteLines(BufferedReader testSuiteReader,
continue;
}

if (expectMockArguments && !expectUsing
&& (CobolVerbs.isCobolVerb(testSuiteToken)|| testSuiteToken.equals("END-MOCK"))) {
// In this case we expected cobol verbs and stop mock arguments
// update the keyword as fieldname was assumed
expectMockArguments = false;
expectUsing = false;
if (!verifyInProgress) {
ignoreCobolStatementAndFieldNameKeyAction = true;
handleEndOfMockStatement(testSuiteReader, testSuiteToken, false);
}
if(testSuiteToken.equals("END-MOCK") ){
testSuiteToken = getNextTokenFromTestSuite(testSuiteReader);
}
continue;
}



if (!testSuiteErrorLog.checkExpectedTokenSyntax(keyword, testSuiteToken, currentTestSuiteRealFile,
fileLineNumber, fileLineIndexNumber)) {
testSuiteToken = getNextTokenFromTestSuite(testSuiteReader);
Expand Down Expand Up @@ -318,6 +339,8 @@ public List<String> getParsedTestSuiteLines(BufferedReader testSuiteReader,
addTestCodeForAssertion(parsedTestSuiteLines, numericFields);
toBeInProgress = false;
}


if (expectMockIdentifier) {
expectMockIdentifier = false;
ignoreCobolStatementAndFieldNameKeyAction = true;
Expand Down Expand Up @@ -345,22 +368,24 @@ public List<String> getParsedTestSuiteLines(BufferedReader testSuiteReader,
if (!expectUsing) {
currentLineContainsArgument = true;
ignoreCobolStatementAndFieldNameKeyAction = true;

if (verifyInProgress)
currentVerify.addArgument(getCallArgument(currentMockArgument, testSuiteToken));
else
currentMock.addArgument(getCallArgument(currentMockArgument, testSuiteToken));

currentMockArgument = "";
if (testSuiteToken.endsWith(","))
break;
}
// Contains no arguments or all arguments has been added
expectMockArguments = false;
expectUsing = false;
if (!verifyInProgress) {
ignoreCobolStatementAndFieldNameKeyAction = true;
handleEndOfMockStatement(testSuiteReader, testSuiteToken, currentLineContainsArgument);

}else{
expectUsing = false;
expectMockArguments = false;
if (!verifyInProgress) {
ignoreCobolStatementAndFieldNameKeyAction = true;
handleEndOfMockStatement(testSuiteReader, testSuiteToken, currentLineContainsArgument);
}

}

}

if (verifyInProgress) {
Expand All @@ -374,6 +399,8 @@ public List<String> getParsedTestSuiteLines(BufferedReader testSuiteReader,
break;

case Constants.ALPHANUMERIC_LITERAL_KEYWORD:


if (expectTestsuiteName) {
expectTestsuiteName = false;
currentTestSuiteName = testSuiteToken;
Expand Down Expand Up @@ -618,7 +645,7 @@ public List<String> getParsedTestSuiteLines(BufferedReader testSuiteReader,
break;
}
if (CobolVerbs.isStartOrEndCobolVerb(testSuiteToken)) {
if (cobolStatementInProgress) {
if ( cobolStatementInProgress) {
addUserWrittenCobolStatement(parsedTestSuiteLines);
initializeCobolStatement();
}
Expand Down Expand Up @@ -830,6 +857,7 @@ private String getCallArgument(String referenceType, String value) {
outPut = ("REFERENCE " + value.replace(",", ""));
else
outPut = (referenceType + " " + value.replace(",", ""));

return outPut;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public static boolean isEndOfStatement(CobolLine currentLine, CobolLine nextMean
if (currentLine.getTrimmedString().endsWith(Constants.PERIOD)) {
return true;
}
if (currentLine.getTrimmedString().toUpperCase(Locale.ROOT).endsWith(Constants.END_EXEC_TOKEN)) {
return true;
}
if (containsOnlyPeriod(nextMeaningfulLine)){
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
.
==UT==INITIALIZE.
MOVE SPACES TO ==UT==FILE-INFORMATION
MOVE 4 to RETURN-CODE

.
==UT==END.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ ERR027 = ERR027: NumericFields.dataTypeOf() was called with empty fieldName.
ERR028 = ERR028: NumericFields.setDataTypeOf() was called with empty fieldName.
ERR029 = ERR029: NumericFields.setDataTypeOf() was called with null dataType.

ERR030 = ERR030: Command line missing program argument '-p programName' .


WRN001 = WRN001: No test suite directory for program %1$s was found under directory %2$s.
WRN002 = WRN002: No test suite files were found under directory %1$s.
WRN003 = WRN003: DirectoryNameMatcher caught IOException on file %1$s.
Expand Down
40 changes: 40 additions & 0 deletions src/test/cobol/MOCKTEST/MockCallTest.cut
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,46 @@
BY VALUE VALUE-2,
VALUE-3
HAPPENED 2 TIMES

TestCase "Call mock with content reference for arguments with one comma work"
MOCK CALL 'PROG3' USING
BY CONTENT VALUE-1,
BY VALUE VALUE-2
VALUE-3
MOVE "content" TO VALUE-1
MOVE "value" TO VALUE-2
MOVE "reference" TO VALUE-3
END-MOCK
PERFORM 800-MAKE-CALL
EXPECT VALUE-1 TO BE "content"
EXPECT VALUE-2 TO BE "value"
EXPECT VALUE-3 TO BE "reference"
VERIFY CALL 'PROG3' USING
BY CONTENT VALUE-1,
BY VALUE VALUE-2,
VALUE-3
HAPPENED 2 TIMES


TestCase "Call mock with content reference for arguments without comma work"
MOCK CALL 'PROG3' USING
BY CONTENT VALUE-1
BY VALUE VALUE-2
VALUE-3
MOVE "content" TO VALUE-1
MOVE "value" TO VALUE-2
MOVE "reference" TO VALUE-3
END-MOCK
PERFORM 800-MAKE-CALL
EXPECT VALUE-1 TO BE "content"
EXPECT VALUE-2 TO BE "value"
EXPECT VALUE-3 TO BE "reference"
VERIFY CALL 'PROG3' USING
BY CONTENT VALUE-1,
BY VALUE VALUE-2,
VALUE-3
HAPPENED 2 TIMES


TestCase "Paragraph mock is called and call mock is ignored"
MOCK CALL 'PROG3' USING
Expand Down
8 changes: 8 additions & 0 deletions src/test/cobol/RETURNCODE/ReturnCode-0.cut
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TestSuite "Test Return Code without GOBACK in MOCK "

TestCase "Return code should be 0"
MOCK CALL 'PROG1'
MOVE "Exit with return code 0" TO VALUE-1
END-MOCK
PERFORM 000-MAKE-CALL
EXPECT VALUE-1 TO BE "Exit with return code 0"
9 changes: 9 additions & 0 deletions src/test/cobol/RETURNCODE/ReturnCode-4.cut
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
TestSuite "Test Return Code with GOBACK in MOCK "

TestCase "Return code should be 4 (Should fail) "
MOCK CALL 'PROG1'
MOVE "Exit with return code 4" TO VALUE-1
GOBACK.
END-MOCK
PERFORM 000-MAKE-CALL
EXPECT VALUE-1 TO BE "Exit with return code 4"
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,26 @@ public void it_throws_when_no_value_is_passed_for_the_last_argument_and_it_requi
});
}

@Test
public void it_throws_when_program_argument_is_not_present() {
Throwable ex = assertThrows(CommandLineArgumentException.class, () -> {
ArgumentHandler argumentHandler = new ArgumentHandler(new String[] { },
optionSpec);
argumentHandler.loadArgProgramPaths();
});
assertEquals("ERR030: Command line missing program argument '-p programName' .",
ex.getMessage());
}

@Test
public void it_throws_when_program_argument_is_not_presen_and_has_other_argument() {
Throwable ex = assertThrows(CommandLineArgumentException.class, () -> {
ArgumentHandler argumentHandler = new ArgumentHandler(new String[] {"-c", "config.properties" },
optionSpec);
argumentHandler.loadArgProgramPaths();
});
assertEquals("ERR030: Command line missing program argument '-p programName' .",
ex.getMessage());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -854,5 +854,25 @@ public void it_registers_EXEC_CICS_as_stub() throws IOException {
assertTrue(testsRan);
}

@Test
public void it_handles_END_EXEC_without_terminating_period() throws IOException {
String str1 = " DATA DIVISION.";
String str2 = " WORKING-STORAGE SECTION.";
String str3 = " 01 FILLER.";
String str4 = " 05 WS-FIELD PIC 9(04).";
String str5 = " EXEC SQL";
String str6 = " SQL STUFF";
String str7 = " END-exec";
String str8 = " PROCEDURE DIVISION.";

Mockito.when(mockedReader.readLine()).thenReturn(str1, str2, str3, str4, str5, str6, str7, str8, null);

while (interpreterController.interpretNextLine() != null){
interpreterController.interpretNextLine();
}

assertTrue(interpreterController.didLineJustEnter(Constants.PROCEDURE_DIVISION));

}

}
Loading

0 comments on commit 0994d17

Please sign in to comment.