Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ object ConsoleTestOutputSpec extends ZIOBaseSpec {
test("empty test suite") {
runLog(suite4).map(res => containsUnstyled(res, suite4Expected))
},
test("nested suite with sequential tests") {
runLog(suite5).map(res => containsUnstyled(res, suite5Expected))
},
test("failure of simple assertion") {
runLog(test5).map(res => containsUnstyled(res, test5Expected))
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ object IntellijRendererSpec extends ZIOBaseSpec {
test("correctly reports empty test suite") {
runLog(suite4).map(res => suite4Expected.map(expected => containsUnstyled(res, expected)).reduce(_ && _))
},
test("nested suite with sequential tests") {
runLog(suite5).map(res => suite5Expected.map(expected => containsUnstyled(res, expected)).reduce(_ && _))
},
test("correctly reports failure of simple assertion") {
runLog(test5).map(res => test5Expected.map(expected => containsUnstyled(res, expected)).reduce(_ && _))
},
Expand Down Expand Up @@ -90,6 +93,15 @@ object IntellijRendererSpec extends ZIOBaseSpec {
) ++ suite1Expected ++ Vector(suiteStarted("Empty"), suiteFinished("Empty")) ++
test3Expected ++ Vector(suiteFinished("Suite4"))

def suite5Expected(implicit sourceLocation: SourceLocation): Vector[String] = Vector(
suiteStarted("Suite1"),
suiteStarted("Suite2"),
testStarted("Test1"),
testFinished("Test1"),
suiteFinished("Suite2"),
suiteFinished("Suite1")
)

def test5Expected(implicit sourceLocation: SourceLocation): Vector[String] = Vector(
testStarted("Addition works fine"),
testFailed(
Expand Down
14 changes: 14 additions & 0 deletions test-tests/shared/src/test/scala/zio/test/ReportingTestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,20 @@ object ReportingTestUtils {
test3Expected()
}

def suite5(implicit sourceLocation: SourceLocation): Spec[Any, Nothing] =
suite("Suite1")(
suite("Suite2")(
test("Test1")(assertCompletes)
) @@ TestAspect.sequential
)

def suite5Expected(implicit sourceLocation: SourceLocation): Vector[String] =
Vector(
expectedSuccess("Suite1"),
expectedSuccess("Suite2"),
expectedSuccess("Test1")
)

def assertSourceLocation()(implicit sourceLocation: SourceLocation): String =
cyan(s"at ${sourceLocation.path}:${sourceLocation.line} ")

Expand Down
22 changes: 11 additions & 11 deletions test/shared/src/main/scala/zio/test/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package zio

import zio.internal.stacktracer.{SourceLocation, Tracer}
import zio.stacktracer.TracingImplicits.disableAutoTrace
import zio.stream.{ZChannel, ZSink, ZStream}
import zio.stream.{ZSink, ZStream}
import zio.test.ReporterEventRenderer.ConsoleEventRenderer
import zio.test.Spec.LabeledCase
import zio.test.Spec.{ExecCase, LabeledCase}

import scala.language.implicitConversions

Expand Down Expand Up @@ -974,18 +974,18 @@ package object test extends CompileVariants {
Spec.labeled(
label,
if (specs.isEmpty) Spec.empty
else if (specs.length == 1) {
wrapIfLabelledCase(specs.head)
} else Spec.multiple(Chunk.fromIterable(specs).map(spec => suiteConstructor(spec)))
else if (specs.length == 1) wrapIfLabelledCase(specs.head)
else Spec.multiple(Chunk.fromIterable(specs).map(spec => suiteConstructor(spec)))
)

// Ensures we render suite label when we have an individual Labeled test case
private def wrapIfLabelledCase[In](spec: In)(implicit suiteConstructor: SuiteConstructor[In], trace: Trace) =
spec match {
case Spec(LabeledCase(_, _)) =>
Spec.multiple(Chunk(suiteConstructor(spec)))
case _ => suiteConstructor(spec)
// Ensures we render suite label when we have an individual Labeled / Exec test case
private def wrapIfLabelledCase[In](spec: In)(implicit suiteConstructor: SuiteConstructor[In], trace: Trace) = {
val suite = suiteConstructor(spec)
suite.caseValue match {
case _: LabeledCase[?] | _: ExecCase[?] => Spec.multiple(Chunk.single(suite))
case _ => suite
}
}

/**
* Builds a spec with a single test.
Expand Down
Loading