Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tmc-langs-r/src/main/java/fi/helsinki/cs/tmc/langs/r/RPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public Optional<ExerciseDesc> scanExercise(Path path, String exerciseName) {
@Override
public RunResult runTests(Path path) {
ProcessRunner runner = new ProcessRunner(getTestCommand(), path);

deleteResultsJson(path);

try {
ProcessResult result = runner.call();
Expand Down Expand Up @@ -189,6 +191,14 @@ public String[] getAvailablePointsCommand() {
return ArrayUtils.addAll(command, args);
}

public void deleteResultsJson(Path path) {
try {
Files.deleteIfExists(path.resolve(".results.json"));
} catch (Exception e) {
log.error("Could not delete .results.json", e);
}
}

/**
* No operation for now. To be possibly implemented later: remove .Rdata, .Rhistory etc
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public void runTestsReturnsStackTraceWhenPathDoesNotExist() {
RunResult res = plugin.runTests(doesNotExist);

String stackTrace = new String(res.logs.get(SpecialLogs.GENERIC_ERROR_MESSAGE));
assertEquals("java.lang.NullPointerException", stackTrace.split("\n")[0]);
assertEquals("java.lang.NullPointerException",
stackTrace.split(System.getProperty("line.separator"))[0]);
assertTrue(stackTrace.split("\n").length > 1);
}

Expand Down Expand Up @@ -155,4 +156,17 @@ public void getStudentFilePolicyReturnsRStudentFilePolicy() {

assertTrue(policy instanceof RStudentFilePolicy);
}

@Test
public void resultsJsonIsDeletedBeforeRunning() throws IOException {
Files.createFile(simpleAllTestsPassProject.resolve(".results.json"));
plugin.deleteResultsJson(simpleAllTestsPassProject);
assertTrue(!Files.exists(simpleAllTestsPassProject.resolve(".results.json")));
}

@Test
public void deleteResultsJsonWorksCorrectlyWhenNoJson() throws IOException {
plugin.deleteResultsJson(simpleAllTestsPassProject);
assertTrue(!Files.exists(simpleAllTestsPassProject.resolve(".results.json")));
}
}