Skip to content

Commit

Permalink
Add explanatory message for missing or extra newlines.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Jun 13, 2021
1 parent 43625ad commit c47625e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .idea/detekt.xml

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

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
java
`maven-publish`

id("org.jmailen.kotlinter") version "3.4.4"
id("org.jmailen.kotlinter") version "3.4.5"
checkstyle
id("com.github.sherter.google-java-format") version "0.9"

Expand Down
24 changes: 23 additions & 1 deletion src/main/kotlin/Submission.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class Submission(val solution: Solution, val submission: Class<*>, private val s
} ?: defaultVerify(result)
}

@Suppress("ComplexMethod")
@Suppress("ComplexMethod", "LongMethod")
private fun defaultVerify(result: TestResult<*, *>) {
val solution = result.solution
val submission = result.submission
Expand All @@ -197,9 +197,31 @@ class Submission(val solution: Solution, val submission: Class<*>, private val s
}
if ((strictOutput || solution.stdout.isNotBlank()) && solution.stdout != submission.stdout) {
result.differs.add(TestResult.Differs.STDOUT)
if (solution.stdout == submission.stdout + "\n") {
result.message = if (result.submissionIsKotlin) {
"Output is missing a newline, maybe use println instead of print?"
} else {
"Output is missing a newline, maybe use System.out.println instead of System.out.print?"
}
}
if (solution.stdout + "\n" == submission.stdout) {
result.message = if (result.submissionIsKotlin) {
"Output has an extra newline, maybe use print instead of println?"
} else {
"Output has an extra newline, maybe use System.out.print instead of System.out.println?"
}
}
}
if ((strictOutput || solution.stderr.isNotBlank()) && solution.stderr != submission.stderr) {
result.differs.add(TestResult.Differs.STDERR)
if (solution.stdout == submission.stdout + "\n") {
result.message =
"Error output is missing a newline, maybe use System.err.println instead of System.err.print?"
}
if (solution.stdout + "\n" == submission.stdout) {
result.message =
"Error output has an extra newline, maybe use System.err.print instead of System.err.println?"
}
}

if (result.type == TestResult.Type.METHOD) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2021.6.0
version=2021.6.1
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ class TestJavaExamples : StringSpec(
examples.java.noreceiver.twostringequality.Correct::class.java.also {
"${it.testName()}" { it.test() }
}
examples.java.noreceiver.printvprintln.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,7 @@
package examples.java.noreceiver.printvprintln;

public class Correct {
public static void run() {
System.out.println("It");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package examples.java.noreceiver.printvprintln;

public class Incorrect0 {
public static void run() {
System.out.print("It");
}
}

0 comments on commit c47625e

Please sign in to comment.