Skip to content

Commit abc1818

Browse files
authored
Merge pull request #89 from RTMC/master
Added packaging configuration for RPlugin and improved error handling.
2 parents 9b577cf + 6f86d07 commit abc1818

File tree

9 files changed

+103
-29
lines changed

9 files changed

+103
-29
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import fi.helsinki.cs.tmc.langs.abstraction.ValidationResult;
77
import fi.helsinki.cs.tmc.langs.domain.ExerciseBuilder;
88
import fi.helsinki.cs.tmc.langs.domain.ExerciseDesc;
9+
import fi.helsinki.cs.tmc.langs.domain.ExercisePackagingConfiguration;
910
import fi.helsinki.cs.tmc.langs.domain.RunResult;
1011
import fi.helsinki.cs.tmc.langs.domain.SpecialLogs;
1112
import fi.helsinki.cs.tmc.langs.domain.TestDesc;
@@ -14,6 +15,7 @@
1415
import fi.helsinki.cs.tmc.langs.io.sandbox.StudentFileAwareSubmissionProcessor;
1516
import fi.helsinki.cs.tmc.langs.io.zip.StudentFileAwareUnzipper;
1617
import fi.helsinki.cs.tmc.langs.io.zip.StudentFileAwareZipper;
18+
import fi.helsinki.cs.tmc.langs.utils.ProcessResult;
1719
import fi.helsinki.cs.tmc.langs.utils.ProcessRunner;
1820

1921
import com.google.common.base.Optional;
@@ -96,7 +98,11 @@ public Optional<ExerciseDesc> scanExercise(Path path, String exerciseName) {
9698
ProcessRunner runner = new ProcessRunner(this.getAvailablePointsCommand(), path);
9799

98100
try {
99-
runner.call();
101+
ProcessResult result = runner.call();
102+
if (result.statusCode != 0) {
103+
log.error(CANNOT_SCAN_EXERCISE_MESSAGE);
104+
return Optional.absent();
105+
}
100106
} catch (Exception e) {
101107
log.error(CANNOT_SCAN_EXERCISE_MESSAGE, e);
102108
return Optional.absent();
@@ -117,7 +123,11 @@ public RunResult runTests(Path path) {
117123
ProcessRunner runner = new ProcessRunner(getTestCommand(), path);
118124

119125
try {
120-
runner.call();
126+
ProcessResult result = runner.call();
127+
if (result.statusCode != 0) {
128+
log.error(CANNOT_RUN_TESTS_MESSAGE);
129+
return getGenericErrorRunResult(new Exception(CANNOT_RUN_TESTS_MESSAGE));
130+
}
121131
} catch (Exception e) {
122132
log.error(CANNOT_RUN_TESTS_MESSAGE, e);
123133
return getGenericErrorRunResult(e);
@@ -185,4 +195,10 @@ public String[] getAvailablePointsCommand() {
185195
@Override
186196
public void clean(Path path) {
187197
}
198+
199+
@Override
200+
public ExercisePackagingConfiguration getExercisePackagingConfiguration(Path path) {
201+
return new ExercisePackagingConfiguration(
202+
ImmutableList.of("R"), ImmutableList.of("tests"));
203+
}
188204
}

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public class RPluginTest {
2525

2626
private Path simpleAllTestsPassProject;
2727
private Path simpleSomeTestsFailProject;
28-
private Path simpleSourceCodeErrorProject;
28+
private Path simpleSourcingFailProject;
29+
private Path simpleRunFailProject;
2930

3031
@Rule
3132
public final ExpectedException exception = ExpectedException.none();
@@ -38,16 +39,18 @@ public void setUp() {
3839
"simple_all_tests_pass");
3940
simpleSomeTestsFailProject = TestUtils.getPath(getClass(),
4041
"simple_some_tests_fail");
41-
simpleSourceCodeErrorProject = TestUtils.getPath(getClass(),
42-
"simple_source_code_error");
42+
simpleSourcingFailProject = TestUtils.getPath(getClass(),
43+
"simple_sourcing_fail");
44+
simpleRunFailProject = TestUtils.getPath(getClass(),
45+
"simple_run_fail");
4346
}
4447

4548
@After
4649
public void tearDown() throws IOException {
4750
removeAvailablePointsJson(simpleAllTestsPassProject);
4851
removeResultsJson(simpleAllTestsPassProject);
4952
removeResultsJson(simpleSomeTestsFailProject);
50-
removeResultsJson(simpleSourceCodeErrorProject);
53+
removeResultsJson(simpleSourcingFailProject);
5154
}
5255

5356
private void removeResultsJson(Path projectPath) throws IOException {
@@ -88,8 +91,15 @@ public void runTestsRunResultWithCorrectStatusForSimpleSomeFail() {
8891
}
8992

9093
@Test
91-
public void runTestsCreatesRunResultWithCorrectStatusWhenSourceCodeHasError() {
92-
RunResult res = plugin.runTests(simpleSourceCodeErrorProject);
94+
public void runTestsCreatesRunResultWithCorrectStatusForSourcingFail() {
95+
RunResult res = plugin.runTests(simpleSourcingFailProject);
96+
97+
assertEquals(RunResult.Status.COMPILE_FAILED, res.status);
98+
}
99+
100+
@Test
101+
public void runTestsCreatesRunResultWithCorrecStatusForRunFails() {
102+
RunResult res = plugin.runTests(simpleRunFailProject);
93103

94104
assertEquals(RunResult.Status.COMPILE_FAILED, res.status);
95105
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ret_true <- function() {
2+
return(TRUE)
3+
}
4+
5+
ret_one <- function() {
6+
return(1)
7+
}
8+
9+
add <- function(a, b) {
10+
return(a + b)
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library('testthat')
2+
3+
source("../../R/main.R")
4+
5+
points_for_all_tests(c("r1"))
6+
7+
test("RetTrue works.", c("r1.1"), {
8+
#Produces run fail:
9+
in error in
10+
expect_true(ret_true())
11+
})
12+
13+
test("RetOne works.", c("r1.2"), {
14+
expect_equal(ret_one(), 1)
15+
})
16+
17+
test("Add works.", c("r1.3", "r1.4"), {
18+
expect_equal(add(1, 1), 2)
19+
expect_equal(add(0, 1), 1)
20+
expect_equal(add(0, 0), 0)
21+
expect_equal(add(5, 5), 10)
22+
})

tmc-langs-r/src/test/resources/simple_source_code_error/tests/testthat/testMain.R

Lines changed: 0 additions & 18 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
RetTrue <- function() {
1+
ret_true <- function() {
22
return(TRUE)
33
}
44

55
#This function produces an error
6-
RetOne <- function() {
6+
ret_one <- function() {
77
error in source code
88
}
99

10-
Add <- function(a, b) {
10+
add <- function(a, b) {
1111
return(a + b)
1212
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: Default
4+
SaveWorkspace: Default
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
library('testthat')
2+
3+
source("../../R/main.R")
4+
5+
points_for_all_tests(c("r1"))
6+
7+
test("RetTrue works.", c("r1.1"), {
8+
expect_true(ret_true())
9+
})
10+
11+
test("RetOne works.", c("r1.2"), {
12+
expect_equal(ret_one(), 1)
13+
})
14+
15+
test("Add works.", c("r1.3", "r1.4"), {
16+
expect_equal(add(1, 1), 2)
17+
expect_equal(add(0, 1), 1)
18+
expect_equal(add(0, 0), 0)
19+
expect_equal(add(5, 5), 10)
20+
})

0 commit comments

Comments
 (0)