Skip to content

Commit 4e957df

Browse files
committed
Merge pull request #91 from RTMC/master
Added solution file support for R and made cheating harder.
2 parents a91894d + 3482170 commit 4e957df

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/domain/MetaSyntaxGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static List<MetaSyntax> listSyntaxes(String fileType) {
2020
list.add(new MetaSyntax("\\/\\*+", "\\*+\\/")); /* */
2121
} else if (fileType.matches("xml|http|html")) {
2222
list.add(new MetaSyntax("<!--", "-->"));
23-
} else if (fileType.matches("properties|py")) {
23+
} else if (fileType.matches("properties|py|R")) {
2424
list.add(new MetaSyntax("#", ""));
2525
}
2626
cache.put(fileType, list);

tmc-langs-r/src/main/java/fi/helsinki/cs/tmc/langs/r/RPlugin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ public Optional<ExerciseDesc> scanExercise(Path path, String exerciseName) {
121121
@Override
122122
public RunResult runTests(Path path) {
123123
ProcessRunner runner = new ProcessRunner(getTestCommand(), path);
124+
125+
deleteResultsJson(path);
124126

125127
try {
126128
ProcessResult result = runner.call();
@@ -189,6 +191,14 @@ public String[] getAvailablePointsCommand() {
189191
return ArrayUtils.addAll(command, args);
190192
}
191193

194+
public void deleteResultsJson(Path path) {
195+
try {
196+
Files.deleteIfExists(path.resolve(".results.json"));
197+
} catch (Exception e) {
198+
log.error("Could not delete .results.json", e);
199+
}
200+
}
201+
192202
/**
193203
* No operation for now. To be possibly implemented later: remove .Rdata, .Rhistory etc
194204
*/

tmc-langs-r/src/test/java/fi/helsinki/cs/tmc/langs/r/RPluginTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ public void runTestsReturnsStackTraceWhenPathDoesNotExist() {
120120
RunResult res = plugin.runTests(doesNotExist);
121121

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

@@ -155,4 +156,17 @@ public void getStudentFilePolicyReturnsRStudentFilePolicy() {
155156

156157
assertTrue(policy instanceof RStudentFilePolicy);
157158
}
159+
160+
@Test
161+
public void resultsJsonIsDeletedBeforeRunning() throws IOException {
162+
Files.createFile(simpleAllTestsPassProject.resolve(".results.json"));
163+
plugin.deleteResultsJson(simpleAllTestsPassProject);
164+
assertTrue(!Files.exists(simpleAllTestsPassProject.resolve(".results.json")));
165+
}
166+
167+
@Test
168+
public void deleteResultsJsonWorksCorrectlyWhenNoJson() throws IOException {
169+
plugin.deleteResultsJson(simpleAllTestsPassProject);
170+
assertTrue(!Files.exists(simpleAllTestsPassProject.resolve(".results.json")));
171+
}
158172
}

0 commit comments

Comments
 (0)