Skip to content

Commit

Permalink
Merge pull request #347 from openmainframeproject/Developer
Browse files Browse the repository at this point in the history
Merge DEV to MAIN
  • Loading branch information
SMoRG75 authored Jun 10, 2024
2 parents 4900510 + 45d168f commit 890de4c
Show file tree
Hide file tree
Showing 29 changed files with 488 additions and 362 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/VerifyAction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04, windows-latest, macos-latest]
java-version: [8, 11]
java-version: [11]

steps:
- uses: actions/checkout@v3
- name: set up JDK 8
- name: set up JDK 11
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java-version }}
Expand All @@ -27,4 +27,4 @@ jobs:
- name: Tests
run: ./gradlew clean test
- name: Approval Tests
run: ./gradlew clean approvalTest
run: ./gradlew clean approvalTest
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ output/testResults.txt
approval-test-actual.txt
default.conf
null
ParserErrorLog.txt
ParserErrorLog.txt
/zapp.json
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Mock SQL tables
- Mock batch file I/O

## \[0.2.10\] 2024-05-13
### Not released
- Fixing bug in showing unit test result twice.

## \[0.2.9\] 2024-04-23
### Not released
- Better thread handling of the files processInput and processError


## \[0.2.8\] 2023-10-17
### Implemented
- Proper handling of END-EXEC without trailing period in WORKING-STORAGE
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.8 pre-release is available!
Version 0.2.10 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/tree/Developer/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.8'
def productVersion = '0.2.10'
def productName = 'cobol-check'
group = 'org.openmainframeproject'
description = 'Unit testing framework for Cobol'
Expand Down
Binary file added build/distributions/cobol-check-0.2.10.zip
Binary file not shown.
Binary file added build/distributions/cobol-check-0.2.9.zip
Binary file not shown.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import org.openmainframeproject.cobolcheck.services.Constants;
import org.openmainframeproject.cobolcheck.services.cobolLogic.*;
import org.openmainframeproject.cobolcheck.services.log.Log;
import org.openmainframeproject.cobolcheck.services.platform.Platform;
import org.openmainframeproject.cobolcheck.services.platform.PlatformLookup;
import org.openmainframeproject.cobolcheck.services.RunInfo;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -140,7 +143,7 @@ public boolean shouldCurrentLineBeStubbed() throws IOException {
if (reader.getState().isFlagSetFor(Constants.PROCEDURE_DIVISION)) {
if (Interpreter.shouldLineBeStubbed(reader.getCurrentLine(), reader.getState())) {
if (!insideSectionOrParagraphMockBody && Interpreter.endsInPeriod(reader.getCurrentLine()))
reader.putNextLine(" .");
reader.putNextLine(" .");
reader.putNextLine(" CONTINUE");
return true;
}
Expand All @@ -154,9 +157,11 @@ public boolean shouldCurrentLineBeStubbed() throws IOException {
public boolean shouldCurrentStatementBeStubbed() {
for (CobolLine line : reader.getCurrentStatement()) {
if (Interpreter.shouldLineBeStubbed(line, reader.getState())) {
if (!insideSectionOrParagraphMockBody && Interpreter.endsInPeriod(reader.getCurrentLine()))
reader.putNextLine(" .");
reader.putNextLine(" CONTINUE");
if (reader.getState().isFlagSetFor(Constants.PROCEDURE_DIVISION)){
if (!insideSectionOrParagraphMockBody && !Interpreter.endsInPeriod(reader.getCurrentLine()))
reader.putNextLine(" .");
reader.putNextLine(" CONTINUE");
}
return true;
}
}
Expand Down Expand Up @@ -445,17 +450,26 @@ private void updateLineRepository(CobolLine line) throws IOException {
lineRepository.addFileSectionStatement(line.getUnNumberedString());
}
}

if (reader.isFlagSet(Constants.WORKING_STORAGE_SECTION) &&
line.containsToken(Constants.EXEC_SQL_TOKEN) &&
(line.containsToken(Constants.INCLUDE)
|| reader.peekNextMeaningfulLine().containsToken(Constants.INCLUDE))) {
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);
Platform platform = PlatformLookup.get();
switch(platform){
case ZOS:
if (line.containsToken("SQLCA") || line.containsToken("SQLDA"))
return;
default:
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);
}
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ public Formatter(DataTransferObjectStyle dataTransferObjectStyle){
*/
public void parseText(String text, String testSuitePackage){
String[] lines = text.split(Constants.NEWLINE);

for (String line : lines){
if (line.trim().isEmpty() || line.startsWith("==="))
continue;


//Getting Test Suite name
if (line.trim().equalsIgnoreCase(testSuiteKeyword))
expectTestSuiteName = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ int launchProgram(ProcessLauncher launcher, String programPath,
int launchProgram(ProcessLauncher launcher, String programPath) throws InterruptedException {
if (launcher == null) return -1;
Process process = launcher.run(programPath);

int exitCode = 1;
exitCode = process.waitFor();
return exitCode;
return exitCode;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public void runTestProgram(String programName, boolean isLastRun) throws Interru
int exitCode = launcher.launchProgram(pLauncher, PathHelper.getTestSourceOutPath(), (proc) ->
processOutputWriter.writeProcessOutputToTestResultsFile(proc, Config.getTestResultFormat(),
Config.getTestResultFormatStyle(), programName, true, isLastRun));

if (processOutputWriter.writeWasSuccesful){
Log.info(Messages.get("INF011", processName, processOutputWriter.getTestResultsFilePath()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,76 @@ public void writeProcessOutputToTestResultsFile(Process proc, TestOutputFormat f
}

private void getProcessOut(Process proc) {
BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
processInput = "";
processError = "";

try{
String s = null;
while ((s = stdInput.readLine()) != null){
if (s != null)
processInput += s + Constants.NEWLINE;
StringBuilder processErrorBuilder = new StringBuilder();
final Object lock = new Object(); // For synchronizing access if necessary

Thread inputThread = new Thread(() -> {
Reader reader = new InputStreamReader(proc.getInputStream());
int maxBytesToReadFromCobolCheck = 25000;
char tempReadBuffer[] = new char[maxBytesToReadFromCobolCheck];
int writeOffset = 0;
int numberOfCharsRead = 0;
char cobolCheckOutput[] = null;
try {
synchronized (lock) {
numberOfCharsRead = reader.read(tempReadBuffer, writeOffset, maxBytesToReadFromCobolCheck);
if(numberOfCharsRead > 0) {
if(numberOfCharsRead == maxBytesToReadFromCobolCheck) {
int largeMaxBytesToReadFromCobolCheck = 100000;
char largeTempReadBuffer[] = new char[maxBytesToReadFromCobolCheck + largeMaxBytesToReadFromCobolCheck];
System.arraycopy(tempReadBuffer, 0, largeTempReadBuffer, 0, tempReadBuffer.length);
int largeNumberOfCharsRead = reader.read(largeTempReadBuffer, tempReadBuffer.length, largeMaxBytesToReadFromCobolCheck);
numberOfCharsRead += largeNumberOfCharsRead;
cobolCheckOutput = new char[numberOfCharsRead];
System.arraycopy(largeTempReadBuffer, 0, cobolCheckOutput, 0, numberOfCharsRead);
}
else {
cobolCheckOutput = new char[numberOfCharsRead];
System.arraycopy(tempReadBuffer, 0, cobolCheckOutput, 0, numberOfCharsRead);
}
}
reader.close();
}
} catch (IOException e) {
Log.warn(Messages.get("WRN007"));
}

while ((s = stdError.readLine()) != null){
if (s != null)
processError += s + Constants.NEWLINE;
processInput = "";
for (int i = 0; i < numberOfCharsRead; i++) {
processInput += cobolCheckOutput[i];
}
});

Thread errorThread = new Thread(() -> {
try (BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()))) {
String s;
while ((s = stdError.readLine()) != null) {
synchronized (lock) {
processErrorBuilder.append(s).append(Constants.NEWLINE);
}
}
} catch (IOException e) {
Log.warn(Messages.get("WRN007"));
}
//Remove extra NEWLINE:
processInput = StringHelper.removeLastIndex(processInput);
processError = StringHelper.removeLastIndex(processError);
});

stdInput.close();
stdError.close();
}
catch (IOException ex)
{
Log.warn(Messages.get("WRN007"));
inputThread.start();
errorThread.start();

// Wait for both threads to finish
try {
inputThread.join();
errorThread.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt(); // Restore interrupted status
Log.warn(Messages.get("WRN009"));
}

// Convert StringBuilder to String, removing the last NEWLINE if necessary
processInput = StringHelper.removeLastIndex(processInput.toString());
processError = StringHelper.removeLastIndex(processErrorBuilder.toString());
}


private void writeOutPutToConsole() {
System.out.println(processInput);
System.out.println(processError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ static List<String> generateSectionLines(String identifier, List<String> comment
lines.add(String.format(SECTION_HEADER_FORMAT, identifier));
if (commentLines != null)
lines.addAll(commentLines);
if (bodyLines != null)
if (bodyLines != null) {
lines.addAll(bodyLines);
lines.add(ENDING_PERIOD);
// 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;
}

Expand All @@ -32,9 +39,16 @@ static List<String> generateParagraphLines(String identifier, List<String> comme
lines.add(String.format(PARAGRAPH_HEADER_FORMAT, identifier));
if (commentLines != null)
lines.addAll(commentLines);
if (bodyLines != null)
if (bodyLines != null) {
lines.addAll(bodyLines);
lines.add(ENDING_PERIOD);
// 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;
}

Expand Down Expand Up @@ -75,17 +89,28 @@ static void addStartAndEndTags(List<String> lines){
lines.add(getInjectEndTagComment());
}

static List<String> generateWhenOtherLines(String identifier, String type, List<String> commentLines, List<String> bodyLines){
static List<String> generateWhenOtherLines(String identifier, String type, List<String> commentLines, List<String> bodyLines) {
List<String> lines = new ArrayList<>();
if(type.equals(Constants.SECTION_TOKEN))
if (type.equals(Constants.SECTION_TOKEN))
lines.add(String.format(WHEN_OTHER_SECTION_HEADER_FORMAT, identifier));
else lines.add(String.format(PARAGRAPH_HEADER_FORMAT, identifier));
else
lines.add(String.format(PARAGRAPH_HEADER_FORMAT, identifier));

if (commentLines != null)
lines.addAll(commentLines);
if (bodyLines != null)

if (bodyLines != null) {
lines.addAll(bodyLines);
lines.add(ENDING_PERIOD);
// 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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.openmainframeproject.cobolcheck.features.interpreter.Area;
import org.openmainframeproject.cobolcheck.features.interpreter.State;
import org.openmainframeproject.cobolcheck.services.Constants;
import org.openmainframeproject.cobolcheck.services.platform.Platform;
import org.openmainframeproject.cobolcheck.services.platform.PlatformLookup;

import java.util.*;

Expand Down Expand Up @@ -271,13 +273,23 @@ public static boolean shouldLineBeParsed(CobolLine line, State state) {
public static boolean shouldLineBeStubbed(CobolLine line, State state) {
if (state.isFlagSetFor(Constants.PROCEDURE_DIVISION)) {
if (checkForBatchFileIOStatement(line) || line.containsToken(Constants.CALL_TOKEN) ||
line.containsToken(Constants.EXEC_SQL_TOKEN) || line.containsToken(Constants.EXEC_CICS_TOKEN)) {
line.containsToken(Constants.EXEC_SQL_TOKEN) || line.containsToken(Constants.EXEC_CICS_TOKEN) || line.containsToken(Constants.END_EXEC_TOKEN)) {
return true;
}
}
if (state.isFlagSetFor(Constants.WORKING_STORAGE_SECTION)) {
if (line.containsToken(Constants.EXEC_SQL_TOKEN) || line.containsToken(Constants.INCLUDE) || line.containsToken(Constants.END_EXEC_TOKEN))
return true;
if (line.containsToken(Constants.EXEC_SQL_TOKEN) || line.containsToken(Constants.INCLUDE) || line.containsToken(Constants.END_EXEC_TOKEN)) {
Platform platform = PlatformLookup.get();
switch(platform){
case ZOS:
if(line.containsToken(Constants.INCLUDE))
return false;
else
return true;
default:
return true;
}
}
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ WRN005 = WRN005: Test results input file not found: %1$s. Define in config as te
WRN006 = WRN006: IOException writing test results to file: %1$s in ProcessOutputWriter.writeProcessOutputToFile(...)
WRN007 = WRN007: IOException reading test results from current process
WRN008 = WRN008: Access denied: Could not change permissions for %1$s
WRN009 = WRN009: InterruptedException during reading processInput and processError

INF001 = INF001: Attempting to load config from %1$s.
INF002 = INF002: Loaded config successfully from %1$s.
Expand Down
Loading

0 comments on commit 890de4c

Please sign in to comment.