import * as tracing_1 from "../../Tracing"
import * as tracing_2 from "../../Tracing"
const fileName_1 = "(@effect-ts/system): _src/Testing/TestExecutor/index.ts"
import * as Cause from "../../Cause"
import * as Tp from "../../Collections/Immutable/Tuple"
import * as T from "../../Effect"
import * as E from "../../Either"
import { pipe } from "../../Function"
import * as M from "../../Managed"
import * as ES from "../ExecutedSpec"
import * as Spec from "../Spec"
import * as TAM from "../TestAnnotationMap"
import * as TF from "../TestFailure"
export function defaultExecutor(env) {
  return {
    environment: env,
    run: (spec, defExec) =>
      M.use_(
        Spec.forEachExec(
          defExec,
          (e) =>
            E.fold_(
              Cause.failureOrCause(e),
              ({ tuple: [failure, annotations] }) =>
                T.succeed(
                  Tp.tuple(E.left(failure), annotations),
                  fileName_1 + ":39:26"
                ),
              (cause) =>
                T.succeed(
                  Tp.tuple(E.left(TF.halt(cause)), TAM.TestAnnotationMap.empty),
                  fileName_1 + ":41:26"
                )
            ),
          ({ tuple: [success, annotations] }) =>
            T.succeed(Tp.tuple(E.right(success), annotations), fileName_1 + ":44:22")
        )(Spec.provideLayer(env)(Spec.annotated(spec))),
        (_) =>
          M.useNow(
            Spec.foldM(defExec)((_) => {
              Spec.concreteSpecCase(_)

              switch (_._tag) {
                case "SuiteCase": {
                  const v = _
                  return M.map_(
                    v.specs,
                    (specs) =>
                      new ES.ExecutedSpec(new ES.ExecutedSuiteCase(v.label, specs)),
                    fileName_1 + ":57:28"
                  )
                }

                case "TestCase": {
                  const v = _
                  return T.toManaged(
                    T.map_(
                      v.test,
                      ({ tuple: [result, dynamicAnnotations] }) =>
                        new ES.ExecutedSpec(
                          new ES.ExecutedTestCase(
                            v.label,
                            result,
                            TAM.concat(v.annotations, dynamicAnnotations)
                          )
                        ),
                      fileName_1 + ":67:28"
                    )
                  )
                }
              }
            })(_),
            fileName_1 + ":83:21"
          ),
        fileName_1 + ":46:14"
      )
  }
}
//# sourceMappingURL=index.js.map
