Skip to content

Commit

Permalink
Change test evaluation (#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek committed Mar 25, 2024
1 parent 7d680b6 commit a472c8d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
10 changes: 9 additions & 1 deletion cli/src/main/scala/org/bykn/bosatsu/PathModule.scala
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/org/bykn/bosatsu/Evaluation.scala
Expand Up @@ -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)
Expand Down Expand Up @@ -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(_))
}

Expand Down
5 changes: 2 additions & 3 deletions 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 {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion jsui/src/main/scala/org/bykn/bosatsu/jsui/Store.scala
Expand Up @@ -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"
Expand Down

0 comments on commit a472c8d

Please sign in to comment.