Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change test evaluation #1187

Merged
merged 1 commit into from Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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