Skip to content

Commit

Permalink
Prevents ChalkBox from failing when test/ dir is missing in submission
Browse files Browse the repository at this point in the history
Fixes #6
  • Loading branch information
maxcmiller committed Mar 30, 2021
1 parent 04ddc7c commit 59238e7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/chalkbox/java/junit/JUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,13 @@ public Collection run(Collection submission) {
* @return given submission with extra test results
*/
private Collection compileTests(Collection submission) {
Bundle tests = submission.getSource().getBundle("test");
Bundle source = submission.getSource();
Bundle tests = null;
try {
tests = source.getBundle("test");
} catch (NullPointerException npe) {
/* Test directory was not submitted, leave 'tests' as null */
}

StringJoiner output = new StringJoiner("\n");
StringWriter error = new StringWriter();
Expand All @@ -334,7 +340,7 @@ private Collection compileTests(Collection submission) {
StringWriter compileOutput = new StringWriter();
SourceFile file;
try {
file = tests.getFile(fileName);
file = tests.getFile(fileName); // throws NPE if no test directory was found
List<SourceFile> files = new ArrayList<>();
files.add(file);
boolean fileSuccess = Compiler.compile(files,
Expand All @@ -348,7 +354,7 @@ private Collection compileTests(Collection submission) {
output.add("JUnit test file " + fileName
+ (fileSuccess ? " compiles" : " does not compile"));
output.add(compileOutput.toString());
} catch (FileNotFoundException e) {
} catch (FileNotFoundException | NullPointerException e) {
error.write("JUnit test file " + fileName + " not found\n");
} catch (IOException e) {
error.write("IO Compile Error - Please contact course staff\n");
Expand Down

0 comments on commit 59238e7

Please sign in to comment.