Skip to content

Commit

Permalink
Tests: remove deprecated adapter, closes #3072 (#4372)
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti authored Jan 31, 2025
1 parent aa26d9b commit d1a5b43
Show file tree
Hide file tree
Showing 159 changed files with 7,127 additions and 7,209 deletions.
1 change: 1 addition & 0 deletions packages/effect/src/Either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ export const getOrThrowWith: {
throw onLeft(self.left)
})

// TODO(4.0): by default should throw `L` (i.e getOrThrowWith with the identity function)
/**
* Extracts the value of an `Either` or throws if the `Either` is `Left`.
*
Expand Down
8 changes: 4 additions & 4 deletions packages/effect/test/Channel/constructors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { describe } from "vitest"

describe("Channel", () => {
it.effect("succeed", () =>
Effect.gen(function*($) {
const [chunk, value] = yield* $(Channel.runCollect(Channel.succeed(1)))
Effect.gen(function*() {
const [chunk, value] = yield* Channel.runCollect(Channel.succeed(1))
assertTrue(Chunk.isEmpty(chunk))
strictEqual(value, 1)
}))

it.effect("fail", () =>
Effect.gen(function*($) {
const result = yield* $(Effect.exit(Channel.runCollect(Channel.fail("uh oh"))))
Effect.gen(function*() {
const result = yield* Effect.exit(Channel.runCollect(Channel.fail("uh oh")))
deepStrictEqual(result, Exit.fail("uh oh"))
}))
})
16 changes: 8 additions & 8 deletions packages/effect/test/Channel/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export const isNumberService = (u: unknown): u is NumberService => {

describe("Channel", () => {
it.effect("provide - simple", () =>
Effect.gen(function*($) {
const result = yield* $(
Effect.gen(function*() {
const result = yield* pipe(
NumberService,
Channel.provideService(NumberService, new NumberServiceImpl(100)),
Channel.run
Expand All @@ -54,8 +54,8 @@ describe("Channel", () => {
}))

it.effect("provide -> zip -> provide", () =>
Effect.gen(function*($) {
const result = yield* $(
Effect.gen(function*() {
const result = yield* pipe(
NumberService,
Channel.provideService(NumberService, new NumberServiceImpl(100)),
Channel.zip(
Expand All @@ -70,8 +70,8 @@ describe("Channel", () => {
}))

it.effect("concatMap(provide).provide", () =>
Effect.gen(function*($) {
const [chunk, value] = yield* $(
Effect.gen(function*() {
const [chunk, value] = yield* pipe(
Channel.fromEffect(NumberService),
Channel.emitCollect,
Channel.mapOut((tuple) => tuple[1]),
Expand All @@ -91,15 +91,15 @@ describe("Channel", () => {
}))

it.effect("provide is modular", () =>
Effect.gen(function*($) {
Effect.gen(function*() {
const channel1 = Channel.fromEffect(NumberService)
const channel2 = pipe(
NumberService,
Effect.provide(pipe(Context.empty(), Context.add(NumberService, new NumberServiceImpl(2)))),
Channel.fromEffect
)
const channel3 = Channel.fromEffect(NumberService)
const [[result1, result2], result3] = yield* $(
const [[result1, result2], result3] = yield* pipe(
channel1,
Channel.zip(channel2),
Channel.zip(channel3),
Expand Down
22 changes: 11 additions & 11 deletions packages/effect/test/Channel/error-handling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { describe } from "vitest"

describe("Channel", () => {
it.effect("catchAll - structure confusion", () =>
Effect.gen(function*($) {
Effect.gen(function*() {
const channel = pipe(
Channel.write(8),
Channel.catchAll(() =>
Expand All @@ -21,36 +21,36 @@ describe("Channel", () => {
),
Channel.concatMap(() => Channel.fail("error2"))
)
const result = yield* $(Effect.exit(Channel.runCollect(channel)))
const result = yield* (Effect.exit(Channel.runCollect(channel)))
deepStrictEqual(result, Exit.fail("error2"))
}))

it.effect("error cause is propagated on channel interruption", () =>
Effect.gen(function*($) {
const deferred = yield* $(Deferred.make<void>())
const finished = yield* $(Deferred.make<void>())
const ref = yield* $(Ref.make<Exit.Exit<void>>(Exit.void))
Effect.gen(function*() {
const deferred = yield* (Deferred.make<void>())
const finished = yield* (Deferred.make<void>())
const ref = yield* (Ref.make<Exit.Exit<void>>(Exit.void))
const effect = pipe(
Deferred.succeed(deferred, void 0),
Effect.zipRight(Effect.never)
)
yield* $(
yield* pipe(
Channel.fromEffect(effect),
Channel.runDrain,
Effect.onExit((exit) => Ref.set(ref, exit as Exit.Exit<void>)),
Effect.ensuring(Deferred.succeed(finished, void 0)),
Effect.race(Deferred.await(deferred)),
Effect.either
)
yield* $(Deferred.await(finished)) // Note: interruption in race is now done in the background
const result = yield* $(Ref.get(ref))
yield* (Deferred.await(finished)) // Note: interruption in race is now done in the background
const result = yield* (Ref.get(ref))
assertTrue(Exit.isInterrupted(result))
}))

it.effect("scoped failures", () =>
Effect.gen(function*($) {
Effect.gen(function*() {
const channel = Channel.scoped(Effect.fail("error"))
const result = yield* $(Channel.runCollect(channel), Effect.exit)
const result = yield* pipe(Channel.runCollect(channel), Effect.exit)
deepStrictEqual(result, Exit.fail("error"))
}))
})
30 changes: 15 additions & 15 deletions packages/effect/test/Channel/finalization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const Second = (first: First): Second => ({ _tag: "Second", first })

describe("Channel", () => {
it.effect("ensuring - prompt closure between continuations", () =>
Effect.gen(function*($) {
const ref = yield* $(Ref.make<ReadonlyArray<string>>([]))
Effect.gen(function*() {
const ref = yield* (Ref.make<ReadonlyArray<string>>([]))
const event = (label: string) => Ref.update(ref, (array) => [...array, label])
const channel = pipe(
Channel.fromEffect(event("Acquire1")),
Expand All @@ -37,7 +37,7 @@ describe("Channel", () => {
)
)
)
const result = yield* $(Channel.runDrain(channel), Effect.zipRight(Ref.get(ref)))
const result = yield* pipe(Channel.runDrain(channel), Effect.zipRight(Ref.get(ref)))
deepStrictEqual(result, [
"Acquire1",
"Release11",
Expand All @@ -48,8 +48,8 @@ describe("Channel", () => {
}))

it.effect("ensuring - last finalizers are deferred to the scope", () =>
Effect.gen(function*($) {
const ref = yield* $(Ref.make<ReadonlyArray<string>>([]))
Effect.gen(function*() {
const ref = yield* (Ref.make<ReadonlyArray<string>>([]))
function event(label: string) {
return Ref.update(ref, (array) => [...array, label])
}
Expand All @@ -65,7 +65,7 @@ describe("Channel", () => {
),
Channel.ensuring(event("ReleaseOuter"))
)
const [eventsInScope, eventsOutsideScope] = yield* $(
const [eventsInScope, eventsOutsideScope] = yield* pipe(
Channel.toPull(channel),
Effect.flatMap((pull) => pipe(Effect.exit(pull), Effect.zipRight(Ref.get(ref)))),
Effect.scoped,
Expand All @@ -88,8 +88,8 @@ describe("Channel", () => {
}))

it.effect("ensuring - mixture of concatMap and ensuring", () =>
Effect.gen(function*($) {
const ref = yield* $(Ref.make<ReadonlyArray<string>>([]))
Effect.gen(function*() {
const ref = yield* (Ref.make<ReadonlyArray<string>>([]))
const event = (label: string) => Ref.update(ref, (array) => [...array, label])
const channel = pipe(
Channel.writeAll(1, 2, 3),
Expand All @@ -109,7 +109,7 @@ describe("Channel", () => {
),
Channel.ensuring(event("Second concatMap"))
)
const [[elements], events] = yield* $(
const [[elements], events] = yield* pipe(
Channel.runCollect(channel),
Effect.zip(Ref.get(ref))
)
Expand All @@ -132,8 +132,8 @@ describe("Channel", () => {
}))

it.effect("ensuring - finalizer ordering 2", () =>
Effect.gen(function*($) {
const ref = yield* $(Ref.make<ReadonlyArray<string>>([]))
Effect.gen(function*() {
const ref = yield* (Ref.make<ReadonlyArray<string>>([]))
const event = (label: string) => Ref.update(ref, (array) => [...array, label])
const channel = pipe(
Channel.writeAll(1, 2),
Expand All @@ -145,8 +145,8 @@ describe("Channel", () => {
)
)
)
yield* $(Channel.runDrain(channel))
const result = yield* $(Ref.get(ref))
yield* (Channel.runDrain(channel))
const result = yield* (Ref.get(ref))
deepStrictEqual(Array.from(result), [
"pulled 1",
"close 1",
Expand All @@ -156,8 +156,8 @@ describe("Channel", () => {
}))

it.effect("ensuring - finalizer failure is propagated", () =>
Effect.gen(function*(_) {
const result = yield* _(
Effect.gen(function*() {
const result = yield* pipe(
Channel.void,
Channel.ensuring(Effect.dieMessage("die")),
Channel.ensuring(Effect.void),
Expand Down
30 changes: 12 additions & 18 deletions packages/effect/test/Channel/foreign.test.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
import * as Channel from "effect/Channel"
import * as Context from "effect/Context"
import * as Effect from "effect/Effect"
import * as Either from "effect/Either"
import * as Exit from "effect/Exit"
import * as Option from "effect/Option"
import * as Random from "effect/Random"
import { Channel, Context, Effect, Either, Exit, Option, pipe, Random } from "effect"
import { strictEqual } from "effect/test/util"
import * as it from "effect/test/utils/extend"
import { unify } from "effect/Unify"
import { describe } from "vitest"

describe("Channel.Foreign", () => {
it.effect("Tag", () =>
Effect.gen(function*($) {
Effect.gen(function*() {
const tag = Context.GenericTag<number>("number")
const result = yield* $(tag, Channel.run, Effect.provideService(tag, 10))
const result = yield* pipe(tag, Channel.run, Effect.provideService(tag, 10))
strictEqual(result, 10)
}))

it.effect("Unify", () =>
Effect.gen(function*($) {
const unifiedEffect = unify((yield* $(Random.nextInt)) > 1 ? Effect.succeed(0) : Effect.fail(1))
const unifiedExit = unify((yield* $(Random.nextInt)) > 1 ? Exit.succeed(0) : Exit.fail(1))
const unifiedEither = unify((yield* $(Random.nextInt)) > 1 ? Either.right(0) : Either.left(1))
const unifiedOption = unify((yield* $(Random.nextInt)) > 1 ? Option.some(0) : Option.none())
strictEqual(yield* $(Channel.run(unifiedEffect)), 0)
strictEqual(yield* $(Channel.run(unifiedExit)), 0)
strictEqual(yield* $(Channel.run(unifiedEither)), 0)
strictEqual(yield* $(Channel.run(unifiedOption)), 0)
Effect.gen(function*() {
const unifiedEffect = unify((yield* (Random.nextInt)) > 1 ? Effect.succeed(0) : Effect.fail(1))
const unifiedExit = unify((yield* (Random.nextInt)) > 1 ? Exit.succeed(0) : Exit.fail(1))
const unifiedEither = unify((yield* (Random.nextInt)) > 1 ? Either.right(0) : Either.left(1))
const unifiedOption = unify((yield* (Random.nextInt)) > 1 ? Option.some(0) : Option.none())
strictEqual(yield* (Channel.run(unifiedEffect)), 0)
strictEqual(yield* (Channel.run(unifiedExit)), 0)
strictEqual(yield* (Channel.run(unifiedEither)), 0)
strictEqual(yield* (Channel.run(unifiedOption)), 0)
}))
})
56 changes: 28 additions & 28 deletions packages/effect/test/Channel/interruption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,78 @@ import { describe } from "vitest"

describe("Channel", () => {
it.effect("interruptWhen - interrupts the current element", () =>
Effect.gen(function*($) {
const interrupted = yield* $(Ref.make(false))
const latch = yield* $(Deferred.make<void>())
const halt = yield* $(Deferred.make<void>())
const started = yield* $(Deferred.make<void>())
Effect.gen(function*() {
const interrupted = yield* (Ref.make(false))
const latch = yield* (Deferred.make<void>())
const halt = yield* (Deferred.make<void>())
const started = yield* (Deferred.make<void>())
const channel = pipe(
Deferred.succeed(started, void 0),
Effect.zipRight(Deferred.await(latch)),
Effect.onInterrupt(() => Ref.set(interrupted, true)),
Channel.fromEffect,
Channel.interruptWhen(Deferred.await(halt))
)
const fiber = yield* $(Effect.fork(Channel.runDrain(channel)))
yield* $(
const fiber = yield* (Effect.fork(Channel.runDrain(channel)))
yield* pipe(
Deferred.await(started),
Effect.zipRight(Deferred.succeed(halt, void 0))
)
yield* $(Fiber.await(fiber))
const result = yield* $(Ref.get(interrupted))
yield* (Fiber.await(fiber))
const result = yield* (Ref.get(interrupted))
assertTrue(result)
}))

it.effect("interruptWhen - propagates errors", () =>
Effect.gen(function*($) {
const deferred = yield* $(Deferred.make<never, string>())
Effect.gen(function*() {
const deferred = yield* (Deferred.make<never, string>())
const channel = pipe(
Channel.fromEffect(Effect.never),
Channel.interruptWhen(Deferred.await(deferred))
)
yield* $(Deferred.fail(deferred, "fail"))
const result = yield* $(Effect.either(Channel.runDrain(channel)))
yield* (Deferred.fail(deferred, "fail"))
const result = yield* (Effect.either(Channel.runDrain(channel)))
assertLeft(result, "fail")
}))

it.effect("interruptWhenDeferred - interrupts the current element", () =>
Effect.gen(function*($) {
const interrupted = yield* $(Ref.make(false))
const latch = yield* $(Deferred.make<void>())
const halt = yield* $(Deferred.make<void>())
const started = yield* $(Deferred.make<void>())
Effect.gen(function*() {
const interrupted = yield* (Ref.make(false))
const latch = yield* (Deferred.make<void>())
const halt = yield* (Deferred.make<void>())
const started = yield* (Deferred.make<void>())
const channel = pipe(
Deferred.succeed(started, void 0),
Effect.zipRight(Deferred.await(latch)),
Effect.onInterrupt(() => Ref.set(interrupted, true)),
Channel.fromEffect,
Channel.interruptWhenDeferred(halt)
)
const fiber = yield* $(Effect.fork(Channel.runDrain(channel)))
yield* $(
const fiber = yield* (Effect.fork(Channel.runDrain(channel)))
yield* pipe(
Deferred.await(started),
Effect.zipRight(Deferred.succeed(halt, void 0))
)
yield* $(Fiber.await(fiber))
const result = yield* $(Ref.get(interrupted))
yield* (Fiber.await(fiber))
const result = yield* (Ref.get(interrupted))
assertTrue(result)
}))

it.effect("interruptWhenDeferred - propagates errors", () =>
Effect.gen(function*($) {
const deferred = yield* $(Deferred.make<never, string>())
Effect.gen(function*() {
const deferred = yield* (Deferred.make<never, string>())
const channel = pipe(
Channel.fromEffect(Effect.never),
Channel.interruptWhenDeferred(deferred)
)
yield* $(Deferred.fail(deferred, "fail"))
const result = yield* $(Effect.either(Channel.runDrain(channel)))
yield* (Deferred.fail(deferred, "fail"))
const result = yield* (Effect.either(Channel.runDrain(channel)))
assertLeft(result, "fail")
}))

it.effect("runScoped - in uninterruptible region", () =>
Effect.gen(function*(_) {
const result = yield* _(Effect.uninterruptible(Channel.run(Channel.void)))
Effect.gen(function*() {
const result = yield* Effect.uninterruptible(Channel.run(Channel.void))
strictEqual(result, undefined)
}))
})
Loading

0 comments on commit d1a5b43

Please sign in to comment.