Skip to content

Commit

Permalink
Revert "Merge pull request #34 from DarthKipsu/lang-syntax"
Browse files Browse the repository at this point in the history
This reverts commit fdad46d, reversing
changes made to cf7c78c.
  • Loading branch information
jamo committed Nov 6, 2015
1 parent 77ad37c commit 6e40def
Show file tree
Hide file tree
Showing 14 changed files with 6 additions and 351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;

public class CargoPlugin extends AbstractLanguagePlugin {

Expand Down Expand Up @@ -63,7 +61,7 @@ protected StudentFilePolicy getStudentFilePolicy(Path projectPath) {
public ValidationResult checkCodeStyle(Path path) {
if (run(new String[]{"cargo", "clean"}, path).isPresent()) {
String[] command = {"cargo", "rustc", "--", "--forbid", "warnings"};
log.info("Building for lints with command {}", Arrays.deepToString(command));
log.info("Building for lints with command {0}", Arrays.deepToString(command));
Optional<ProcessResult> result = run(command, path);
if (result.isPresent()) {
return parseLints(result.get());
Expand All @@ -83,25 +81,7 @@ public String getPluginName() {

@Override
public Optional<ExerciseDesc> scanExercise(Path path, String exerciseName) {
if (!isExerciseTypeCorrect(path)) {
log.error("Failed to scan exercise due to missing Cargo.toml.");
return Optional.absent();
}

try {
runTests(path);
} catch (Exception e) {
log.error("Failed to run tests: {}", e);
return Optional.absent();
}
try {
Path pointsFile = path.resolve(Constants.POINTS);
List<String> lines = Files.readAllLines(pointsFile, StandardCharsets.UTF_8);
return Optional.of(parseExercisePoints(lines, exerciseName));
} catch (IOException e) {
log.error("Failed to parse test points: {}", e);
return Optional.absent();
}
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
Expand All @@ -116,7 +96,7 @@ public RunResult runTests(Path path) {

private Optional<RunResult> build(Path path) {
String[] command = {"cargo", "test", "--no-run"};
log.info("Building project with command {}", Arrays.deepToString(command));
log.info("Building project with command {0}", Arrays.deepToString(command));
Optional<ProcessResult> result = run(command, path);
if (result.isPresent()) {
if (result.get().statusCode == 0) {
Expand All @@ -129,7 +109,7 @@ private Optional<RunResult> build(Path path) {

private RunResult runBuiltTests(Path dir) {
String[] command = {"cargo", "test"};
log.info("Running tests with command {}", Arrays.deepToString(command));
log.info("Running tests with command {0}", Arrays.deepToString(command));
Optional<ProcessResult> result = run(command, dir);
if (result.isPresent()) {
return parseResult(result.get(), dir);
Expand All @@ -142,7 +122,7 @@ private Optional<ProcessResult> run(String[] command, Path dir) {
try {
return Optional.of(runner.call());
} catch (Exception e) {
log.error("Running command {} failed {}", Arrays.deepToString(command), e);
log.error("Running command {0} failed {1}", Arrays.deepToString(command), e);
return Optional.absent();
}
}
Expand All @@ -166,12 +146,4 @@ private ValidationResult parseLints(ProcessResult processResult) {
return new LinterResultParser().parse(processResult);
}

private ExerciseDesc parseExercisePoints(List<String> lines, String exerciseName) {
Optional<ExerciseDesc> result = new RustPointsParser().parse(lines, exerciseName);
if (result.isPresent()) {
return result.get();
}
log.error("Parsing points file failed.");
return null;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

package fi.helsinki.cs.tmc.langs.rust.util;

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

public class Constants {

public static final Path CARGO_TOML = Paths.get("Cargo.toml");
public static final Path SOURCE = Paths.get("src");
public static final Path TESTS = Paths.get("tests", "mod.rs");
public static final Path POINTS = Paths.get("tmc-points.txt");
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@

import fi.helsinki.cs.tmc.langs.abstraction.ValidationError;
import fi.helsinki.cs.tmc.langs.abstraction.ValidationResult;
import fi.helsinki.cs.tmc.langs.domain.ExerciseDesc;
import fi.helsinki.cs.tmc.langs.domain.RunResult;
import fi.helsinki.cs.tmc.langs.domain.SpecialLogs;
import fi.helsinki.cs.tmc.langs.domain.TestDesc;
import fi.helsinki.cs.tmc.langs.utils.TestUtils;

import com.google.common.base.Optional;

import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -216,49 +212,4 @@ public void lintingHasRightErrorsWithTwoFiles() {
assertTrue(error2.getValue().get(0).getMessage().contains("snake case"));
assertTrue(error2.getValue().get(0).getSourceName().contains("xor_adder.rs"));
}

@Test
public void scanningExerciseWorks() {
Path path = TestUtils.getPath(getClass(), "points");
Optional<ExerciseDesc> desc = cargoPlugin.scanExercise(path, "test");
assertTrue(desc.isPresent());
assertEquals("test", desc.get().name);
assertEquals(1, desc.get().tests.size());
assertEquals("it_shall_work", desc.get().tests.get(0).name);
assertEquals(1, desc.get().tests.get(0).points.size());
assertEquals("10", desc.get().tests.get(0).points.get(0));
}

@Test
public void scanningWithMultipleExerciseWorks() {
Path path = TestUtils.getPath(getClass(), "multiplePoints");
Optional<ExerciseDesc> desc = cargoPlugin.scanExercise(path, "test");
assertTrue(desc.isPresent());
assertEquals("test", desc.get().name);
assertEquals(2, desc.get().tests.size());
TestDesc test1 = desc.get().tests.get(0);
TestDesc test2 = desc.get().tests.get(1);
if (test2.name.equals("it_shall_work")) {
TestDesc tmp = test1;
test1 = test2;
test2 = tmp;
}
assertEquals("it_shall_work", test1.name);
assertEquals(1, test1.points.size());
assertEquals("4", test1.points.get(0));

assertEquals("it_shall_work2", test2.name);
assertEquals(1, test2.points.size());
assertEquals("7", test2.points.get(0));
}

@Test
public void scanningWithSuiteWorks() {
Path path = TestUtils.getPath(getClass(), "multiplePointsSuite");
Optional<ExerciseDesc> desc = cargoPlugin.scanExercise(path, "test");
assertTrue(desc.isPresent());
assertEquals("test", desc.get().name);
assertEquals(3, desc.get().tests.size());
//TODO: Figure out how the suites should actually work
}
}

This file was deleted.

7 changes: 0 additions & 7 deletions tmc-langs-rust/src/test/resources/multiplePoints/Cargo.toml

This file was deleted.

5 changes: 0 additions & 5 deletions tmc-langs-rust/src/test/resources/multiplePoints/src/lib.rs

This file was deleted.

16 changes: 0 additions & 16 deletions tmc-langs-rust/src/test/resources/multiplePoints/tests/mod.rs

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 6e40def

Please sign in to comment.