From a472c8d204bf2e2f1028a88ad914802841fee9dc Mon Sep 17 00:00:00 2001 From: "P. Oscar Boykin" Date: Sun, 24 Mar 2024 16:43:31 -1000 Subject: [PATCH] Change test evaluation (#1187) --- cli/src/main/scala/org/bykn/bosatsu/PathModule.scala | 10 +++++++++- core/src/main/scala/org/bykn/bosatsu/Evaluation.scala | 4 ++-- core/src/main/scala/org/bykn/bosatsu/Test.scala | 5 ++--- jsui/src/main/scala/org/bykn/bosatsu/jsui/Store.scala | 3 ++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cli/src/main/scala/org/bykn/bosatsu/PathModule.scala b/cli/src/main/scala/org/bykn/bosatsu/PathModule.scala index 0dc033b86..c6d667285 100644 --- a/cli/src/main/scala/org/bykn/bosatsu/PathModule.scala +++ b/cli/src/main/scala/org/bykn/bosatsu/PathModule.scala @@ -98,7 +98,15 @@ object PathModule extends MainModule[IO] { out match { case Output.TestOutput(resMap, color) => val hasMissing = resMap.exists(_._2.isEmpty) - val testReport = Test.outputFor(resMap, color) + // it would be nice to run in parallel, but + // MatchlessToValue is not currently threadsafe + val evalTest = resMap.map { + case (p, Some(evalTest)) => + (p, Some(evalTest.value)) + case (p, None) => (p, None) + } + + val testReport = Test.outputFor(evalTest, color) val success = !hasMissing && (testReport.fails == 0) val code = if (success) ExitCode.Success else ExitCode.Error print(testReport.doc.render(80)).as(code) diff --git a/core/src/main/scala/org/bykn/bosatsu/Evaluation.scala b/core/src/main/scala/org/bykn/bosatsu/Evaluation.scala index d10d6c03a..7a2368c49 100644 --- a/core/src/main/scala/org/bykn/bosatsu/Evaluation.scala +++ b/core/src/main/scala/org/bykn/bosatsu/Evaluation.scala @@ -90,7 +90,7 @@ case class Evaluation[T](pm: PackageMap.Typed[T], externals: Externals) { /** Return the last test, if any, in the package. this is the test that is run * when we test the package */ - def lastTest(p: PackageName): Option[Eval[Value]] = + def testValue(p: PackageName): Option[Eval[Value]] = for { pack <- pm.toMap.get(p) (name, _, _) <- Package.testValue(pack) @@ -123,7 +123,7 @@ case class Evaluation[T](pm: PackageMap.Typed[T], externals: Externals) { */ def evalTest(ps: PackageName): Option[Eval[Test]] = - lastTest(ps).map { ea => + testValue(ps).map { ea => ea.map(Test.fromValue(_)) } diff --git a/core/src/main/scala/org/bykn/bosatsu/Test.scala b/core/src/main/scala/org/bykn/bosatsu/Test.scala index 7999d9bf6..70d8d33f0 100644 --- a/core/src/main/scala/org/bykn/bosatsu/Test.scala +++ b/core/src/main/scala/org/bykn/bosatsu/Test.scala @@ -1,6 +1,5 @@ package org.bykn.bosatsu -import cats.Eval import org.typelevel.paiges.Doc sealed abstract class Test { @@ -100,12 +99,12 @@ object Test { } def outputFor( - resultList: List[(PackageName, Option[Eval[Test]])], + resultList: List[(PackageName, Option[Test])], color: LocationMap.Colorize ): Report = { val noTests = resultList.collect { case (p, None) => p } val results = resultList - .collect { case (p, Some(t)) => (p, Test.report(t.value, color)) } + .collect { case (p, Some(t)) => (p, Test.report(t, color)) } .sortBy(_._1) val successes = results.iterator.map { case (_, Report(s, _, _)) => s }.sum diff --git a/jsui/src/main/scala/org/bykn/bosatsu/jsui/Store.scala b/jsui/src/main/scala/org/bykn/bosatsu/jsui/Store.scala index 937dd6d38..d941e6125 100644 --- a/jsui/src/main/scala/org/bykn/bosatsu/jsui/Store.scala +++ b/jsui/src/main/scala/org/bykn/bosatsu/jsui/Store.scala @@ -51,7 +51,8 @@ object Store { ) val handler: HandlerFn = { case memoryMain.Output.TestOutput(resMap, color) => - val testReport = Test.outputFor(resMap, color) + val evaluatedTests = resMap.map { case (p, opt) => (p, opt.map(_.value)) } + val testReport = Test.outputFor(evaluatedTests, color) testReport.doc.render(80) case other => s"internal error. got unexpected result: $other"