-
Notifications
You must be signed in to change notification settings - Fork 7
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 #236 from Feuermagier/test-framework
New Test Framework
- Loading branch information
Showing
93 changed files
with
1,255 additions
and
794 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# The Test Framework | ||
|
||
## Syntax | ||
The `core` module contains a framework for testing in checks in `src/test/java/de/firemage/autograder/core/framework`. | ||
It allows you to create tests simply by writing valid Java code and inserting so-called *meta comments* that specify e.g. where the Autograder is expected to find problems. | ||
Meta comments are valid Java comments with additional '#' characters: Either block comments denoted by `/*#` and `#*/` or line comments denoted by `//#`. | ||
The framework will parse them and remove the comments before passing the code to the Autograder, so that they do not impact the actual source code to check. | ||
In particular, meta block comments can be used inside of standard Java strings and comments. | ||
|
||
The content of a meta comment consists of up to three parts, separated by semicolons: | ||
`<tag> ; <optional comment> ; <optional expected problem type>` | ||
Whitespace around the parts is ignored. | ||
The first part must be a tag from the following table: | ||
|
||
| tag | description | | ||
|----------------|-------------------------------------------------------------------------------| | ||
| <empty string> | No problem expected here; use for comments | | ||
| ok | No problem expected here; used for documenting why this is the case | | ||
| not ok | Expect a problem here | | ||
| false positive | Expect a problem here, but warn about the existence of a false positive | | ||
| false negative | Don't expect a problem here, but warn about the existence of a false positive | | ||
|
||
The second part of the meta comment is optional and can be used to provide a comment. | ||
The third part of the meta comment is also optional and may only be present if the second (comment) part is present (which may be empty). | ||
It should contain the name of the problem type to expect here. | ||
If specified, a problem of this type is expected at this line, as long as the tag indicated that a problem is expected here. | ||
|
||
## Examples | ||
``` | ||
//# not ok | ||
//# not ok; This is a comment | ||
//# not ok; auto-generated javadoc; JAVADOC_STUB_DESCRIPTION | ||
//# not ok;; JAVADOC_STUB_DESCRIPTION | ||
/*# not ok #*/ | ||
/*#not ok#*/ | ||
/*# false positive; see github issue #*/ | ||
/*# ok; This is a comment*/ | ||
/*# ;This is only a comment #*/ | ||
``` |
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 |
---|---|---|
|
@@ -63,6 +63,7 @@ | |
import java.util.stream.Stream; | ||
|
||
public final class SpoonUtil { | ||
|
||
private SpoonUtil() { | ||
|
||
} | ||
|
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
18 changes: 18 additions & 0 deletions
18
autograder-core/src/test/java/de/firemage/autograder/core/framework/ExpectedProblem.java
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,18 @@ | ||
package de.firemage.autograder.core.framework; | ||
|
||
import de.firemage.autograder.core.ProblemType; | ||
import de.firemage.autograder.core.file.SourcePath; | ||
|
||
public record ExpectedProblem(SourcePath file, int line, ProblemType problemType, String comment) { | ||
public String format() { | ||
return "%s@%s:%d".formatted( | ||
this.problemType != null ? this.problemType : "?", | ||
this.file, | ||
this.line | ||
); | ||
} | ||
|
||
public String toString() { | ||
return this.format(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
autograder-core/src/test/java/de/firemage/autograder/core/framework/ReportedProblem.java
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,6 @@ | ||
package de.firemage.autograder.core.framework; | ||
|
||
import de.firemage.autograder.core.Problem; | ||
|
||
public record ReportedProblem(Problem problem, String translatedMessage) { | ||
} |
44 changes: 44 additions & 0 deletions
44
autograder-core/src/test/java/de/firemage/autograder/core/framework/TestConfig.java
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,44 @@ | ||
package de.firemage.autograder.core.framework; | ||
|
||
import de.firemage.autograder.core.check.Check; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public record TestConfig(List<String> lines) { | ||
public static TestConfig fromPath(Path path) { | ||
try { | ||
List<String> lines = Files.readAllLines(path.resolve("config.txt")); | ||
|
||
if (lines.size() < 2) { | ||
throw new IllegalArgumentException("Config file must contain at least two lines"); | ||
} | ||
|
||
return new TestConfig(lines); | ||
} catch (IOException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
|
||
public String checkPath() { | ||
return this.lines.get(0); | ||
} | ||
|
||
public String description() { | ||
return this.lines.get(1); | ||
} | ||
|
||
public String qualifiedName() { | ||
return "de.firemage.autograder.core.check." + this.checkPath(); | ||
} | ||
|
||
public Check check() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException { | ||
return (Check) Class.forName(this.qualifiedName()) | ||
.getDeclaredConstructor() | ||
.newInstance(); | ||
} | ||
} |
Oops, something went wrong.