Skip to content
Snippets Groups Projects
Commit 3217e270 authored by Janis Daniel Dähne's avatar Janis Daniel Dähne
Browse files

- when compiling 2 files the and no the main file had an error then the path...

- when compiling 2 files the and no the main file had an error then the path is now removed (./ or .\)
- added to docs: * matches even if the program does not output anything
- expected output is now added as a new line in the conversation protocol
parent a109a0dc
Branches
No related tags found
No related merge requests found
......@@ -58,10 +58,20 @@ public class Main {
/**
* the char that indicates the output for the users program in the test content
*/
static Character expectedOutputFromProgramChar = '>';
static Character outputFromProgramChar = '>';
/**
* the char that matches every user programs output (this is used when the output does not matter)
* the error prefix
*/
static String errorOutputPrefix = "error:";
/**
* the expected output
*/
static String expectedOutputPrefix = "expected:";
/**
* the char that matches every user programs output EVENT NO OUTPUT! (this is used when the output does not matter)
*/
static Character wildcardOutputMatchChar = '*';
......@@ -263,7 +273,7 @@ public class Main {
if (useDebugTestContent) {
testContents.add("$ 1 arg2 \"arg and 3\" arg4 10");
testContents.add("");
//testContents.add("");
testContents.add("> 1");
//testContents.add("< Test Echo");
//testContents.add("> Test Echo");
......@@ -441,13 +451,15 @@ public class Main {
return 100;
}
} else if (testLine.charAt(0) == expectedOutputFromProgramChar) {
} else if (testLine.charAt(0) == outputFromProgramChar) {
//read the output (if any)
String output = "";
try {
output = reader.readLine();
} catch (IOException e) {
System.out.println("Could not read from the process");
//error prefix is only for the user program errors
//Conversation.add(errorOutputPrefix: ' could not read from the process');
return 100;
}
......@@ -456,29 +468,35 @@ public class Main {
if (trimmedTestLine.length() > 0 && trimmedTestLine.charAt(0) == wildcardOutputMatchChar) {
//program output does not matter but we need output
Conversation.add(expectedOutputFromProgramChar + " " + toSafeLine(output.trim()));
Conversation.add(outputFromProgramChar + " " + toSafeLine(output.trim()));
} else {
String outPut = "";
//check if output matched
if (Objects.equals(output.trim(), trimmedTestLine)) {
if (output == null) {
//no output from user program
//but we cannot output null...
} else {
outPut = output;
}
if (Objects.equals(outPut.trim(), trimmedTestLine)) {
Conversation.add(testLine);
if (isDebug) {
System.out.println(testLine);
}
} else {
Conversation.add(expectedOutputFromProgramChar + " " + toSafeLine(output.trim()));
Conversation.add("expected: " + trimmedTestLine);
Conversation.add(outputFromProgramChar + " " + toSafeLine(outPut.trim()));
Conversation.add(expectedOutputPrefix + " " + trimmedTestLine);
if (isDebug) {
System.out.println(expectedOutputFromProgramChar + " " + toSafeLine(output.trim()));
System.out.print("expected: " + trimmedTestLine);
System.out.println(outputFromProgramChar + " " + toSafeLine(outPut.trim()));
System.out.print(expectedOutputPrefix + " " + trimmedTestLine);
}
outputMismatch[0] = true;
}
}
} else {
//ignore line
}
......@@ -541,7 +559,7 @@ public class Main {
try {
while ((errorLine = errorReader.readLine()) != null) {
Conversation.add("error: " + toSafeLine(errorLine));
Conversation.add(errorOutputPrefix + " " + toSafeLine(errorLine));
}
} catch (IOException e) {
//e.printStackTrace();
......@@ -738,7 +756,8 @@ public class Main {
Main.DirectoryPath = Main.DirectoryPath + File.separator;
}
if (line.startsWith("./")) {
//when compiling 2 files A is the main file B not and B has an error then B the path of B is something like ./B.java
if (line.startsWith("./") || line.startsWith(".\\")) {
line = line.substring(2);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment