Skip to content

Commit

Permalink
Latest version.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Jul 28, 2021
1 parent 469bc84 commit 8804f29
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 4 deletions.
10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion src/main/kotlin/Annotations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,26 @@ fun Method.isCompare() = isAnnotationPresent(Compare::class.java)

class CompareException(message: String? = null) : RuntimeException(message)

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class ShouldContinue {
companion object {
val name: String = ShouldContinue::class.java.simpleName
fun validate(method: Method) {
check(method.isPrivate()) { "@$name methods must be private" }
check(!method.isStatic()) { "@$name methods must not be static" }
check(method.returnType.name == "boolean") {
"@$name methods must return a boolean"
}
check(method.parameterTypes.isEmpty()) {
"@$name methods must not accept parameters"
}
method.isAccessible = true
}
}
}
fun Method.isShouldContinue() = isAnnotationPresent(ShouldContinue::class.java)

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class Configure(val strictOutput: Boolean = false)
Expand Down Expand Up @@ -351,7 +371,9 @@ fun Executable.isJenisol() = setOf(
Verify::class.java,
Both::class.java,
FilterParameters::class.java,
InstanceValidator::class.java
InstanceValidator::class.java,
Compare::class.java,
ShouldContinue::class.java
).any {
isAnnotationPresent(it)
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/kotlin/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,19 @@ class Solution(val solution: Class<*>) {
val instanceValidator = solution.declaredMethods.filter {
it.isInstanceValidator()
}.also {
checkDesign(it.size <= 1) { "Solution has multiple instance validators" }
checkDesign(it.size <= 1) { "Solution has multiple methods annotated with @InstanceValidator" }
}.firstOrNull()?.also {
checkDesign { InstanceValidator.validate(it) }
}

val shouldContinue = solution.declaredMethods.filter {
it.isShouldContinue()
}.also {
checkDesign(it.size <= 1) { "Solution has multiple methods annotated with @ShouldContinue" }
}.firstOrNull()?.also {
checkDesign { ShouldContinue.validate(it) }
}

val customCompares = solution.declaredMethods.filter {
it.isCompare()
}.filterNotNull().let { compareMethods ->
Expand Down
8 changes: 7 additions & 1 deletion src/main/kotlin/Testing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ class TestRunner(
val failed: Boolean
get() = testResults.any { it.failed }
val ready: Boolean
get() = testResults.none { it.failed } && receivers != null
get() = testResults.none { it.failed } && receivers != null && shouldContinue
private var shouldContinue = true

var lastComplexity: Complexity? = null

Expand Down Expand Up @@ -583,6 +584,11 @@ class TestRunner(
initialized = true
} else {
run(methodIterator.first(), stepCount)
if (submission.solution.shouldContinue != null && receivers != null) {
shouldContinue = unwrap {
submission.solution.shouldContinue.invoke(receivers!!.solution)
} as Boolean
}
}
return ready
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2021.6.9
version=2021.7.0
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ class TestJavaExamples : StringSpec(
examples.java.receiver.rejectstaticfield.Correct::class.java.also {
"${it.testName()}" { it.test() }
}
examples.java.receiver.withshouldcontinue.Correct::class.java.also {
"${it.testName()}" { it.test() }
}
examples.java.receiver.timeouttest.Correct::class.java.also {
"${it.testName()}" {
val runnable = object : Runnable {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package examples.java.receiver.withshouldcontinue;

import edu.illinois.cs.cs125.jenisol.core.ShouldContinue;

public class Correct {
@ShouldContinue
private boolean shouldContinue() {
return false;
}

public int getValue() {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package examples.java.receiver.withshouldcontinue;

public class Correct0 {
private int value = 0;

public int getValue() {
return value--;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package examples.java.receiver.withshouldcontinue;

public class Incorrect0 {
public int getValue() {
return 1;
}
}

0 comments on commit 8804f29

Please sign in to comment.