diff --git a/.gitignore b/.gitignore index 4fcecfb..613ca3d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,13 @@ .bsp/ .idea/ +.vscode/ +.metals/ +.bloop/ +dumps/ target/ tests/**/results.json tests/**/build.log tests/**/runner.log -tests/**/*.original \ No newline at end of file +tests/**/*.original +project/metals.sbt +project/project \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 64cf2e1..48fdb22 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,16 @@ -FROM mozilla/sbt:8u232_1.4.5 +FROM mozilla/sbt:8u292_1.5.7 WORKDIR /opt/test-runner +RUN wget https://downloads.lightbend.com/scala/2.13.8/scala-2.13.8.tgz +RUN tar zxvf scala-2.13.8.tgz + +ENV PATH="$PATH:/opt/test-runner/scala-2.13.8/bin" + COPY project/ project/ COPY src/ src/ COPY build.sbt build.sbt + RUN sbt assembly COPY . . diff --git a/bin/run-tests.sh b/bin/run-tests.sh index bfce5db..72d832d 100755 --- a/bin/run-tests.sh +++ b/bin/run-tests.sh @@ -13,8 +13,6 @@ exit_code=0 -sbt test - # Iterate over all test directories for test_dir in tests/*; do test_dir_name=$(basename "${test_dir}") diff --git a/bin/run.sh b/bin/run.sh index 25ffc8d..3873bf7 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -24,36 +24,45 @@ fi slug="$1" input_dir="${2%/}" output_dir="${3%/}" + exercise=$(echo "${slug}" | sed -E 's/(^|-)([a-z])/\U\2/g') -tests_file="${input_dir}/src/test/scala/${exercise}Test.scala" -tests_results_file="${input_dir}/target/test-reports/TEST-${exercise}Test.xml" -original_tests_file="${input_dir}/src/test/scala/${exercise}Test.scala.original" + +test_runner_jar=/opt/test-runner/target/scala-2.13/TestRunner-assembly-0.1.0-SNAPSHOT.jar + +workdir=/tmp/exercise +workdir_target=/tmp/exercise/target + results_file="${output_dir}/results.json" build_log_file="${output_dir}/build.log" runner_log_file="${output_dir}/runner.log" +tests_results_file="${workdir}/test-reports/TEST-${exercise}Test.xml" # Create the output directory if it doesn't exist mkdir -p "${output_dir}" -echo "${slug}: testing..." +# ensure a clean workdir +rm -rf "${workdir}" +mkdir -p "${workdir}" +mkdir -p "${workdir_target}" -pushd "${input_dir}" > /dev/null +echo +echo "${slug}: testing..." -cp "${tests_file}" "${original_tests_file}" +cp -R "${input_dir}"/src "${workdir}" # Enable all pending tests -sed -i 's/pending//g' "${tests_file}" - -sbt "set offline := true" test > "${build_log_file}" +sed -i 's/pending//g' "${workdir}"/src/test/scala/* -# Sanitize the output -sed -i -E '/^\[info\]/d' "${build_log_file}" +# compile source and tests +scalac -classpath "${test_runner_jar}" -d "${workdir_target}" "${workdir}"/src/main/scala/* "${workdir}"/src/test/scala/* &> "${build_log_file}" -mv -f "${original_tests_file}" "${tests_file}" +# run tests +scala -classpath "${test_runner_jar}" org.scalatest.tools.Runner -R "${workdir_target}" -u "${workdir}"/test-reports -popd > /dev/null +# Write the results.json file in the exercism format +java -jar "${test_runner_jar}" "${build_log_file}" "${tests_results_file}" "${results_file}" &> "${runner_log_file}" -# Write the results.json file -java -jar target/scala-2.12/TestRunner-assembly-0.1.0-SNAPSHOT.jar "${build_log_file}" "${tests_results_file}" "${results_file}" > "${runner_log_file}" +# change workdir back to the original input_dir in the final results file +sed -i "s~${workdir}~${input_dir}~g" "${results_file}" echo "${slug}: done" diff --git a/build.sbt b/build.sbt index 151ecd8..03e54fb 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ import Dependencies._ -ThisBuild / scalaVersion := "2.12.8" +ThisBuild / scalaVersion := "2.13.6" ThisBuild / version := "0.1.0-SNAPSHOT" ThisBuild / organization := "org.exercism" ThisBuild / organizationName := "exercism" @@ -8,6 +8,7 @@ ThisBuild / organizationName := "exercism" lazy val root = (project in file(".")) .settings( name := "TestRunner", - libraryDependencies += scalaTest % Test, - libraryDependencies += "org.json" % "json" % "20201115" + // not in the Test scope so that it gets added to the fat jar generated by sbt assembly + libraryDependencies += scalaTest, + libraryDependencies += "org.json" % "json" % "20220320" ) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index c11e0a2..71265bd 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -1,5 +1,5 @@ import sbt._ object Dependencies { - lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.1" + lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.2.10" } diff --git a/project/build.properties b/project/build.properties index c06db1b..baf5ff3 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.4.5 +sbt.version=1.5.7 diff --git a/src/main/scala/Application.scala b/src/main/scala/Application.scala index 96e4e63..e7895c4 100644 --- a/src/main/scala/Application.scala +++ b/src/main/scala/Application.scala @@ -36,8 +36,7 @@ val fileSource = Source.fromFile(buildLogFilePath) val rawContent = fileSource.mkString fileSource.close - if (rawContent.contains("[error] (Compile / compileIncremental) Compilation failed") || - rawContent.contains("[error] (Test / compileIncremental) Compilation failed")) rawContent else "" + if (rawContent.contains("error: ")) rawContent else "" } def toTestCaseJSON(testCase: JSONObject): JSONObject = { @@ -53,7 +52,7 @@ def toExercismJSON(buildLogFilePath: String, testResultsFilePath: String): JSONObject = { val baseObject = new JSONObject().put("version", 2) val errorMessage = findErrorsInLog(buildLogFilePath) - if(!errorMessage.isEmpty) { + if(errorMessage.nonEmpty) { baseObject .put("status", "error") .put("message", errorMessage) diff --git a/src/test/resources/GradeSchoolTest.scala b/src/test/resources/GradeSchoolTest.scala index 8dc2b3c..5388e63 100644 --- a/src/test/resources/GradeSchoolTest.scala +++ b/src/test/resources/GradeSchoolTest.scala @@ -1,7 +1,7 @@ import org.scalatest._ /** @version created manually **/ -class GradeSchoolTest extends FunSuite with Matchers with OneInstancePerTest { +class GradeSchoolTest extends AnyFunSuite with Matchers with OneInstancePerTest { val school = new School test ("empty school") { diff --git a/src/test/resources/outputs/output_empty.txt b/src/test/resources/outputs/output_empty.txt index fa318e1..3278b05 100644 --- a/src/test/resources/outputs/output_empty.txt +++ b/src/test/resources/outputs/output_empty.txt @@ -1,15 +1,13 @@ -[error] /opt/test-runner/tests/example-empty-file/src/test/scala/ExampleEmptyFileTest.scala:7:5: not found: value Leap -[error] Leap.leapYear(2015) should be (false) -[error] ^ -[error] /opt/test-runner/tests/example-empty-file/src/test/scala/ExampleEmptyFileTest.scala:12:5: not found: value Leap -[error] Leap.leapYear(1996) should be (true) -[error] ^ -[error] /opt/test-runner/tests/example-empty-file/src/test/scala/ExampleEmptyFileTest.scala:17:5: not found: value Leap -[error] Leap.leapYear(2100) should be (false) -[error] ^ -[error] /opt/test-runner/tests/example-empty-file/src/test/scala/ExampleEmptyFileTest.scala:22:5: not found: value Leap -[error] Leap.leapYear(2000) should be (true) -[error] ^ -[error] four errors found -[error] (Test / compileIncremental) Compilation failed -[error] Total time: 4 s, completed Apr 14, 2021 2:11:23 PM +/tmp/exercise/src/test/scala/ExampleEmptyFileTest.scala:7: error: not found: value Leap + Leap.leapYear(2015) should be (false) + ^ +/tmp/exercise/src/test/scala/ExampleEmptyFileTest.scala:12: error: not found: value Leap + Leap.leapYear(1996) should be (true) + ^ +/tmp/exercise/src/test/scala/ExampleEmptyFileTest.scala:17: error: not found: value Leap + Leap.leapYear(2100) should be (false) + ^ +/tmp/exercise/src/test/scala/ExampleEmptyFileTest.scala:22: error: not found: value Leap + Leap.leapYear(2000) should be (true) + ^ +4 errors diff --git a/src/test/resources/outputs/output_error.txt b/src/test/resources/outputs/output_error.txt index 74cf4de..a870cbe 100644 --- a/src/test/resources/outputs/output_error.txt +++ b/src/test/resources/outputs/output_error.txt @@ -1,25 +1,49 @@ -[info] Loading project definition from /Users/pro/Exercism/scala/grade-school/project -[info] Loading settings for project grade-school from build.sbt ... -[info] Set current project to grade-school (in build file:/Users/pro/Exercism/scala/grade-school/) -[info] Compiling 1 Scala source to /Users/pro/Exercism/scala/grade-school/target/scala-2.13/test-classes ... -[error] /Users/pro/Exercism/scala/grade-school/src/test/scala/GradeSchoolTest.scala:8:15: overloaded method should with alternatives: -[error] (endWithWord: org.scalatest.words.EndWithWord)(implicit ev: GradeSchoolTest.this.school.DB <:< String): GradeSchoolTest.this.ResultOfEndWithWordForString -[error] (startWithWord: org.scalatest.words.StartWithWord)(implicit ev: GradeSchoolTest.this.school.DB <:< String): GradeSchoolTest.this.ResultOfStartWithWordForString -[error] (includeWord: org.scalatest.words.IncludeWord)(implicit ev: GradeSchoolTest.this.school.DB <:< String): GradeSchoolTest.this.ResultOfIncludeWordForString -[error] (notExist: org.scalatest.words.ResultOfNotExist)(implicit existence: org.scalatest.enablers.Existence[GradeSchoolTest.this.school.DB]): org.scalatest.Assertion -[error] (existWord: org.scalatest.words.ExistWord)(implicit existence: org.scalatest.enablers.Existence[GradeSchoolTest.this.school.DB]): org.scalatest.Assertion -[error] (containWord: org.scalatest.words.ContainWord)org.scalatest.words.ResultOfContainWord[GradeSchoolTest.this.school.DB] -[error] (haveWord: org.scalatest.words.HaveWord)GradeSchoolTest.this.ResultOfHaveWordForExtent[GradeSchoolTest.this.school.DB] -[error] (beWord: org.scalatest.words.BeWord)GradeSchoolTest.this.ResultOfBeWordForAny[GradeSchoolTest.this.school.DB] -[error] (inv: org.scalactic.TripleEqualsSupport.TripleEqualsInvocationOnSpread[GradeSchoolTest.this.school.DB])(implicit ev: Numeric[GradeSchoolTest.this.school.DB]): org.scalatest.Assertion -[error] [U](inv: org.scalactic.TripleEqualsSupport.TripleEqualsInvocation[U])(implicit constraint: org.scalactic.CanEqual[GradeSchoolTest.this.school.DB,U]): org.scalatest.Assertion -[error] (notWord: org.scalatest.words.NotWord)org.scalatest.words.ResultOfNotWordForAny[GradeSchoolTest.this.school.DB] -[error] [TYPECLASS1[_], TYPECLASS2[_]](rightMatcherFactory2: org.scalatest.matchers.MatcherFactory2[GradeSchoolTest.this.school.DB,TYPECLASS1,TYPECLASS2])(implicit typeClass1: TYPECLASS1[GradeSchoolTest.this.school.DB], typeClass2: TYPECLASS2[GradeSchoolTest.this.school.DB]): org.scalatest.Assertion -[error] [TYPECLASS1[_]](rightMatcherFactory1: org.scalatest.matchers.MatcherFactory1[GradeSchoolTest.this.school.DB,TYPECLASS1])(implicit typeClass1: TYPECLASS1[GradeSchoolTest.this.school.DB]): org.scalatest.Assertion -[error] (rightMatcherX1: org.scalatest.matchers.Matcher[GradeSchoolTest.this.school.DB])org.scalatest.Assertion -[error] cannot be applied to (scala.collection.immutable.Map[Nothing,Nothing]) -[error] school.db should (Map()) -[error] ^ -[error] one error found -[error] (Compile / compileIncremental) Compilation failed -[error] Total time: 2 s, completed Feb 21, 2021, 2:37:03 PM +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:8: error: value should is not a member of Map[String,Int] + school.db should be (Map()) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:8: error: not found: value be + school.db should be (Map()) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:14: error: value should is not a member of Map[String,Int] + school.db should be (Map(2 -> Seq("Aimee"))) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:14: error: not found: value be + school.db should be (Map(2 -> Seq("Aimee"))) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:22: error: value should is not a member of Map[String,Int] + school.db should be (Map(2 -> Seq("James", "Blair", "Paul"))) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:22: error: not found: value be + school.db should be (Map(2 -> Seq("James", "Blair", "Paul"))) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:29: error: value should is not a member of Map[String,Int] + school.db should be (Map(3 -> Seq("Chelsea"), 7 -> Seq("Logan"))) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:29: error: not found: value be + school.db should be (Map(3 -> Seq("Chelsea"), 7 -> Seq("Logan"))) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:37: error: value should is not a member of Seq[String] + school.grade(5) should be (Seq("Franklin", "Bradley")) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:37: error: not found: value be + school.grade(5) should be (Seq("Franklin", "Bradley")) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:42: error: value should is not a member of Seq[String] + school.grade(1) should be (Seq()) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:42: error: not found: value be + school.grade(1) should be (Seq()) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:56: error: value should is not a member of Map[Int,Seq[String]] + school.sorted should be (sorted) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:56: error: not found: value be + school.sorted should be (sorted) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:57: error: value should is not a member of List[Int] + school.sorted.keys.toList should be (Seq(3, 4, 6)) + ^ +/tmp/exercise/src/test/scala/GradeSchoolTest.scala:57: error: not found: value be + school.sorted.keys.toList should be (Seq(3, 4, 6)) + ^ +16 errors diff --git a/src/test/scala/ApplicationSpec.scala b/src/test/scala/ApplicationSpec.scala index 00e8dfc..7b3415c 100644 --- a/src/test/scala/ApplicationSpec.scala +++ b/src/test/scala/ApplicationSpec.scala @@ -1,7 +1,8 @@ import org.json.JSONObject -import org.scalatest.{Matchers, FunSuite} +import org.scalatest.funsuite.AnyFunSuite +import org.scalatest.matchers.should.Matchers -class ApplicationSpec extends FunSuite with Matchers { +class ApplicationSpec extends AnyFunSuite with Matchers { test("A successful xml should pass simply") { val xmlTestURL = getClass.getResource("/GradeSchool_successful.xml").getPath diff --git a/tests/example-all-fail/build.sbt b/tests/example-all-fail/build.sbt index a330461..2fd8912 100644 --- a/tests/example-all-fail/build.sbt +++ b/tests/example-all-fail/build.sbt @@ -1,3 +1,3 @@ -scalaVersion := "2.12.8" +scalaVersion := "2.13.6" -libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test" \ No newline at end of file +libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.10" % "test" \ No newline at end of file diff --git a/tests/example-all-fail/project/build.properties b/tests/example-all-fail/project/build.properties deleted file mode 100644 index c06db1b..0000000 --- a/tests/example-all-fail/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.4.5 diff --git a/tests/example-all-fail/src/test/scala/ExampleAllFailTest.scala b/tests/example-all-fail/src/test/scala/ExampleAllFailTest.scala index aec2d61..7de1dda 100644 --- a/tests/example-all-fail/src/test/scala/ExampleAllFailTest.scala +++ b/tests/example-all-fail/src/test/scala/ExampleAllFailTest.scala @@ -1,7 +1,8 @@ -import org.scalatest.{Matchers, FunSuite} +import org.scalatest.funsuite.AnyFunSuite +import org.scalatest.matchers.should.Matchers /** @version 1.3.0 */ -class ExampleAllFailTest extends FunSuite with Matchers { +class ExampleAllFailTest extends AnyFunSuite with Matchers { test("year not divisible by 4: common year") { Leap.leapYear(2015) should be (false) diff --git a/tests/example-empty-file/build.sbt b/tests/example-empty-file/build.sbt index a330461..2fd8912 100644 --- a/tests/example-empty-file/build.sbt +++ b/tests/example-empty-file/build.sbt @@ -1,3 +1,3 @@ -scalaVersion := "2.12.8" +scalaVersion := "2.13.6" -libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test" \ No newline at end of file +libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.10" % "test" \ No newline at end of file diff --git a/tests/example-empty-file/expected_results.json b/tests/example-empty-file/expected_results.json index 0bbcb89..f9c4fe6 100644 --- a/tests/example-empty-file/expected_results.json +++ b/tests/example-empty-file/expected_results.json @@ -1 +1 @@ -{"message":"[error] /solution/src/test/scala/ExampleEmptyFileTest.scala:7:5: not found: value Leap\n[error] Leap.leapYear(2015) should be (false)\n[error] ^\n[error] /solution/src/test/scala/ExampleEmptyFileTest.scala:12:5: not found: value Leap\n[error] Leap.leapYear(1996) should be (true)\n[error] ^\n[error] /solution/src/test/scala/ExampleEmptyFileTest.scala:17:5: not found: value Leap\n[error] Leap.leapYear(2100) should be (false)\n[error] ^\n[error] /solution/src/test/scala/ExampleEmptyFileTest.scala:22:5: not found: value Leap\n[error] Leap.leapYear(2000) should be (true)\n[error] ^\n[error] four errors found\n[error] (Test / compileIncremental) Compilation failed\n[error] \n","version":2,"status":"error"} \ No newline at end of file +{"message":"/solution/src/test/scala/ExampleEmptyFileTest.scala:8: error: not found: value Leap\n Leap.leapYear(2015) should be (false)\n ^\n/solution/src/test/scala/ExampleEmptyFileTest.scala:13: error: not found: value Leap\n Leap.leapYear(1996) should be (true)\n ^\n/solution/src/test/scala/ExampleEmptyFileTest.scala:18: error: not found: value Leap\n Leap.leapYear(2100) should be (false)\n ^\n/solution/src/test/scala/ExampleEmptyFileTest.scala:23: error: not found: value Leap\n Leap.leapYear(2000) should be (true)\n ^\n4 errors\n","version":2,"status":"error"} \ No newline at end of file diff --git a/tests/example-empty-file/project/build.properties b/tests/example-empty-file/project/build.properties deleted file mode 100644 index c06db1b..0000000 --- a/tests/example-empty-file/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.4.5 diff --git a/tests/example-empty-file/src/test/scala/ExampleEmptyFileTest.scala b/tests/example-empty-file/src/test/scala/ExampleEmptyFileTest.scala index b63f9dd..14f78ce 100644 --- a/tests/example-empty-file/src/test/scala/ExampleEmptyFileTest.scala +++ b/tests/example-empty-file/src/test/scala/ExampleEmptyFileTest.scala @@ -1,7 +1,8 @@ -import org.scalatest.{Matchers, FunSuite} +import org.scalatest.funsuite.AnyFunSuite +import org.scalatest.matchers.should.Matchers /** @version 1.3.0 */ -class ExampleEmptyFileTest extends FunSuite with Matchers { +class ExampleEmptyFileTest extends AnyFunSuite with Matchers { test("year not divisible by 4: common year") { Leap.leapYear(2015) should be (false) diff --git a/tests/example-partial-fail/build.sbt b/tests/example-partial-fail/build.sbt index a330461..2fd8912 100644 --- a/tests/example-partial-fail/build.sbt +++ b/tests/example-partial-fail/build.sbt @@ -1,3 +1,3 @@ -scalaVersion := "2.12.8" +scalaVersion := "2.13.6" -libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test" \ No newline at end of file +libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.10" % "test" \ No newline at end of file diff --git a/tests/example-partial-fail/project/build.properties b/tests/example-partial-fail/project/build.properties deleted file mode 100644 index c06db1b..0000000 --- a/tests/example-partial-fail/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.4.5 diff --git a/tests/example-partial-fail/src/test/scala/ExamplePartialFailTest.scala b/tests/example-partial-fail/src/test/scala/ExamplePartialFailTest.scala index 8f511df..0d0ea58 100644 --- a/tests/example-partial-fail/src/test/scala/ExamplePartialFailTest.scala +++ b/tests/example-partial-fail/src/test/scala/ExamplePartialFailTest.scala @@ -1,7 +1,8 @@ -import org.scalatest.{Matchers, FunSuite} +import org.scalatest.funsuite.AnyFunSuite +import org.scalatest.matchers.should.Matchers /** @version 1.3.0 */ -class ExamplePartialFailTest extends FunSuite with Matchers { +class ExamplePartialFailTest extends AnyFunSuite with Matchers { test("year not divisible by 4: common year") { Leap.leapYear(2015) should be (false) diff --git a/tests/example-success/build.sbt b/tests/example-success/build.sbt index a330461..2fd8912 100644 --- a/tests/example-success/build.sbt +++ b/tests/example-success/build.sbt @@ -1,3 +1,3 @@ -scalaVersion := "2.12.8" +scalaVersion := "2.13.6" -libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test" \ No newline at end of file +libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.10" % "test" \ No newline at end of file diff --git a/tests/example-success/project/build.properties b/tests/example-success/project/build.properties deleted file mode 100644 index c06db1b..0000000 --- a/tests/example-success/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.4.5 diff --git a/tests/example-success/src/test/scala/ExampleSuccessTest.scala b/tests/example-success/src/test/scala/ExampleSuccessTest.scala index 05ec33b..914b091 100644 --- a/tests/example-success/src/test/scala/ExampleSuccessTest.scala +++ b/tests/example-success/src/test/scala/ExampleSuccessTest.scala @@ -1,7 +1,8 @@ -import org.scalatest.{Matchers, FunSuite} +import org.scalatest.funsuite.AnyFunSuite +import org.scalatest.matchers.should.Matchers /** @version 1.3.0 */ -class ExampleSuccessTest extends FunSuite with Matchers { +class ExampleSuccessTest extends AnyFunSuite with Matchers { test("year not divisible by 4: common year") { Leap.leapYear(2015) should be (false) diff --git a/tests/example-syntax-error/build.sbt b/tests/example-syntax-error/build.sbt index a330461..2fd8912 100644 --- a/tests/example-syntax-error/build.sbt +++ b/tests/example-syntax-error/build.sbt @@ -1,3 +1,3 @@ -scalaVersion := "2.12.8" +scalaVersion := "2.13.6" -libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test" \ No newline at end of file +libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.10" % "test" \ No newline at end of file diff --git a/tests/example-syntax-error/expected_results.json b/tests/example-syntax-error/expected_results.json index b0aa74d..5b15d35 100644 --- a/tests/example-syntax-error/expected_results.json +++ b/tests/example-syntax-error/expected_results.json @@ -1 +1 @@ -{"message":"[error] /solution/src/main/scala/ExampleSyntaxError.scala:1:1: expected class or object definition\n[error] objeTTTWE @#Leap\n[error] ^\n[error] one error found\n[error] (Compile / compileIncremental) Compilation failed\n[error] \n","version":2,"status":"error"} \ No newline at end of file +{"message":"/solution/src/main/scala/ExampleSyntaxError.scala:1: error: expected class or object definition\nobjeTTTWE @#Leap\n^\n1 error\n","version":2,"status":"error"} \ No newline at end of file diff --git a/tests/example-syntax-error/project/build.properties b/tests/example-syntax-error/project/build.properties deleted file mode 100644 index c06db1b..0000000 --- a/tests/example-syntax-error/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.4.5 diff --git a/tests/example-syntax-error/src/test/scala/ExampleSyntaxErrorTest.scala b/tests/example-syntax-error/src/test/scala/ExampleSyntaxErrorTest.scala index 5805d95..c422f83 100644 --- a/tests/example-syntax-error/src/test/scala/ExampleSyntaxErrorTest.scala +++ b/tests/example-syntax-error/src/test/scala/ExampleSyntaxErrorTest.scala @@ -1,7 +1,8 @@ -import org.scalatest.{Matchers, FunSuite} +import org.scalatest.funsuite.AnyFunSuite +import org.scalatest.matchers.should.Matchers /** @version 1.3.0 */ -class ExampleSyntaxErrorTest extends FunSuite with Matchers { +class ExampleSyntaxErrorTest extends AnyFunSuite with Matchers { test("year not divisible by 4: common year") { Leap.leapYear(2015) should be (false) diff --git a/tests/grade-school-error/build.sbt b/tests/grade-school-error/build.sbt new file mode 100644 index 0000000..2fd8912 --- /dev/null +++ b/tests/grade-school-error/build.sbt @@ -0,0 +1,3 @@ +scalaVersion := "2.13.6" + +libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.10" % "test" \ No newline at end of file diff --git a/tests/grade-school-error/expected_results.json b/tests/grade-school-error/expected_results.json new file mode 100644 index 0000000..d979ae7 --- /dev/null +++ b/tests/grade-school-error/expected_results.json @@ -0,0 +1 @@ +{"message":"/solution/src/test/scala/GradeSchoolTest.scala:10: error: value should is not a member of Map[String,Int]\n school.db should be (Map())\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:10: error: not found: value be\n school.db should be (Map())\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:16: error: value should is not a member of Map[String,Int]\n school.db should be (Map(2 -> Seq(\"Aimee\")))\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:16: error: not found: value be\n school.db should be (Map(2 -> Seq(\"Aimee\")))\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:24: error: value should is not a member of Map[String,Int]\n school.db should be (Map(2 -> Seq(\"James\", \"Blair\", \"Paul\")))\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:24: error: not found: value be\n school.db should be (Map(2 -> Seq(\"James\", \"Blair\", \"Paul\")))\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:31: error: value should is not a member of Map[String,Int]\n school.db should be (Map(3 -> Seq(\"Chelsea\"), 7 -> Seq(\"Logan\")))\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:31: error: not found: value be\n school.db should be (Map(3 -> Seq(\"Chelsea\"), 7 -> Seq(\"Logan\")))\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:39: error: value should is not a member of Seq[String]\n school.grade(5) should be (Seq(\"Franklin\", \"Bradley\"))\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:39: error: not found: value be\n school.grade(5) should be (Seq(\"Franklin\", \"Bradley\"))\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:44: error: value should is not a member of Seq[String]\n school.grade(1) should be (Seq())\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:44: error: not found: value be\n school.grade(1) should be (Seq())\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:58: error: value should is not a member of Map[Int,Seq[String]]\n school.sorted should be (sorted)\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:58: error: not found: value be\n school.sorted should be (sorted)\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:59: error: value should is not a member of List[Int]\n school.sorted.keys.toList should be (Seq(3, 4, 6))\n ^\n/solution/src/test/scala/GradeSchoolTest.scala:59: error: not found: value be\n school.sorted.keys.toList should be (Seq(3, 4, 6))\n ^\n16 errors\n","version":2,"status":"error"} \ No newline at end of file diff --git a/tests/grade-school-error/src/main/scala/School.scala b/tests/grade-school-error/src/main/scala/School.scala new file mode 100644 index 0000000..8e6c799 --- /dev/null +++ b/tests/grade-school-error/src/main/scala/School.scala @@ -0,0 +1,7 @@ +class School { + val db: Map[String, Int] = Map.empty + + def add(name: String, grade: Int): Unit = () + def grade(idx: Int): Seq[String] = Seq.empty + def sorted(): Map[Int, Seq[String]] = Map.empty +} diff --git a/tests/grade-school-error/src/test/scala/GradeSchoolTest.scala b/tests/grade-school-error/src/test/scala/GradeSchoolTest.scala new file mode 100644 index 0000000..abcc1b4 --- /dev/null +++ b/tests/grade-school-error/src/test/scala/GradeSchoolTest.scala @@ -0,0 +1,61 @@ +import org.scalatest.funsuite.AnyFunSuite +import org.scalatest.matchers.should.Matchers +import org.scalatest.OneInstancePerTest + +/** @version created manually **/ +class GradeSchoolTest extends AnyFunSuite with OneInstancePerTest { + val school = new School + + test ("empty school") { + school.db should be (Map()) + } + + test ("add student") { + // pending + school.add("Aimee", 2) + school.db should be (Map(2 -> Seq("Aimee"))) + } + + test ("add more students in same class") { + // pending + school.add("James", 2) + school.add("Blair", 2) + school.add("Paul", 2) + school.db should be (Map(2 -> Seq("James", "Blair", "Paul"))) + } + + test ("add students to different grades") { + // pending + school.add("Chelsea", 3) + school.add("Logan", 7) + school.db should be (Map(3 -> Seq("Chelsea"), 7 -> Seq("Logan"))) + } + + test ("get students in a grade") { + // pending + school.add("Franklin", 5) + school.add("Bradley", 5) + school.add("Jeff", 1) + school.grade(5) should be (Seq("Franklin", "Bradley")) + } + + test ("get students in a non-existent grade") { + // pending + school.grade(1) should be (Seq()) + } + + test ("sort school") { + // pending + school.add("Jennifer", 4) + school.add("Kareem", 6) + school.add("Christopher", 4) + school.add("Kyle", 3) + val sorted = Map( + 3 -> Seq("Kyle"), + 4 -> Seq("Christopher", "Jennifer"), + 6 -> Seq("Kareem") + ) + school.sorted should be (sorted) + school.sorted.keys.toList should be (Seq(3, 4, 6)) + } +}