From c47625ed7f3ce72701c70872941c9d3e4fe7d39e Mon Sep 17 00:00:00 2001 From: Geoffrey Challen Date: Sun, 13 Jun 2021 16:08:40 -0500 Subject: [PATCH] Add explanatory message for missing or extra newlines. --- .idea/detekt.xml | 3 ++- build.gradle.kts | 2 +- src/main/kotlin/Submission.kt | 24 ++++++++++++++++++- ...edu.illinois.cs.cs125.jenisol.core.version | 2 +- .../cs/cs125/jenisol/core/TestJavaExamples.kt | 3 +++ .../noreceiver/printvprintln/Correct.java | 7 ++++++ .../noreceiver/printvprintln/Incorrect0.java | 7 ++++++ 7 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 src/test/java/examples/java/noreceiver/printvprintln/Correct.java create mode 100644 src/test/java/examples/java/noreceiver/printvprintln/Incorrect0.java diff --git a/.idea/detekt.xml b/.idea/detekt.xml index 40fb4ae..71d32b1 100644 --- a/.idea/detekt.xml +++ b/.idea/detekt.xml @@ -3,6 +3,7 @@ true true - $PROJECT_DIR$/../questioner-examples/config/detekt/detekt.yml + true + $PROJECT_DIR$/../questioner-problems/config/detekt/detekt.yml \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index e5af183..2998f62 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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" diff --git a/src/main/kotlin/Submission.kt b/src/main/kotlin/Submission.kt index be3a54c..1708928 100644 --- a/src/main/kotlin/Submission.kt +++ b/src/main/kotlin/Submission.kt @@ -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 @@ -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) { diff --git a/src/main/resources/edu.illinois.cs.cs125.jenisol.core.version b/src/main/resources/edu.illinois.cs.cs125.jenisol.core.version index 1202cba..86f3800 100644 --- a/src/main/resources/edu.illinois.cs.cs125.jenisol.core.version +++ b/src/main/resources/edu.illinois.cs.cs125.jenisol.core.version @@ -1 +1 @@ -version=2021.6.0 \ No newline at end of file +version=2021.6.1 \ No newline at end of file diff --git a/src/test/java/edu/illinois/cs/cs125/jenisol/core/TestJavaExamples.kt b/src/test/java/edu/illinois/cs/cs125/jenisol/core/TestJavaExamples.kt index 60f4c5c..2d10a82 100644 --- a/src/test/java/edu/illinois/cs/cs125/jenisol/core/TestJavaExamples.kt +++ b/src/test/java/edu/illinois/cs/cs125/jenisol/core/TestJavaExamples.kt @@ -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 { diff --git a/src/test/java/examples/java/noreceiver/printvprintln/Correct.java b/src/test/java/examples/java/noreceiver/printvprintln/Correct.java new file mode 100644 index 0000000..8ae9aaf --- /dev/null +++ b/src/test/java/examples/java/noreceiver/printvprintln/Correct.java @@ -0,0 +1,7 @@ +package examples.java.noreceiver.printvprintln; + +public class Correct { + public static void run() { + System.out.println("It"); + } +} diff --git a/src/test/java/examples/java/noreceiver/printvprintln/Incorrect0.java b/src/test/java/examples/java/noreceiver/printvprintln/Incorrect0.java new file mode 100644 index 0000000..8683fde --- /dev/null +++ b/src/test/java/examples/java/noreceiver/printvprintln/Incorrect0.java @@ -0,0 +1,7 @@ +package examples.java.noreceiver.printvprintln; + +public class Incorrect0 { + public static void run() { + System.out.print("It"); + } +}