Skip to content

Commit

Permalink
Rename TestContext to Testbed
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Jan 8, 2025
1 parent e2c73fe commit 70825cb
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/core/probably-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ extension [TestType](test: Test[TestType])

assert[ReportType](pf.isDefinedAt(_))

extension [ValueType](inline value: ValueType)(using inline test: TestContext)
extension [ValueType](inline value: ValueType)(using inline test: Testbed)
inline def debug: ValueType = ${Probably.debug('value, 'test)}

package testContexts:
given threadLocal: TestContext = new TestContext():
private val delegate: Option[TestContext] = Option(Runner.testContextThreadLocal.get()).map(_.nn).flatten
package testbeds:
given threadLocal: Testbed = new Testbed():
private val delegate: Option[Testbed] = Option(Runner.testbedThreadLocal.get()).map(_.nn).flatten

override def capture[ValueType: Inspectable](name: Text, value: ValueType): ValueType =
delegate.map(_.capture[ValueType](name, value)).getOrElse(value)
2 changes: 1 addition & 1 deletion src/core/probably.Probably.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ object Probably:
inc.include(runner.report, test.id, outcome)
result(run)

def debug[TestType: Type](expr: Expr[TestType], test: Expr[TestContext])(using Quotes): Expr[TestType] =
def debug[TestType: Type](expr: Expr[TestType], test: Expr[Testbed])(using Quotes): Expr[TestType] =
import quotes.reflect.*

val exprName: Text = expr.asTerm.pos match
Expand Down
8 changes: 4 additions & 4 deletions src/core/probably.Runner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import rudiments.*
import vacuous.*

object Runner:
private[probably] val testContextThreadLocal: ThreadLocal[Option[TestContext]] = ThreadLocal()
private[probably] val testbedThreadLocal: ThreadLocal[Option[Testbed]] = ThreadLocal()

class Runner[ReportType]()(using reporter: Reporter[ReportType]):
private var active: Set[TestId] = Set()
Expand All @@ -31,8 +31,8 @@ class Runner[ReportType]()(using reporter: Reporter[ReportType]):

def run[T, S](test: Test[T]): Trial[T] =
synchronized { active += test.id }
val ctx = TestContext()
Runner.testContextThreadLocal.set(Some(ctx))
val ctx = Testbed()
Runner.testbedThreadLocal.set(Some(ctx))
val ns0 = System.nanoTime

try
Expand All @@ -53,7 +53,7 @@ class Runner[ReportType]()(using reporter: Reporter[ReportType]):
synchronized { active -= test.id }

finally
Runner.testContextThreadLocal.set(None)
Runner.testbedThreadLocal.set(None)

def suite(suite: TestSuite, block: TestSuite ?=> Unit): Unit =
if !skip(suite.id) then
Expand Down
2 changes: 1 addition & 1 deletion src/core/probably.Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package probably

case class Test[+ReturnType](id: TestId, action: TestContext => ReturnType)
case class Test[+ReturnType](id: TestId, action: Testbed => ReturnType)
2 changes: 1 addition & 1 deletion src/core/probably.TestId.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ case class TestId(name: Text, suite: Optional[TestSuite], codepoint: Codepoint):
lazy val id: Text = (suite.hashCode ^ name.hashCode).hex.pad(6, Rtl, '0').keep(6, Rtl)
lazy val ids: List[Text] = id :: suite.let(_.id.ids).or(Nil)

def apply[ResultType](ctx: TestContext ?=> ResultType): Test[ResultType] =
def apply[ResultType](ctx: Testbed ?=> ResultType): Test[ResultType] =
Test[ResultType](this, ctx(using _))

def depth: Int = suite.let(_.id.depth).or(0) + 1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import spectacular.*

import scala.collection.mutable as scm

open class TestContext():
open class Testbed():
private[probably] val captured: scm.ArrayBuffer[(Text, Text)] = scm.ArrayBuffer()

def capture[ValueType: Inspectable](name: Text, value: ValueType): ValueType =
Expand Down
4 changes: 2 additions & 2 deletions src/core/soundness+probably-core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package soundness

export probably.{Baseline, Benchmark, Details, Inclusion, Outcome, Runner, Test, TestContext,
export probably.{Baseline, Benchmark, Details, Inclusion, Outcome, Runner, Test, Testbed,
TestId, TestReport, Reporter, Trial, TestSuite, Tolerance, Min, Mean, Max, BySpeed,
ByTime, Ratio, Difference, `+/-`, meets, test, suite, aspire, assert, check, matches, debug}

package testContexts:
export probably.testContexts.{threadLocal}
export probably.testbeds.{threadLocal}

0 comments on commit 70825cb

Please sign in to comment.