-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from scottweaver/zio-2.0-RC4
[WIP] First pass at ZIO 2.0 RC4 compatibility.
- Loading branch information
Showing
25 changed files
with
1,526 additions
and
765 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 25 additions & 48 deletions
73
mock-tests/shared/src/test/scala/zio/mock/ComposedMockSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,39 @@ | ||
package zio.mock | ||
|
||
import zio._ | ||
import zio.test.{Assertion, assertM} | ||
|
||
import java.io.IOException | ||
import zio.test._ | ||
|
||
object ComposedMockSpec extends ZIOBaseSpec { | ||
|
||
import Assertion._ | ||
import Expectation._ | ||
|
||
private def testValueComposed[R1: EnvironmentTag, E, A](name: String)( | ||
mock: ULayer[R1], | ||
app: ZIO[R1, E, A], | ||
check: Assertion[A] | ||
) = test(name) { | ||
val result = ZIO.scoped[Any](mock.build.flatMap(app.provideEnvironment(_))) | ||
assertM(result)(check) | ||
} | ||
|
||
def spec = suite("ComposedMockSpec")( | ||
suite("mocking composed environments")( | ||
{ | ||
val cmd1 = MockClock.NanoTime(value(42L)) | ||
val cmd2 = MockConsole.PrintLine(equalTo("42"), unit) | ||
val composed = cmd1 ++ cmd2 | ||
|
||
val program = | ||
for { | ||
time <- Clock.nanoTime | ||
_ <- Console.printLine(time.toString) | ||
} yield () | ||
|
||
testValueComposed[Clock with Console, IOException, Unit]("Console with Clock")( | ||
composed, | ||
program, | ||
isUnit | ||
) | ||
}, { | ||
val cmd1 = MockRandom.NextInt(value(42)) | ||
val cmd2 = MockClock.Sleep(equalTo(42.seconds)) | ||
val cmd3 = MockSystem.Property(equalTo("foo"), value(None)) | ||
val cmd4 = MockConsole.PrintLine(equalTo("None"), unit) | ||
|
||
val composed = cmd1 ++ cmd2 ++ cmd3 ++ cmd4 | ||
|
||
val program = | ||
for { | ||
n <- Random.nextInt | ||
_ <- Clock.sleep(n.seconds) | ||
v <- System.property("foo") | ||
_ <- Console.printLine(v.toString) | ||
} yield () | ||
|
||
testValueComposed[Random with Clock with System with Console, Throwable, Unit]( | ||
"Random with Clock with System with Console" | ||
)(composed, program, isUnit) | ||
} | ||
test("Console with Clock") { | ||
for { | ||
time <- Clock.nanoTime | ||
_ <- Console.printLine(time.toString) | ||
} yield (assertTrue(true)) | ||
|
||
} @@ TestAspects.withExpectationsAsEnv( | ||
MockClock.NanoTime(value(42L)) ++ | ||
MockConsole.PrintLine(equalTo("42"), unit) | ||
), | ||
test("Random with Clock with System with Console") { | ||
|
||
for { | ||
n <- Random.nextInt | ||
_ <- Clock.sleep(n.seconds) | ||
v <- System.property("foo") | ||
_ <- Console.printLine(v.toString) | ||
} yield (assertTrue(true)) | ||
} @@ TestAspects.withExpectationsAsEnv( | ||
MockRandom.NextInt(value(42)) ++ | ||
MockClock.Sleep(equalTo(42.seconds)) ++ | ||
MockSystem.Property(equalTo("foo"), value(None)) ++ | ||
MockConsole.PrintLine(equalTo("None"), unit) | ||
) | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 44 additions & 61 deletions
105
mock-tests/shared/src/test/scala/zio/mock/MockTestReporterSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,55 @@ | ||
package zio.mock | ||
|
||
import zio.Scope | ||
import zio.mock.ReportingTestUtils._ | ||
import zio.test.Assertion._ | ||
import zio.test.TestAspect._ | ||
import zio.test._ | ||
|
||
object MockTestReporterSpec extends ZIOBaseSpec { | ||
|
||
def spec: ZSpec[ | ||
Annotations | ||
with Live | ||
with Sized | ||
with TestClock | ||
with TestConfig | ||
with TestConsole | ||
with TestRandom | ||
with TestSystem | ||
with Scope, | ||
Any | ||
] = | ||
def spec = | ||
suite("MockTestReporterSpec")( | ||
test("correctly reports a successful test") { | ||
assertM(runLog(test1))(equalTo(test1Expected.mkString + reportStats(1, 0, 0))) | ||
}, | ||
test("correctly reports a failed test") { | ||
assertM(runLog(test3))(equalTo(test3Expected.mkString + "\n" + reportStats(0, 0, 1))) | ||
}, | ||
test("correctly reports an error in a test") { | ||
for { | ||
log <- runLog(test4) | ||
} yield assertTrue(log.contains("Test 4 Fail")) | ||
}, | ||
test("correctly reports successful test suite") { | ||
assertM(runLog(suite1))(equalTo(suite1Expected.mkString + reportStats(2, 0, 0))) | ||
}, | ||
test("correctly reports failed test suite") { | ||
assertM(runLog(suite2))(equalTo(suite2Expected.mkString + "\n" + reportStats(2, 0, 1))) | ||
}, | ||
test("correctly reports multiple test suites") { | ||
assertM(runLog(suite3))(equalTo(suite3Expected.mkString + "\n" + reportStats(4, 0, 2))) | ||
}, | ||
test("correctly reports empty test suite") { | ||
assertM(runLog(suite4))(equalTo(suite4Expected.mkString + "\n" + reportStats(2, 0, 1))) | ||
}, | ||
test("correctly reports failure of simple assertion") { | ||
assertM(runLog(test5))(equalTo(test5Expected.mkString + "\n" + reportStats(0, 0, 1))) | ||
}, | ||
test("correctly reports multiple nested failures") { | ||
assertM(runLog(test6))(equalTo(test6Expected.mkString + "\n" + reportStats(0, 0, 1))) | ||
}, | ||
test("correctly reports labeled failures") { | ||
assertM(runLog(test7))(equalTo(test7Expected.mkString + "\n" + reportStats(0, 0, 1))) | ||
}, | ||
test("correctly reports negated failures") { | ||
assertM(runLog(test8))(equalTo(test8Expected.mkString + "\n" + reportStats(0, 0, 1))) | ||
}, | ||
test("correctly reports mock failure of invalid call") { | ||
runLog(mock1).map(str => assertTrue(str == mock1Expected.mkString + reportStats(0, 0, 1))) | ||
}, | ||
test("correctly reports mock failure of unmet expectations") { | ||
runLog(mock2).map(str => assertTrue(str == mock2Expected.mkString + reportStats(0, 0, 1))) | ||
}, | ||
test("correctly reports mock failure of unexpected call") { | ||
assertM(runLog(mock3))(equalTo(mock3Expected.mkString + reportStats(0, 0, 1))) | ||
}, | ||
test("correctly reports mock failure of invalid range") { | ||
assertM(runLog(mock4))(equalTo(mock4Expected.mkString + reportStats(0, 0, 1))) | ||
} | ||
suite("reports")( | ||
test("a successful test") { | ||
runLog(test1).map(res => assertTrue(test1Expected == res)) | ||
}, | ||
test("a failed test") { | ||
runLog(test3).map(res => test3Expected.map(expected => assertTrue(res.contains(expected))).reduce(_ && _)) | ||
}, | ||
test("an error in a test") { | ||
runLog(test4).map(log => assertTrue(log.contains("Test 4 Fail"))) | ||
} @@ ignore, | ||
test("successful test suite") { | ||
runLog(suite1).map(res => suite1Expected.map(expected => assertTrue(res.contains(expected))).reduce(_ && _)) | ||
}, | ||
test("failed test suite") { | ||
runLog(suite2).map(res => suite2Expected.map(expected => assertTrue(res.contains(expected))).reduce(_ && _)) | ||
}, | ||
test("multiple test suites") { | ||
runLog(suite3).map(res => suite3Expected.map(expected => assertTrue(res.contains(expected))).reduce(_ && _)) | ||
}, | ||
test("empty test suite") { | ||
runLog(suite4).map(res => suite4Expected.map(expected => assertTrue(res.contains(expected))).reduce(_ && _)) | ||
}, | ||
test("failure of simple assertion") { | ||
runLog(test5).map(res => test5Expected.map(expected => assertTrue(res.contains(expected))).reduce(_ && _)) | ||
}, | ||
test("multiple nested failures") { | ||
runLog(test6).map(res => test6Expected.map(expected => assertTrue(res.contains(expected))).reduce(_ && _)) | ||
}, | ||
test("labeled failures") { | ||
runLog(test7).map(res => test7Expected.map(expected => assertTrue(res.contains(expected))).reduce(_ && _)) | ||
}, | ||
test("labeled failures for assertTrue") { | ||
for { | ||
log <- runLog(test9) | ||
} yield assertTrue(log.contains("""?? "third""""), log.contains("""?? "fourth"""")) | ||
}, | ||
test("negated failures") { | ||
runLog(test8).map(res => test8Expected.map(expected => assertTrue(res.contains(expected))).reduce(_ && _)) | ||
} | ||
// test("correctly reports mock failure of invalid call") { | ||
// runLog(mock1).map(str => assertTrue(str == mock1Expected.mkString + reportStats(0, 0, 1))) | ||
// } | ||
) | ||
) @@ silent | ||
} |
Oops, something went wrong.