forked from BraeWebb/chalkbox
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from UQTools/gradescope
Gradescope
- Loading branch information
Showing
540 changed files
with
43,545 additions
and
5,463 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package chalkbox.api; | ||
|
||
import chalkbox.engines.ConfigFormatException; | ||
import chalkbox.engines.Engine; | ||
import chalkbox.engines.EngineLoader; | ||
|
||
public class ChalkBox { | ||
private static final String USAGE = "Incorrect usage:" + System.lineSeparator() | ||
+ "\tchalkbox <box file>" + System.lineSeparator() | ||
+ "\tchalkbox help <class>"; | ||
|
||
public static void main(String[] args) throws ConfigFormatException { | ||
|
||
if (args.length != 1) { | ||
System.err.println(USAGE); | ||
return; | ||
} | ||
|
||
Engine engine = EngineLoader.load(args[0]); | ||
engine.run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package chalkbox.api.common.java; | ||
|
||
import chalkbox.api.collections.Data; | ||
import org.junit.runner.Description; | ||
import org.junit.runner.notification.Failure; | ||
import org.junit.runner.notification.RunListener; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class JUnitListener extends RunListener { | ||
private static class TestResult { | ||
private final String testName; | ||
private boolean visible = false; | ||
private boolean passed = true; | ||
private String output = ""; | ||
|
||
public TestResult(String testName) { | ||
this.testName = testName; | ||
} | ||
} | ||
|
||
private List<TestResult> results; | ||
private TestResult currentResult; | ||
private int numFailed = 0; | ||
private StringBuilder output; | ||
|
||
public JUnitListener() { | ||
this.results = new ArrayList<>(); | ||
this.output = new StringBuilder(); | ||
} | ||
|
||
@Override | ||
public void testStarted(Description description) throws Exception { | ||
super.testStarted(description); | ||
|
||
this.currentResult = new TestResult( | ||
description.getTestClass().getSimpleName() | ||
+ "." + description.getMethodName()); | ||
|
||
/* Results of this test should be immediately visible */ | ||
// TODO create a library containing a custom annotation for this | ||
if (description.getAnnotation(Deprecated.class) != null) { | ||
this.currentResult.visible = true; | ||
} | ||
} | ||
|
||
@Override | ||
public void testFinished(Description description) throws Exception { | ||
super.testFinished(description); | ||
|
||
if (this.currentResult != null) { | ||
this.results.add(this.currentResult); | ||
} | ||
this.currentResult = null; | ||
} | ||
|
||
@Override | ||
public void testFailure(Failure failure) throws Exception { | ||
super.testFailure(failure); | ||
|
||
if (this.currentResult != null) { | ||
this.output.append(failure); | ||
this.output.append("\n"); | ||
this.currentResult.output = failure.toString(); | ||
this.currentResult.passed = false; | ||
} | ||
this.numFailed++; | ||
} | ||
|
||
public Data getResultsForClass() { | ||
Data data = new Data(); | ||
data.set("extra_data.passes", this.results.size() - this.numFailed); | ||
data.set("extra_data.fails", this.numFailed); | ||
data.set("extra_data.total", this.results.size()); | ||
data.set("output", this.output.toString()); | ||
return data; | ||
} | ||
|
||
public List<Data> getIndividualResults() { | ||
List<Data> results = new ArrayList<>(); | ||
|
||
for (TestResult result : this.results) { | ||
Data data = new Data(); | ||
data.set("extra_data.passes", result.passed ? 1 : 0); | ||
data.set("extra_data.fails", result.passed ? 0 : 1); | ||
data.set("extra_data.total", 1); | ||
data.set("output", result.output); | ||
data.set("name", result.testName); | ||
data.set("visibility", result.visible ? "visible" : "after_due_date"); | ||
results.add(data); | ||
} | ||
return results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package chalkbox.api.common.java; | ||
|
||
import chalkbox.api.collections.Data; | ||
import org.junit.runner.JUnitCore; | ||
|
||
import java.io.File; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.List; | ||
|
||
/** | ||
* Utility class to execute a JUnit test. | ||
*/ | ||
public class JUnitRunner { | ||
|
||
// Runs all tests in the given class and returns a single output object | ||
public static Data runTestsCombined(String className, String classPath) { | ||
return run(className, classPath).getResultsForClass(); | ||
} | ||
|
||
// Runs all tests in the given class and returns an output object for each @Test | ||
public static List<Data> runTests(String className, String classPath) { | ||
return run(className, classPath).getIndividualResults(); | ||
} | ||
|
||
private static JUnitListener run(String className, String classPath) { | ||
JUnitListener listener = new JUnitListener(); | ||
JUnitCore runner = new JUnitCore(); | ||
runner.addListener(listener); | ||
|
||
String[] classPathEntries = classPath.split( | ||
System.getProperty("path.separator")); | ||
URL[] classPathUrls = new URL[classPathEntries.length]; | ||
for (int i = 0; i < classPathEntries.length; ++i) { | ||
try { | ||
classPathUrls[i] = new File(classPathEntries[i]).toURI().toURL(); | ||
} catch (MalformedURLException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
URLClassLoader classLoader = new URLClassLoader(classPathUrls); | ||
try { | ||
runner.run(classLoader.loadClass(className)); | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
return listener; | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package chalkbox.collectors; | ||
|
||
import chalkbox.api.collections.Collection; | ||
import chalkbox.api.collections.Data; | ||
|
||
import java.io.File; | ||
|
||
public class GradescopeCollector { | ||
|
||
public Collection collect(String submissionPath, String outputPath) { | ||
File submissionFolder = new File(submissionPath); | ||
|
||
Data metadata = new Data(); | ||
|
||
metadata.set("root", submissionFolder.getPath()); | ||
metadata.set("json", outputPath); | ||
|
||
return new Collection(metadata); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package chalkbox.engines; | ||
|
||
public class ConfigFormatException extends Exception { | ||
public ConfigFormatException() { | ||
super(); | ||
} | ||
|
||
public ConfigFormatException(String message) { | ||
super(message); | ||
} | ||
|
||
public ConfigFormatException(String message, Exception exception) { | ||
super(message, exception); | ||
} | ||
} |
Oops, something went wrong.