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
45 changes: 45 additions & 0 deletions .old_travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
language: java
sudo: false
cache:
directories:
- "$HOME/.m2"
addons:
apt:
sources:
- deadsnakes
packages:
- valgrind
- check
- python3.4
env:
global:
- secure: yiW+hXiZEycKFzF19rLlejJX8BTGbncSisBHyE8uulZee5n7UVGXnG1yvt9+6hz0nvMbxL7r1Daql0xxRHXUFB9VYVUKhF0ycHyJO5ze87U51mlIKAL8UnCkmxpkHNdxY45olEdK+mEbZBtot67nenlwGDfxLI7laITkR8IBAvY=
- secure: WVOHmRlzHZhuYqpTVFR2ZjdVDugr/EGEZGhnkWFFh6DE2zfa+na8WSLQdynHjTH1sL2DMg+p4l8siLoKk6Kn9wh+Wah2GP54oKQNIvt+Zl0olTR8TZq/uEo1iU4dqsDbMscId2xK7imdQ9wMKXV0t/bqhjiFR/wxheR96WxvIVs=
- M3_HOME=/usr/local/maven

before_install:
- curl -L https://static.rust-lang.org/rustup.sh | sh -s -- --channel=stable --yes --prefix=$PWD --disable-sudo
- export PATH=$PATH:$PWD/bin
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib
- mkdir $HOME/bin && ln -s $(which python3.4) $HOME/bin/python3 && export PATH="$HOME/bin:$PATH"
- mvn install -Dmaven.test.skip=true
script:
- mvn clean test
- mvn checkstyle:check
- . ./clitest.sh
after_success:
- mvn clean cobertura:cobertura org.eluder.coveralls:coveralls-maven-plugin:report
- ./deploy.sh
os:
- linux
- osx
jdk:
- oraclejdk8
- oraclejdk7
- openjdk7
matrix:
allow_failures:
- os: osx
notifications:
slack:
secure: elwVbriXdc/RkeP3UfVpSC0N6mbdk60ro7Pu1+2ddktmgQIEHjAVSdzpy2FLGTz/gK2MEXo2XU1rSg3t8GqlJNh1RTASzhyhcCUJTa7UdKe84mcRWDxJffunQKsBpUJv71tXBy1OyL8pcdnw1qkpr5NDyqXvBk67VwepVqy8em4=
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,20 @@ addons:
packages:
- valgrind
- check
- python3.4
env:
global:
- secure: yiW+hXiZEycKFzF19rLlejJX8BTGbncSisBHyE8uulZee5n7UVGXnG1yvt9+6hz0nvMbxL7r1Daql0xxRHXUFB9VYVUKhF0ycHyJO5ze87U51mlIKAL8UnCkmxpkHNdxY45olEdK+mEbZBtot67nenlwGDfxLI7laITkR8IBAvY=
- secure: WVOHmRlzHZhuYqpTVFR2ZjdVDugr/EGEZGhnkWFFh6DE2zfa+na8WSLQdynHjTH1sL2DMg+p4l8siLoKk6Kn9wh+Wah2GP54oKQNIvt+Zl0olTR8TZq/uEo1iU4dqsDbMscId2xK7imdQ9wMKXV0t/bqhjiFR/wxheR96WxvIVs=
- M3_HOME=/usr/local/maven

before_install:
- curl -L https://static.rust-lang.org/rustup.sh | sh -s -- --channel=stable --yes --prefix=$PWD --disable-sudo
- export PATH=$PATH:$PWD/bin
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib
- mkdir -p $HOME/bin && ln -s $(which python3.4) $HOME/bin/python3 && export PATH="$HOME/bin:$PATH"
- export PATH="$HOME/bin:$PATH"
- mvn install -Dmaven.test.skip=true
script:
- mvn clean test
- mvn clean test -pl tmc-langs-r
- mvn checkstyle:check
- . ./clitest.sh
after_success:
Expand All @@ -40,6 +39,4 @@ jdk:
matrix:
allow_failures:
- os: osx
notifications:
slack:
secure: elwVbriXdc/RkeP3UfVpSC0N6mbdk60ro7Pu1+2ddktmgQIEHjAVSdzpy2FLGTz/gK2MEXo2XU1rSg3t8GqlJNh1RTASzhyhcCUJTa7UdKe84mcRWDxJffunQKsBpUJv71tXBy1OyL8pcdnw1qkpr5NDyqXvBk67VwepVqy8em4=
- jdk: oraclejdk7
2 changes: 1 addition & 1 deletion clitest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# The intention is not to really validate the results of the command,
# but to make note should any commands fail and other packaging failures.

mvn clean package -Dmaven.test.skip=true
mvn clean package -Dmaven.test.skip=true

java -jar tmc-langs-cli/target/tmc-langs-cli-*-SNAPSHOT.jar scan-exercise --exercisePath tmc-langs-java/src/test/resources/maven_exercise --outputPath a
cat a
Expand Down
12 changes: 12 additions & 0 deletions old_clitest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash -v
# The intention is not to really validate the results of the command,
# but to make note should any commands fail and other packaging failures.

mvn clean package -Dmaven.test.skip=true

java -jar tmc-langs-cli/target/tmc-langs-cli-*-SNAPSHOT.jar scan-exercise --exercisePath tmc-langs-java/src/test/resources/maven_exercise --outputPath a
cat a

java -jar tmc-langs-cli/target/tmc-langs-cli-*-SNAPSHOT.jar prepare-stubs --exercisePath tmc-langs-java/src/test/resources/ant_arith_funcs/ --outputPath arithfuncs-proj
java -jar tmc-langs-cli/target/tmc-langs-cli-*-SNAPSHOT.jar checkstyle --exercisePath tmc-langs-cli/src/test/resources/arith_funcs --locale=en --outputPath tmp
cat tmp
16 changes: 15 additions & 1 deletion tmc-langs-r/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
<version>0.7.7-SNAPSHOT</version>
</parent>
<artifactId>tmc-langs-r</artifactId>
<version>1.0-SNAPSHOT</version>
<version>0.7.7-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>fi.helsinki.cs.tmc</groupId>
<artifactId>tmc-langs-framework</artifactId>
<version>0.7.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>fi.helsinki.cs.tmc</groupId>
<artifactId>tmc-langs-util</artifactId>
<version>0.7.7-SNAPSHOT</version>
</dependency>
</dependencies>

</project>
106 changes: 106 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
@@ -0,0 +1,106 @@
package fi.helsinki.cs.tmc.langs.r;

import fi.helsinki.cs.tmc.langs.AbstractLanguagePlugin;
import fi.helsinki.cs.tmc.langs.abstraction.ValidationResult;
import fi.helsinki.cs.tmc.langs.domain.ExerciseBuilder;
import fi.helsinki.cs.tmc.langs.domain.ExerciseDesc;
import fi.helsinki.cs.tmc.langs.domain.RunResult;
import fi.helsinki.cs.tmc.langs.io.StudentFilePolicy;
import fi.helsinki.cs.tmc.langs.io.sandbox.StudentFileAwareSubmissionProcessor;
import fi.helsinki.cs.tmc.langs.io.sandbox.SubmissionProcessor;
import fi.helsinki.cs.tmc.langs.io.zip.StudentFileAwareUnzipper;
import fi.helsinki.cs.tmc.langs.io.zip.StudentFileAwareZipper;
import fi.helsinki.cs.tmc.langs.io.zip.Unzipper;
import fi.helsinki.cs.tmc.langs.io.zip.Zipper;
import fi.helsinki.cs.tmc.langs.python3.Python3TestResultParser;
import fi.helsinki.cs.tmc.langs.utils.ProcessRunner;

import com.google.common.base.Optional;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.SystemUtils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Locale;

public final class RPlugin extends AbstractLanguagePlugin {

private static final String CANNOT_RUN_TESTS_MESSAGE = "Failed to run tests.";
private static final String CANNOT_PARSE_TEST_RESULTS_MESSAGE = "Failed to read test results.";
private static final String CANNOT_SCAN_EXERCISE_MESSAGE = "Failed to scan exercise.";
private static final String CANNOT_PARSE_EXERCISE_DESCRIPTION_MESSAGE =
"Failed to parse exercise description.";

private static Logger log = LoggerFactory.getLogger(RPlugin.class);

public RPlugin() {
super(
new ExerciseBuilder(),
new StudentFileAwareSubmissionProcessor(),
new StudentFileAwareZipper(),
new StudentFileAwareUnzipper());
}

@Override
public boolean isExerciseTypeCorrect(Path path) {
return false;
}

@Override
protected StudentFilePolicy getStudentFilePolicy(Path projectPath) {
return null;
}

@Override
public String getPluginName() {
return null;
}

@Override
public Optional<ExerciseDesc> scanExercise(Path path, String exerciseName) {
return null;
}

@Override
public RunResult runTests(Path path) {

ProcessRunner runner = new ProcessRunner(getTestCommand(), path);
try {
runner.call();
} catch (Exception e) {
log.error(CANNOT_RUN_TESTS_MESSAGE, e);
}

try {
return new RTestResultParser(path).parse();
} catch (IOException e) {
log.error(CANNOT_PARSE_TEST_RESULTS_MESSAGE, e);
}
return null;
}

@Override
public ValidationResult checkCodeStyle(Path path, Locale messageLocale) {
return null;
}

private String[] getTestCommand() {
String[] rscr = new String[] {"Rscript", "-e"};
String[] command;
if (SystemUtils.IS_OS_WINDOWS) {
command = new String[] {"\"library('tmcRtestrunner');runTestsWithDefault(TRUE)\""};
} else {
command = new String[] {"\"library(tmcRtestrunner);runTests(\"$PWD\", print=TRUE)\""};
}
return ArrayUtils.addAll(rscr, command);
}

@Override
public void clean(Path path) {

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,79 @@
package fi.helsinki.cs.tmc.langs.r;

import fi.helsinki.cs.tmc.langs.domain.RunResult;
import fi.helsinki.cs.tmc.langs.domain.TestResult;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class RTestResultParser {

public RTestResultParser() {
Path path;
private ObjectMapper mapper;

private static Path RESULT_FILE = Paths.get(".results.json");

public RTestResultParser(Path path) {
this.path = path;
this.mapper = new ObjectMapper();
}

RunResult parse() throws IOException {
List<TestResult> testResults = getTestResults();

RunResult.Status status = RunResult.Status.PASSED;
for (TestResult result : testResults) {
if (!result.isSuccessful()) {
status = RunResult.Status.TESTS_FAILED;
}
}

ImmutableList<TestResult> immutableResults = ImmutableList.copyOf(testResults);
ImmutableMap<String, byte[]> logs = ImmutableMap.copyOf(new HashMap<String, byte[]>());
return new RunResult(status, immutableResults, logs);
}

private List<TestResult> getTestResults() throws IOException {
byte[] json = Files.readAllBytes(path.resolve(RESULT_FILE));

List<TestResult> results = new ArrayList<>();

JsonNode tree = mapper.readTree(json);
for (JsonNode node : tree) {
results.add(toTestResult(node));
}

return results;
}

private TestResult toTestResult(JsonNode node) {
List<String> points = new ArrayList<>();
for (JsonNode point : node.get("points")) {
points.add(point.asText());
}

List<String> backTrace = new ArrayList<>();
for (JsonNode line : node.get("backtrace")) {
backTrace.add(line.asText());
}

boolean passed = node.get("status").asText().equals("pass");

return new TestResult(
node.get("name").asText(),
passed,
ImmutableList.copyOf(points),
node.get("message").toString(),
ImmutableList.copyOf(backTrace));
}
}
76 changes: 76 additions & 0 deletions tmc-langs-r/src/main/java/fi/helsinki/cs/tmc/langs/r/TestMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package fi.helsinki.cs.tmc.langs.r;

import fi.helsinki.cs.tmc.langs.domain.RunResult;
import fi.helsinki.cs.tmc.langs.domain.TestResult;
import fi.helsinki.cs.tmc.langs.utils.ProcessRunner;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.SystemUtils;

import java.io.IOException;

import java.nio.file.Path;
import java.nio.file.Paths;

public class TestMain {

/**
* Just testing.
*
* @param args Nothing.
*/
public static void main(String[] args) {

//For now, add the path you want to test here fully,
//for example: pathToGithubFolder/tmc-r/example_projects/example_project1
String exampleProjectLocation = "/tmc-r/example_projects/example_project1";
Path path = Paths.get(exampleProjectLocation);
RunResult runRes = runTests(path);
printTestResult(runRes);
RunResult rr;

/* try {
rr = new RTestResultParser(path).parse();
for (TestResult tr : rr.testResults) {
System.out.println(tr.toString());
}
} catch (IOException e) {
System.out.println("Something wrong: " + e.getMessage());
}*/
}

public static void printTestResult(RunResult rr) {
for (TestResult tr : rr.testResults) {
System.out.println(tr.toString());
}
}


public static RunResult runTests(Path path) {

ProcessRunner runner = new ProcessRunner(getTestCommand(), path);
try {
runner.call();
} catch (Exception e) {
System.out.println("Something wrong: " + e.getMessage());
}

try {
return new RTestResultParser(path).parse();
} catch (IOException e) {
System.out.println("Something wrong: " + e.getMessage());
}
return null;
}

private static String[] getTestCommand() {
String[] rscr = new String[]{"Rscript", "-e"};
String[] command;
if (SystemUtils.IS_OS_WINDOWS) {
command = new String[] {"\"library('tmcRtestrunner');runTestsWithDefault(TRUE)\""};
} else {
command = new String[] {"\"library(tmcRtestrunner);runTests(\"$PWD\", print=TRUE)\""};
}
return ArrayUtils.addAll(rscr, command);
}
}
Loading