From bd8bf616b01260be601c6933952e34fe7530eb96 Mon Sep 17 00:00:00 2001 From: Adam Fraser Date: Tue, 3 May 2022 17:58:51 -0700 Subject: [PATCH] upgrade zio version (#130) --- build.sbt | 2 +- .../main/scala/zio/cli/examples/WcApp.scala | 7 +- .../shared/src/main/scala/zio/cli/Args.scala | 14 +- .../src/main/scala/zio/cli/CliConfig.scala | 4 +- .../src/main/scala/zio/cli/Command.scala | 12 +- .../src/main/scala/zio/cli/Options.scala | 24 ++-- .../src/main/scala/zio/cli/PrimType.scala | 12 +- .../scala/zio/cli/completion/Completion.scala | 2 +- .../main/scala/zio/cli/files/FileSystem.scala | 6 +- .../src/test/scala/zio/cli/CommandSpec.scala | 32 ++--- .../src/test/scala/zio/cli/FileArgsSpec.scala | 8 +- .../src/test/scala/zio/cli/OptionsSpec.scala | 52 ++++---- .../src/test/scala/zio/cli/PrimTypeSpec.scala | 34 ++--- .../zio/cli/completion/CompletionSpec.scala | 120 +++++++++--------- .../cli/completion/RegularLanguageSpec.scala | 97 +++++++------- 15 files changed, 214 insertions(+), 212 deletions(-) diff --git a/build.sbt b/build.sbt index d9185e99..be666164 100644 --- a/build.sbt +++ b/build.sbt @@ -28,7 +28,7 @@ inThisBuild( addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt") addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck") -val zioVersion = "2.0.0-RC5" +val zioVersion = "2.0.0-RC6" lazy val root = project .in(file(".")) diff --git a/examples/shared/src/main/scala/zio/cli/examples/WcApp.scala b/examples/shared/src/main/scala/zio/cli/examples/WcApp.scala index 132bb785..49cb04ab 100644 --- a/examples/shared/src/main/scala/zio/cli/examples/WcApp.scala +++ b/examples/shared/src/main/scala/zio/cli/examples/WcApp.scala @@ -61,8 +61,8 @@ object WcApp extends ZIOAppDefault { zio.Console.printLine(s"executing wc with args: $opts $paths").! *> ZIO .foreachPar[Any, Throwable, Path, WcResult, List](paths)({ path => - def option(bool: Boolean, sink: ZSink[Any, Nothing, Byte, Byte, Long]) - : ZSink[Any, Nothing, Byte, Byte, Option[Long]] = + def option(bool: Boolean, sink: ZSink[Any, Throwable, Byte, Byte, Long]) + : ZSink[Any, Throwable, Byte, Byte, Option[Long]] = if (bool) sink.map(Some(_)) else ZSink.succeed(None) val byteCount = option(opts.bytes, ZSink.count) @@ -75,7 +75,8 @@ object WcApp extends ZIOAppDefault { val charCount = option(opts.char, ZPipeline.utfDecode >>> ZSink.foldLeft[String, Long](0L)((s, e) => s + e.length)) - val zippedSinks: ZSink[Any, Nothing, Byte, Byte, (Option[Long], Option[Long], Option[Long], Option[Long])] = + val zippedSinks + : ZSink[Any, Throwable, Byte, Byte, (Option[Long], Option[Long], Option[Long], Option[Long])] = (byteCount <&> lineCount <&> wordCount <&> charCount) ZStream diff --git a/zio-cli/shared/src/main/scala/zio/cli/Args.scala b/zio-cli/shared/src/main/scala/zio/cli/Args.scala index 4424d80d..94e75f5f 100644 --- a/zio-cli/shared/src/main/scala/zio/cli/Args.scala +++ b/zio-cli/shared/src/main/scala/zio/cli/Args.scala @@ -16,7 +16,7 @@ import java.time.{ ZoneOffset => JZoneOffset, ZonedDateTime => JZonedDateTime } -import zio.{IO, Zippable} +import zio.{IO, ZIO, Zippable} import zio.cli.HelpDoc.Span /** @@ -94,7 +94,7 @@ object Args { case (None, Some(choices)) => s"Missing argument ${primType.typeName} with values $choices." case (None, None) => s"Missing argument ${primType.typeName}." } - IO.fail(HelpDoc.p(msg)) + ZIO.fail(HelpDoc.p(msg)) } private def name: String = "<" + pseudoName.getOrElse(primType.typeName) + ">" @@ -112,7 +112,7 @@ object Args { def synopsis: UsageSynopsis = UsageSynopsis.None def validate(args: List[String], conf: CliConfig): IO[HelpDoc, (List[String], Unit)] = - IO.succeed((args, ())) + ZIO.succeed((args, ())) } final case class Both[+A, +B](head: Args[A], tail: Args[B]) extends Args[(A, B)] { @@ -165,12 +165,12 @@ object Args { val max1 = max.getOrElse(Int.MaxValue) def loop(args: List[String], acc: List[A]): IO[HelpDoc, (List[String], List[A])] = - if (acc.length >= max1) IO.succeed(args -> acc) + if (acc.length >= max1) ZIO.succeed(args -> acc) else value .validate(args, conf) .foldZIO( - failure => if (acc.length >= min1 && args.isEmpty) IO.succeed(args -> acc) else IO.fail(failure), + failure => if (acc.length >= min1 && args.isEmpty) ZIO.succeed(args -> acc) else ZIO.fail(failure), { case (args, a) => loop(args, a :: acc) } ) @@ -192,8 +192,8 @@ object Args { def validate(args: List[String], conf: CliConfig): IO[HelpDoc, (List[String], B)] = value.validate(args, conf).flatMap { case (r, a) => f(a) match { - case Left(value) => IO.fail(value) - case Right(value) => IO.succeed((r, value)) + case Left(value) => ZIO.fail(value) + case Right(value) => ZIO.succeed((r, value)) } } } diff --git a/zio-cli/shared/src/main/scala/zio/cli/CliConfig.scala b/zio-cli/shared/src/main/scala/zio/cli/CliConfig.scala index f643949c..e6d5d680 100644 --- a/zio-cli/shared/src/main/scala/zio/cli/CliConfig.scala +++ b/zio-cli/shared/src/main/scala/zio/cli/CliConfig.scala @@ -1,6 +1,6 @@ package zio.cli -import zio.URIO +import zio.{URIO, ZIO} /** * A `CliConfig` describes how arguments from the command-line are to @@ -29,5 +29,5 @@ object CliConfig { */ val default: CliConfig = CliConfig(caseSensitive = false, autoCorrectLimit = 2) - val cliConfig: URIO[CliConfig, CliConfig] = URIO.service + val cliConfig: URIO[CliConfig, CliConfig] = ZIO.service } diff --git a/zio-cli/shared/src/main/scala/zio/cli/Command.scala b/zio-cli/shared/src/main/scala/zio/cli/Command.scala index d9979d5f..c6599953 100644 --- a/zio-cli/shared/src/main/scala/zio/cli/Command.scala +++ b/zio-cli/shared/src/main/scala/zio/cli/Command.scala @@ -126,7 +126,7 @@ object Command { if (args.headOption.exists(conf.normalizeCase(_) == conf.normalizeCase(name))) builtIn(args, conf) else - IO.fail(None) + ZIO.fail(None) def synopsis: UsageSynopsis = UsageSynopsis.Named(name, None) + options.synopsis + args.synopsis @@ -138,16 +138,16 @@ object Command { for { args <- args match { case head :: tail => - if (conf.normalizeCase(head) == conf.normalizeCase(name)) IO.succeed(tail) + if (conf.normalizeCase(head) == conf.normalizeCase(name)) ZIO.succeed(tail) else - IO.fail( + ZIO.fail( ValidationError( ValidationErrorType.CommandMismatch, HelpDoc.p(s"Unexpected command name: ${args.headOption}") ) ) case Nil => - IO.fail( + ZIO.fail( ValidationError(ValidationErrorType.CommandMismatch, HelpDoc.p(s"Missing command name: ${name}")) ) } @@ -231,9 +231,9 @@ object Command { CommandDirective.builtIn(BuiltInOption.ShowHelp(self.helpDoc)) )) help <- help match { - case CommandDirective.BuiltIn(BuiltInOption.ShowHelp(h)) => IO.succeed(h) + case CommandDirective.BuiltIn(BuiltInOption.ShowHelp(h)) => ZIO.succeed(h) case _ => - IO.fail( + ZIO.fail( ValidationError( ValidationErrorType.InvalidArgument, HelpDoc.empty diff --git a/zio-cli/shared/src/main/scala/zio/cli/Options.scala b/zio-cli/shared/src/main/scala/zio/cli/Options.scala index 67f8771b..771126d8 100644 --- a/zio-cli/shared/src/main/scala/zio/cli/Options.scala +++ b/zio-cli/shared/src/main/scala/zio/cli/Options.scala @@ -16,7 +16,7 @@ import java.time.{ ZoneOffset => JZoneOffset, ZonedDateTime => JZonedDateTime } -import zio.{IO, UIO, Zippable} +import zio.{IO, ZIO, Zippable} import zio.cli.HelpDoc.Span import zio.cli.HelpDoc.p import zio.cli.HelpDoc.Span._ @@ -183,7 +183,7 @@ object Options { def synopsis: UsageSynopsis = UsageSynopsis.None def validate(args: List[String], conf: CliConfig): IO[ValidationError, (List[String], Unit)] = - IO.succeed((args, ())) + ZIO.succeed((args, ())) override def modifySingle(f: SingleModifier): Options[Unit] = Empty @@ -200,7 +200,7 @@ object Options { options .validate(args, conf) .catchSome { - case error if error.isOptionMissing => UIO.succeed(args -> default) + case error if error.isOptionMissing => ZIO.succeed(args -> default) } override def modifySingle(f: SingleModifier): Options[A] = @@ -256,7 +256,7 @@ object Options { fullName, conf ) <= conf.autoCorrectLimit => - IO.fail( + ZIO.fail( ValidationError( ValidationErrorType.MissingValue, p(error(s"""The flag "$head" is not recognized. Did you mean $fullName?""")) @@ -267,7 +267,7 @@ object Options { (head :: args, a) } case Nil => - IO.fail(ValidationError(ValidationErrorType.MissingValue, p(error(s"Expected to find $fullName option.")))) + ZIO.fail(ValidationError(ValidationErrorType.MissingValue, p(error(s"Expected to find $fullName option.")))) } def uid: Option[String] = Some(fullName) @@ -306,7 +306,7 @@ object Options { .validate(args, conf) .foldZIO[Any, ValidationError, (List[String], Either[A, B])]( err2 => - IO.fail( + ZIO.fail( // orElse option is only missing in case neither option was given (err1.validationErrorType, err2.validationErrorType) match { case (ValidationErrorType.MissingValue, ValidationErrorType.MissingValue) => @@ -315,15 +315,15 @@ object Options { ValidationError(ValidationErrorType.InvalidValue, err1.error + err2.error) } ), - success => IO.succeed((success._1, Right(success._2))) + success => ZIO.succeed((success._1, Right(success._2))) ), r => right .validate(r._1, conf) .foldZIO( - _ => IO.succeed((r._1, Left(r._2))), + _ => ZIO.succeed((r._1, Left(r._2))), _ => - IO.fail( + ZIO.fail( ValidationError( ValidationErrorType.InvalidValue, p(error(s"Options collision detected. You can only specify either $left or $right.")) @@ -353,8 +353,8 @@ object Options { right .validate(args, conf) .foldZIO( - err2 => IO.fail(ValidationError(ValidationErrorType.MissingValue, err1.error + err2.error)), - _ => IO.fail(err1) + err2 => ZIO.fail(ValidationError(ValidationErrorType.MissingValue, err1.error + err2.error)), + _ => ZIO.fail(err1) ) ) (args, a) = tuple @@ -376,7 +376,7 @@ object Options { def synopsis: UsageSynopsis = value.synopsis def validate(args: List[String], conf: CliConfig): IO[ValidationError, (List[String], B)] = - value.validate(args, conf).flatMap(r => f(r._2).fold(e => IO.fail(e), s => IO.succeed(r._1 -> s))) + value.validate(args, conf).flatMap(r => f(r._2).fold(e => ZIO.fail(e), s => ZIO.succeed(r._1 -> s))) override def uid: Option[String] = value.uid diff --git a/zio-cli/shared/src/main/scala/zio/cli/PrimType.scala b/zio-cli/shared/src/main/scala/zio/cli/PrimType.scala index c4c6028e..1f4743de 100644 --- a/zio-cli/shared/src/main/scala/zio/cli/PrimType.scala +++ b/zio-cli/shared/src/main/scala/zio/cli/PrimType.scala @@ -113,8 +113,8 @@ object PrimType { def validate(value: Option[String], conf: CliConfig): IO[String, A] = (ZIO.fromOption(value) orElseFail "Enumeration options do not have a default value.").flatMap { value => cases.find(_._1 == value) match { - case None => IO.fail("Expected one of the following cases: " + cases.map(_._1).mkString(", ")) - case Some((_, a)) => IO.succeed(a) + case None => ZIO.fail("Expected one of the following cases: " + cases.map(_._1).mkString(", ")) + case Some((_, a)) => ZIO.succeed(a) } } } @@ -174,10 +174,10 @@ object PrimType { def validate(value: Option[String], conf: CliConfig): IO[String, Boolean] = value.map(conf.normalizeCase) match { - case Some(s) if Bool.TrueValues(s) => IO.succeed(true) - case Some(s) if Bool.FalseValues(s) => IO.succeed(false) - case Some(s) => IO.fail(s"$s cannot be recognized as valid boolean.") - case None => IO.fromOption(defaultValue).orElseFail("Missing default for bool parameter.") + case Some(s) if Bool.TrueValues(s) => ZIO.succeed(true) + case Some(s) if Bool.FalseValues(s) => ZIO.succeed(false) + case Some(s) => ZIO.fail(s"$s cannot be recognized as valid boolean.") + case None => ZIO.fromOption(defaultValue).orElseFail("Missing default for bool parameter.") } def helpDoc: HelpDoc.Span = text("A true or false value.") diff --git a/zio-cli/shared/src/main/scala/zio/cli/completion/Completion.scala b/zio-cli/shared/src/main/scala/zio/cli/completion/Completion.scala index fe786ca1..451274ae 100644 --- a/zio-cli/shared/src/main/scala/zio/cli/completion/Completion.scala +++ b/zio-cli/shared/src/main/scala/zio/cli/completion/Completion.scala @@ -46,7 +46,7 @@ object Completion { val derivative: UIO[RegularLanguage] = ZIO.foldLeft(unclustered)(language)((lang, word) => lang .derive(word) - .provideService(cliConfig) + .provideEnvironment(ZEnvironment(cliConfig)) ) val wordToComplete = if (index < words.size) words(index) else "" diff --git a/zio-cli/shared/src/main/scala/zio/cli/files/FileSystem.scala b/zio-cli/shared/src/main/scala/zio/cli/files/FileSystem.scala index e52567c4..dab14be5 100644 --- a/zio-cli/shared/src/main/scala/zio/cli/files/FileSystem.scala +++ b/zio-cli/shared/src/main/scala/zio/cli/files/FileSystem.scala @@ -23,13 +23,13 @@ object FileSystem { ZIO.attempt(JPaths.get(path)) orElseFail s"'$path' is not a recognized path." override def exists(path: JPath): UIO[Boolean] = - ZIO.attempt(JFiles.exists(path)) orElse IO.succeed(false) + ZIO.attempt(JFiles.exists(path)) orElse ZIO.succeed(false) override def isDirectory(path: JPath): UIO[Boolean] = - ZIO.attempt(JFiles.isDirectory(path)) orElse IO.succeed(false) + ZIO.attempt(JFiles.isDirectory(path)) orElse ZIO.succeed(false) override def isRegularFile(path: JPath): UIO[Boolean] = - ZIO.attempt(JFiles.isRegularFile(path)) orElse IO.succeed(false) + ZIO.attempt(JFiles.isRegularFile(path)) orElse ZIO.succeed(false) } } diff --git a/zio-cli/shared/src/test/scala/zio/cli/CommandSpec.scala b/zio-cli/shared/src/test/scala/zio/cli/CommandSpec.scala index 4584e33c..8da69f50 100644 --- a/zio-cli/shared/src/test/scala/zio/cli/CommandSpec.scala +++ b/zio-cli/shared/src/test/scala/zio/cli/CommandSpec.scala @@ -15,15 +15,15 @@ object CommandSpec extends ZIOSpecDefault { suite("Toplevel Command Spec")( suite("Command with options followed by args")( test("Should validate successfully") { - assertM(Tail.command.parse(List("tail", "-n", "100", "foo.log"), CliConfig.default))( + assertZIO(Tail.command.parse(List("tail", "-n", "100", "foo.log"), CliConfig.default))( equalTo(CommandDirective.UserDefined(List.empty[String], (BigInt(100), "foo.log"))) ) *> - assertM(Ag.command.parse(List("grep", "--after", "2", "--before", "3", "fooBar"), CliConfig.default))( + assertZIO(Ag.command.parse(List("grep", "--after", "2", "--before", "3", "fooBar"), CliConfig.default))( equalTo(CommandDirective.UserDefined(List.empty[String], ((BigInt(2), BigInt(3)), "fooBar"))) ) }, test("Should provide auto correct suggestions for misspelled options") { - assertM( + assertZIO( Ag.command .parse(List("grep", "--afte", "2", "--before", "3", "fooBar"), CliConfig.default) .either @@ -31,7 +31,7 @@ object CommandSpec extends ZIOSpecDefault { )( equalTo(Left(p(error("""The flag "--afte" is not recognized. Did you mean --after?""")))) ) *> - assertM( + assertZIO( Ag.command .parse(List("grep", "--after", "2", "--efore", "3", "fooBar"), CliConfig.default) .either @@ -39,7 +39,7 @@ object CommandSpec extends ZIOSpecDefault { )( equalTo(Left(p(error("""The flag "--efore" is not recognized. Did you mean --before?""")))) ) *> - assertM( + assertZIO( Ag.command .parse(List("grep", "--afte", "2", "--efore", "3", "fooBar"), CliConfig.default) .either @@ -56,7 +56,7 @@ object CommandSpec extends ZIOSpecDefault { ) }, test("Shows an error if an option is missing") { - assertM( + assertZIO( Ag.command .parse(List("grep", "--a", "2", "--before", "3", "fooBar"), CliConfig.default) .either @@ -72,7 +72,7 @@ object CommandSpec extends ZIOSpecDefault { val orElseCommand = Command("remote", Options.Empty, Args.none) | Command("log", Options.Empty, Args.none) - assertM(orElseCommand.parse(List("log"), CliConfig.default))( + assertZIO(orElseCommand.parse(List("log"), CliConfig.default))( equalTo(CommandDirective.UserDefined(Nil, ())) ) } @@ -89,8 +89,8 @@ object CommandSpec extends ZIOSpecDefault { val commandDirective = CommandDirective.UserDefined(Nil, ((true, true, true, true), List("filename"))) - assertM(clustered)(equalTo(commandDirective)) - assertM(unClustered)(equalTo(commandDirective)) + assertZIO(clustered)(equalTo(commandDirective)) + assertZIO(unClustered)(equalTo(commandDirective)) } ), suite("SubCommand Suite")( @@ -104,17 +104,17 @@ object CommandSpec extends ZIOSpecDefault { Vector( test("match first sub command without any surplus arguments") { - assertM(git.parse(List("git", "remote"), CliConfig.default))( + assertZIO(git.parse(List("git", "remote"), CliConfig.default))( equalTo(CommandDirective.UserDefined(Nil, ())) ) }, test("match first sub command with a surplus options") { - assertM(git.parse(List("git", "remote", "-v"), CliConfig.default))( + assertZIO(git.parse(List("git", "remote", "-v"), CliConfig.default))( equalTo(CommandDirective.UserDefined(List("-v"), ())) ) }, test("match second sub command without any surplus arguments") { - assertM(git.parse(List("git", "log"), CliConfig.default))( + assertZIO(git.parse(List("git", "log"), CliConfig.default))( equalTo(CommandDirective.UserDefined(Nil, ())) ) } @@ -129,12 +129,12 @@ object CommandSpec extends ZIOSpecDefault { Vector( test("test sub command with options and arguments") { - assertM(git.parse(List("git", "rebase", "-i", "upstream", "branch"), CliConfig.default))( + assertZIO(git.parse(List("git", "rebase", "-i", "upstream", "branch"), CliConfig.default))( equalTo(CommandDirective.UserDefined(Nil, (true, ("upstream", "branch")))) ) }, test("test unknown sub command") { - assertM(git.parse(List("git", "abc"), CliConfig.default).flip.map(_.validationErrorType))( + assertZIO(git.parse(List("git", "abc"), CliConfig.default).flip.map(_.validationErrorType))( equalTo(ValidationErrorType.CommandMismatch) ) }, @@ -160,7 +160,7 @@ object CommandSpec extends ZIOSpecDefault { ) test("sub sub command with option and argument")( - assertM(command.parse(List("command", "sub", "subsub", "-i", "text"), CliConfig.default))( + assertZIO(command.parse(List("command", "sub", "subsub", "-i", "text"), CliConfig.default))( equalTo(CommandDirective.UserDefined(Nil, (true, "text"))) ) ) @@ -170,7 +170,7 @@ object CommandSpec extends ZIOSpecDefault { suite("test adding helpdoc to commands")( test("add text helpdoc to Single") { val command = Command("tldr").withHelp("this is some help") - assertM(command.parse(List("tldr"), CliConfig.default))( + assertZIO(command.parse(List("tldr"), CliConfig.default))( equalTo(CommandDirective.UserDefined(Nil, ())) ) }, diff --git a/zio-cli/shared/src/test/scala/zio/cli/FileArgsSpec.scala b/zio-cli/shared/src/test/scala/zio/cli/FileArgsSpec.scala index c563a1a2..6b8997fb 100644 --- a/zio-cli/shared/src/test/scala/zio/cli/FileArgsSpec.scala +++ b/zio-cli/shared/src/test/scala/zio/cli/FileArgsSpec.scala @@ -14,26 +14,26 @@ object FileArgsSpec extends ZIOSpecDefault { test("Existing file") { val arg = Args.file("files", Exists.Yes).repeat - assertM( + assertZIO( arg.validate(argsFile.getAbsolutePath :: Nil, CliConfig.default) )(equalTo(List.empty[String] -> List(argsFilePath))) }, test("Not Found file") { val arg = Args.file("files", Exists.Yes).repeat - assertM( + assertZIO( arg.validate("notFound.file" :: Nil, CliConfig.default).either )(isLeft(equalTo(Paragraph(Text("Path 'notFound.file' must exist."))))) }, test("Non Existing file") { val arg = Args.file(Exists.No).repeat - assertM( + assertZIO( arg.validate("doesNotExist.file" :: Nil, CliConfig.default).either )(isRight) }, test("Combination of existing files") { val arg = Args.file.repeat - assertM( + assertZIO( arg.validate(List(argsFile.getAbsolutePath, argsFile.getAbsolutePath), CliConfig.default) )(equalTo(List.empty[String] -> List(argsFilePath, argsFilePath))) } diff --git a/zio-cli/shared/src/test/scala/zio/cli/OptionsSpec.scala b/zio-cli/shared/src/test/scala/zio/cli/OptionsSpec.scala index 534936ac..00a4b4af 100644 --- a/zio-cli/shared/src/test/scala/zio/cli/OptionsSpec.scala +++ b/zio-cli/shared/src/test/scala/zio/cli/OptionsSpec.scala @@ -24,7 +24,7 @@ object OptionsSpec extends ZIOSpecDefault { test("validate boolean option without value") { val r = b.validate(List("--verbose"), CliConfig.default) - assertM(r)(equalTo(List() -> true)) + assertZIO(r)(equalTo(List() -> true)) }, test("validate boolean option with followup option") { val o = Options.boolean("help", true) ++ Options.boolean("v", true) @@ -60,56 +60,56 @@ object OptionsSpec extends ZIOSpecDefault { }, test("validate text option 1") { val r = f.validate(List("--firstname", "John"), CliConfig.default) - assertM(r)(equalTo(List() -> "John")) + assertZIO(r)(equalTo(List() -> "John")) }, test("validate text option with alias") { val r = f.validate(List("-f", "John"), CliConfig.default) - assertM(r)(equalTo(List() -> "John")) + assertZIO(r)(equalTo(List() -> "John")) }, test("validate integer option") { val r = a.validate(List("--age", "100"), CliConfig.default) - assertM(r)(equalTo(List() -> BigInt(100))) + assertZIO(r)(equalTo(List() -> BigInt(100))) }, test("validate option and get remainder") { val r = f.validate(List("--firstname", "John", "--lastname", "Doe"), CliConfig.default) - assertM(r)(equalTo(List("--lastname", "Doe") -> "John")) + assertZIO(r)(equalTo(List("--lastname", "Doe") -> "John")) }, test("validate option and get remainder with different ordering") { val r = f.validate(List("--bar", "baz", "--firstname", "John", "--lastname", "Doe"), CliConfig.default) - assertM(r)(equalTo(List("--bar", "baz", "--lastname", "Doe") -> "John")) + assertZIO(r)(equalTo(List("--bar", "baz", "--lastname", "Doe") -> "John")) }, test("validate when no valid values are passed") { val r = f.validate(List("--lastname", "Doe"), CliConfig.default) - assertM(r.either)(isLeft) + assertZIO(r.either)(isLeft) }, test("validate when option is passed, but not a following value") { val r = f.validate(List("--firstname"), CliConfig.default) - assertM(r.either)(isLeft) + assertZIO(r.either)(isLeft) }, test("validate invalid option value") { val intOption = Options.integer("t") val v1 = intOption.validate(List("-t", "abc"), CliConfig.default) - assertM(v1.exit)( + assertZIO(v1.exit)( fails(equalTo(ValidationError(ValidationErrorType.InvalidValue, p(text("abc is not a integer."))))) ) }, test("validate missing option") { val intOption = Options.integer("t") val v1 = intOption.validate(List(), CliConfig.default) - assertM(v1.exit)( + assertZIO(v1.exit)( fails(equalTo(ValidationError(ValidationErrorType.MissingValue, p(error("Expected to find -t option."))))) ) }, test("validate invalid option using withDefault") { val o = Options.integer("integer").withDefault(BigInt(0), "0 as default") val r = o.validate(List("--integer", "abc"), CliConfig.default) - assertM(r.either)(isLeft) + assertZIO(r.either)(isLeft) }, test("validate collision of boolean option with negation") { val bNegation: Options[Boolean] = Options.boolean("v", true, "s") //.alias("v") val v1 = bNegation.validate(List("-v", "-s"), CliConfig.default) - assertM(v1.either)(isLeft) + assertZIO(v1.either)(isLeft) }, test("validate case sensitive CLI config") { val caseSensitiveConfig = CliConfig(true, 2) @@ -135,27 +135,27 @@ object OptionsSpec extends ZIOSpecDefault { List("--verbose", "true", "--firstname", "John", "--lastname", "Doe", "--age", "100", "--silent", "false"), CliConfig.default ) - assertM(r)(equalTo(List("--verbose", "true", "--silent", "false") -> (("John", "Doe", BigInt(100))))) + assertZIO(r)(equalTo(List("--verbose", "true", "--silent", "false") -> (("John", "Doe", BigInt(100))))) }, test("validate non supplied optional") { val r = aOpt.validate(List(), CliConfig.default) - assertM(r)(equalTo(List() -> None)) + assertZIO(r)(equalTo(List() -> None)) }, test("validate non supplied optional with remainder") { val r = aOpt.validate(List("--bar", "baz"), CliConfig.default) - assertM(r)(equalTo(List("--bar", "baz") -> None)) + assertZIO(r)(equalTo(List("--bar", "baz") -> None)) }, test("validate supplied optional") { val r = aOpt.validate(List("--age", "20"), CliConfig.default) - assertM(r)(equalTo(List() -> Some(BigInt(20)))) + assertZIO(r)(equalTo(List() -> Some(BigInt(20)))) }, test("validate supplied optional with remainder") { val r = aOpt.validate(List("--firstname", "John", "--age", "20", "--lastname", "Doe"), CliConfig.default) - assertM(r)(equalTo(List("--firstname", "John", "--lastname", "Doe") -> Some(BigInt(20)))) + assertZIO(r)(equalTo(List("--firstname", "John", "--lastname", "Doe") -> Some(BigInt(20)))) }, test("returns a HelpDoc if an option is not an exact match, but is close") { val r = f.validate(List("--firstme", "Alice"), CliConfig.default) - assertM(r.either)( + assertZIO(r.either)( equalTo( Left( ValidationError( @@ -294,46 +294,46 @@ object OptionsSpec extends ZIOSpecDefault { test("test orElse options collision") { val o = Options.text("string") | Options.integer("integer") val r = o.validate(List("--integer", "2", "--string", "two"), CliConfig.default) - assertM(r.either)(isLeft) + assertZIO(r.either)(isLeft) }, test("test orElse with no options given") { val o = Options.text("string") | Options.integer("integer") val r = o.validate(Nil, CliConfig.default) - assertM(r.either)(isLeft) + assertZIO(r.either)(isLeft) }, test("validate invalid option in OrElse option when using withDefault") { val o = (Options.integer("min") | Options.integer("max")).withDefault(BigInt(0), "0 as default") val r = o.validate(List("--min", "abc"), CliConfig.default) - assertM(r.either)(isLeft) + assertZIO(r.either)(isLeft) } ), test("returns a HelpDoc if an option is not an exact match and it's a short option") { val r = a.validate(List("--ag", "20"), CliConfig.default) - assertM(r.either)( + assertZIO(r.either)( equalTo(Left(ValidationError(ValidationErrorType.MissingValue, p(error("Expected to find --age option."))))) ) }, suite("property arguments")( test("validate missing option") { val r = m.validate(List(), CliConfig.default) - assertM(r.exit)( + assertZIO(r.exit)( fails(equalTo(ValidationError(ValidationErrorType.MissingValue, p(error("Expected to find --defs option."))))) ) }, test("validate repeated values") { val r = m.validate(List("-d", "key1=v1", "-d", "key2=v2", "--verbose"), CliConfig.default) - assertM(r)(equalTo(List("--verbose") -> Map("key1" -> "v1", "key2" -> "v2"))) + assertZIO(r)(equalTo(List("--verbose") -> Map("key1" -> "v1", "key2" -> "v2"))) }, test("validate different key/values with alias") { val r = m.validate(List("-d", "key1=v1", "key2=v2", "--verbose"), CliConfig.default) - assertM(r)(equalTo(List("--verbose") -> Map("key1" -> "v1", "key2" -> "v2"))) + assertZIO(r)(equalTo(List("--verbose") -> Map("key1" -> "v1", "key2" -> "v2"))) }, test("validate different key/values") { val r = m.validate(List("--defs", "key1=v1", "key2=v2", "--verbose"), CliConfig.default) - assertM(r)(equalTo(List("--verbose") -> Map("key1" -> "v1", "key2" -> "v2"))) + assertZIO(r)(equalTo(List("--verbose") -> Map("key1" -> "v1", "key2" -> "v2"))) } ) ) diff --git a/zio-cli/shared/src/test/scala/zio/cli/PrimTypeSpec.scala b/zio-cli/shared/src/test/scala/zio/cli/PrimTypeSpec.scala index e5df84dc..023a71d5 100644 --- a/zio-cli/shared/src/test/scala/zio/cli/PrimTypeSpec.scala +++ b/zio-cli/shared/src/test/scala/zio/cli/PrimTypeSpec.scala @@ -21,19 +21,19 @@ object PrimTypeSpec extends ZIOSpecDefault { suite("Text Suite") { test("validates everything") { check(Gen.string) { i => - assertM(PrimType.Text.validate(i))(equalTo(i)) + assertZIO(PrimType.Text.validate(i))(equalTo(i)) } } }, suite("Enumeration Suite")( test("validate return proper value if one of the cases") { check(anyPairs) { case ((selectedName, selectedValue), pairs) => - assertM(PrimType.Enumeration(pairs: _*).validate(selectedName))(equalTo(selectedValue)) + assertZIO(PrimType.Enumeration(pairs: _*).validate(selectedName))(equalTo(selectedValue)) } }, test("validate return error if NOT one of the cases") { check(anyPairs) { case (v @ (selectedName, _), pairs) => - assertM( + assertZIO( PrimType.Enumeration(pairs.filterNot(_ == v): _*).validate(selectedName).either )(isLeft(startsWithString(s"Expected one of the following cases:"))) } @@ -42,42 +42,42 @@ object PrimTypeSpec extends ZIOSpecDefault { suite("Boolean Suite")( test("validate true combinations returns proper Boolean representation") { check(anyTrueBooleanString) { i => - assertM(PrimType.Bool(None).validate(i))(equalTo(true)) + assertZIO(PrimType.Bool(None).validate(i))(equalTo(true)) } }, test("validate false combinations returns proper Boolean representation") { check(anyFalseBooleanString) { i => - assertM(PrimType.Bool(None).validate(i))(equalTo(false)) + assertZIO(PrimType.Bool(None).validate(i))(equalTo(false)) } }, test("validate rejects improper Boolean representation") { - assertM(PrimType.Bool(None).validate("bad").either)( + assertZIO(PrimType.Bool(None).validate("bad").either)( isLeft(equalTo("bad cannot be recognized as valid boolean.")) ) }, test("validate uses default value if value is not provided") { check(anyBoolean) { b => - assertM(PrimType.Bool(Some(b)).validate(None, CliConfig.default))((equalTo(b))) + assertZIO(PrimType.Bool(Some(b)).validate(None, CliConfig.default))((equalTo(b))) } } ), suite("Path Suite")( test("validate returns proper directory path") { - assertM( + assertZIO( PrimType .Path(PathType.Directory, shouldExist = Exists.Yes, mockFileSystem(pathIsDirectory = true)) .validate("path") )(equalTo(JPaths.get("path"))) }, test("validate returns proper directory path if both allowed") { - assertM( + assertZIO( PrimType .Path(PathType.Either, shouldExist = Exists.Yes, mockFileSystem(pathIsDirectory = true)) .validate("path") )(equalTo(JPaths.get("path"))) }, test("validate returns error if path targets file but directory was expected") { - assertM( + assertZIO( PrimType .Path(PathType.Directory, shouldExist = Exists.Yes, mockFileSystem(pathIsRegularFile = true)) .validate("path") @@ -85,21 +85,21 @@ object PrimTypeSpec extends ZIOSpecDefault { )(isLeft(equalTo("Expected path 'path' to be a directory."))) }, test("validate returns proper file path") { - assertM( + assertZIO( PrimType .Path(PathType.File, shouldExist = Exists.Yes, mockFileSystem(pathIsRegularFile = true)) .validate("path") )(equalTo(JPaths.get("path"))) }, test("validate returns proper file path if both allowed") { - assertM( + assertZIO( PrimType .Path(PathType.Either, shouldExist = Exists.Yes, mockFileSystem(pathIsRegularFile = true)) .validate("path") )(equalTo(JPaths.get("path"))) }, test("validate returns error if path targets directory but file was expected") { - assertM( + assertZIO( PrimType .Path(PathType.File, shouldExist = Exists.Yes, mockFileSystem(pathIsDirectory = true)) .validate("path") @@ -107,7 +107,7 @@ object PrimTypeSpec extends ZIOSpecDefault { )(isLeft(equalTo("Expected path 'path' to be a regular file."))) }, test("validate returns error if file doesn't exits but must exists") { - assertM( + assertZIO( PrimType .Path(PathType.Either, shouldExist = Exists.Yes, mockFileSystem(pathExists = false)) .validate("path") @@ -115,7 +115,7 @@ object PrimTypeSpec extends ZIOSpecDefault { )(isLeft(equalTo("Path 'path' must exist."))) }, test("validate returns error if file does exits but must not exists") { - assertM( + assertZIO( PrimType.Path(PathType.Either, shouldExist = Exists.No, mockFileSystem()).validate("path").either )(isLeft(equalTo("Path 'path' must not exist."))) } @@ -145,11 +145,11 @@ object PrimTypeSpec extends ZIOSpecDefault { suite(s"$primeTypeName Suite")( test(s"validate returns proper $primeTypeName representation") { check(gen) { i => - assertM(primType.validate(i.toString))(equalTo(i)) + assertZIO(primType.validate(i.toString))(equalTo(i)) } }, test(s"validate rejects improper $primeTypeName representation") { - assertM(primType.validate("bad").either)(isLeft(equalTo(s"bad is not a ${primType.typeName}."))) + assertZIO(primType.validate("bad").either)(isLeft(equalTo(s"bad is not a ${primType.typeName}."))) } ) diff --git a/zio-cli/shared/src/test/scala/zio/cli/completion/CompletionSpec.scala b/zio-cli/shared/src/test/scala/zio/cli/completion/CompletionSpec.scala index 0cf9fb89..c115d842 100644 --- a/zio-cli/shared/src/test/scala/zio/cli/completion/CompletionSpec.scala +++ b/zio-cli/shared/src/test/scala/zio/cli/completion/CompletionSpec.scala @@ -1,6 +1,6 @@ package zio.cli.completion -import zio.{Scope, ZTraceElement, ZIO} +import zio.{Scope, Trace, ZIO} import zio.stream.{ZStream, ZSink} import zio.test.Assertion._ import zio.test._ @@ -18,20 +18,20 @@ object CompletionSpec extends ZIOSpecDefault { * zio >= 2.0.0-RC3. */ object Files { - def createTempDirectoryScoped()(implicit trace: ZTraceElement): ZIO[Scope, IOException, JPath] = + def createTempDirectoryScoped()(implicit trace: Trace): ZIO[Scope, IOException, JPath] = ZIO.acquireRelease(createTempDirectory())(release = deleteRecursive(_).ignore) - def createTempDirectory()(implicit trace: ZTraceElement): ZIO[Any, IOException, JPath] = + def createTempDirectory()(implicit trace: Trace): ZIO[Any, IOException, JPath] = ZIO .attemptBlocking(JFiles.createTempDirectory(null)) .refineToOrDie[IOException] - def deleteRecursive(path: JPath)(implicit trace: ZTraceElement): ZIO[Any, IOException, Long] = + def deleteRecursive(path: JPath)(implicit trace: Trace): ZIO[Any, IOException, Long] = newDirectoryStream(path).mapZIO(delete).run(ZSink.count) <* delete(path) def newDirectoryStream( dir: JPath - )(implicit trace: ZTraceElement): ZStream[Any, IOException, JPath] = + )(implicit trace: Trace): ZStream[Any, IOException, JPath] = ZStream .fromJavaIteratorScoped[Any, JPath]( ZIO @@ -42,13 +42,13 @@ object CompletionSpec extends ZIOSpecDefault { ) .refineToOrDie[IOException] - def delete(path: JPath)(implicit trace: ZTraceElement): ZIO[Any, IOException, Unit] = + def delete(path: JPath)(implicit trace: Trace): ZIO[Any, IOException, Unit] = ZIO.attemptBlocking(JFiles.delete(path)).refineToOrDie[IOException] - def createFile(path: JPath)(implicit trace: ZTraceElement): ZIO[Any, IOException, Unit] = + def createFile(path: JPath)(implicit trace: Trace): ZIO[Any, IOException, Unit] = ZIO.attemptBlocking(JFiles.createFile(path)).unit.refineToOrDie[IOException] - def createDirectory(path: JPath)(implicit trace: ZTraceElement): ZIO[Any, IOException, Unit] = + def createDirectory(path: JPath)(implicit trace: Trace): ZIO[Any, IOException, Unit] = ZIO.attemptBlocking(JFiles.createDirectory(path)).unit.refineToOrDie[IOException] } @@ -60,7 +60,7 @@ object CompletionSpec extends ZIOSpecDefault { suite("Toplevel Command Completion Spec")( suite("Command name")( test("A different command name in the args list should not affect completion") { - assertM( + assertZIO( Completion.complete( List("foo-alias"), 1, @@ -72,7 +72,7 @@ object CompletionSpec extends ZIOSpecDefault { ), suite("Command that accepts no Args or Options")( test("Returns no completions") { - assertM( + assertZIO( Completion.complete(List("true"), 1, True.command, CliConfig.default) )(equalTo(List.empty)) } @@ -80,13 +80,13 @@ object CompletionSpec extends ZIOSpecDefault { suite("Command that accepts no Options, single Args")( suite("PrimType.Bool")( test("No partial word should complete with 'false' and 'true'")( - assertM( + assertZIO( Completion .complete(List("foo"), 1, Command("foo", Options.Empty, Args.bool), CliConfig.default) )(equalTo(List("false ", "true "))) ), test("Partial word 'f' should complete with 'false'")( - assertM( + assertZIO( Completion.complete( List("foo", "f"), 1, @@ -96,7 +96,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("false "))) ), test("Partial word 't' should complete with 'true'")( - assertM( + assertZIO( Completion.complete( List("foo", "t"), 1, @@ -106,7 +106,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("true "))) ), test("Partial word 'true' should return 'true'")( - assertM( + assertZIO( Completion.complete( List("foo", "true"), 1, @@ -116,7 +116,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("true "))) ), test("Partial word 'false' should return 'false'")( - assertM( + assertZIO( Completion.complete( List("foo", "false"), 1, @@ -126,7 +126,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("false "))) ), test("Partial word 'x' should return no completions")( - assertM( + assertZIO( Completion.complete( List("foo", "x"), 1, @@ -138,7 +138,7 @@ object CompletionSpec extends ZIOSpecDefault { ), suite("PrimType.Decimal")( test("No partial word should return no completions")( - assertM( + assertZIO( Completion.complete( List("foo"), 1, @@ -148,7 +148,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List.empty)) ), test("Partial word '32.6' should return no completions")( - assertM( + assertZIO( Completion.complete( List("foo", "32.6"), 1, @@ -158,7 +158,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List.empty)) ), test("Partial word 'x' should return no completions")( - assertM( + assertZIO( Completion.complete( List("foo", "32.6"), 1, @@ -170,7 +170,7 @@ object CompletionSpec extends ZIOSpecDefault { ), suite("PrimType.Enumeration")( test("No partial word should return the complete list of enumeration values")( - assertM( + assertZIO( Completion.complete( List("foo"), 1, @@ -180,7 +180,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("bar ", "baz ", "bippy "))) ), test("Partial word 'b' should complete with 'bar', 'baz', 'bippy'")( - assertM( + assertZIO( Completion.complete( List("foo", "b"), 1, @@ -190,7 +190,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("bar ", "baz ", "bippy "))) ), test("Partial word 'ba' should complete with 'bar' and 'baz'")( - assertM( + assertZIO( Completion.complete( List("foo", "ba"), 1, @@ -200,7 +200,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("bar ", "baz "))) ), test("Partial word 'baz' should return 'baz")( - assertM( + assertZIO( Completion.complete( List("foo", "baz"), 1, @@ -210,7 +210,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("baz "))) ), test("Partial word 'baz' should return 'baz' and 'bazinga'")( - assertM( + assertZIO( Completion.complete( List("foo", "baz"), 1, @@ -232,7 +232,7 @@ object CompletionSpec extends ZIOSpecDefault { Files.createDirectory(tempDir / "fooDir") *> Files.createDirectory(tempDir / "barDir") *> Files.createDirectory(tempDir / "bippyDir") *> - assertM( + assertZIO( Completion.complete( List("program"), 1, @@ -257,7 +257,7 @@ object CompletionSpec extends ZIOSpecDefault { Files.createDirectory(tempDir / "fooDir") *> Files.createDirectory(tempDir / "barDir") *> Files.createDirectory(tempDir / "bippyDir") *> - assertM( + assertZIO( Completion.complete( List("program", "f"), 1, @@ -282,7 +282,7 @@ object CompletionSpec extends ZIOSpecDefault { Files.createDirectory(tempDir / "fooDir") *> Files.createDirectory(tempDir / "barDir") *> Files.createDirectory(tempDir / "bippyDir") *> - assertM( + assertZIO( Completion.complete( List("program", "foo.txt"), 1, @@ -307,7 +307,7 @@ object CompletionSpec extends ZIOSpecDefault { Files.createDirectory(tempDir / "fooDir") *> Files.createDirectory(tempDir / "barDir") *> Files.createDirectory(tempDir / "bippyDir") *> - assertM( + assertZIO( Completion.complete( List("program", "doesnt-exist"), 1, @@ -332,7 +332,7 @@ object CompletionSpec extends ZIOSpecDefault { Files.createDirectory(tempDir / "fooDir") *> Files.createDirectory(tempDir / "barDir") *> Files.createDirectory(tempDir / "bippyDir") *> - assertM( + assertZIO( Completion.complete( List("program"), 1, @@ -357,7 +357,7 @@ object CompletionSpec extends ZIOSpecDefault { Files.createDirectory(tempDir / "fooDir") *> Files.createDirectory(tempDir / "barDir") *> Files.createDirectory(tempDir / "bippyDir") *> - assertM( + assertZIO( Completion.complete( List("program", "f"), 1, @@ -382,7 +382,7 @@ object CompletionSpec extends ZIOSpecDefault { Files.createDirectory(tempDir / "fooDir") *> Files.createDirectory(tempDir / "barDir") *> Files.createDirectory(tempDir / "bippyDir") *> - assertM( + assertZIO( Completion.complete( List("program", "fooDir"), 1, @@ -399,7 +399,7 @@ object CompletionSpec extends ZIOSpecDefault { ), suite("PrimType.ZoneId")( test("'US/' prefix provided")( - assertM( + assertZIO( Completion.complete( List("program", "US/"), 1, @@ -430,7 +430,7 @@ object CompletionSpec extends ZIOSpecDefault { suite("Command with no Options, multiple Args")( suite("PrimType.Enumeration followed by PrimType.ZoneId")( test("Partial word 'baz' should return 'baz' and 'bazinga'")( - assertM( + assertZIO( Completion.complete( List("foo", "baz"), 1, @@ -440,7 +440,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("baz ", "bazinga "))) ), test("Partial word 'US/' should return the US zone IDs")( - assertM( + assertZIO( Completion.complete( List("foo", "baz", "US/"), 2, @@ -467,7 +467,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("Completing ['foo', 'baz', 'US/'] at position 1 should complete with 'baz' and 'bazinga'")( - assertM( + assertZIO( Completion.complete( List("foo", "baz", "US/"), 1, @@ -479,7 +479,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("Completing ['foo', 'x', 'US/'] at position 2 should yield no completions ('x' is invalid)")( - assertM( + assertZIO( Completion.complete( List("foo", "x", "US/"), 1, @@ -495,7 +495,7 @@ object CompletionSpec extends ZIOSpecDefault { suite("Command with Options, no args")( suite("Boolean Options")( test("No prefix should show all flags")( - assertM( + assertZIO( Completion.complete( List("foo"), 1, @@ -511,7 +511,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("'-' prefix should show all flags")( - assertM( + assertZIO( Completion.complete( List("foo", "-"), 1, @@ -527,7 +527,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("'-a' prefix should show flags '-b'")( - assertM( + assertZIO( Completion.complete( List("foo", "-a"), 2, @@ -543,7 +543,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("'-b' prefix should show flags '-a'")( - assertM( + assertZIO( Completion.complete( List("foo", "-b"), 2, @@ -559,7 +559,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("'-a' prefix should show flags '-b', '-c', '-d'")( - assertM( + assertZIO( Completion.complete( List("foo", "-a"), 2, @@ -575,7 +575,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("'-d -a' prefix should show flags '-b', '-c'")( - assertM( + assertZIO( Completion.complete( List("foo", "-d", "-a"), 3, @@ -591,7 +591,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("'-d -c -b -' prefix should show flags '-a'")( - assertM( + assertZIO( Completion.complete( List("foo", "-d", "-c", "-b", "-"), 4, @@ -607,7 +607,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("An invalid flag should yield no completions")( - assertM( + assertZIO( Completion.complete( List("foo", "-x"), 2, @@ -625,7 +625,7 @@ object CompletionSpec extends ZIOSpecDefault { ), suite("Int Options")( test("No prefix should show all flags")( - assertM( + assertZIO( Completion.complete( List("foo"), 1, @@ -641,7 +641,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("'-c' without integer value should provide no completions")( - assertM( + assertZIO( Completion.complete( List("foo", "-c"), 2, @@ -657,7 +657,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("'-c' with integer value should complete with '-a', '-b', '-d'")( - assertM( + assertZIO( Completion.complete( List("foo", "-c", "1"), 3, @@ -673,7 +673,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("'-c' and '-b' with integer value should complete with '-a', '-d'")( - assertM( + assertZIO( Completion.complete( List("foo", "-c", "1", "-b", "2"), 5, @@ -689,7 +689,7 @@ object CompletionSpec extends ZIOSpecDefault { ) ), test("'-c' with integer value and '-b' with no integer value should provide no completions")( - assertM( + assertZIO( Completion.complete( List("foo", "-c", "1", "-b"), 4, @@ -707,7 +707,7 @@ object CompletionSpec extends ZIOSpecDefault { ), suite("Enumeration Options")( test("Partial option name should complete the name of the option")( - assertM( + assertZIO( Completion.complete( List("foo", "--q"), 1, @@ -717,7 +717,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("--quux "))) ), test("No partial word should return the complete list of enumeration options")( - assertM( + assertZIO( Completion.complete( List("foo", "--quux"), 2, @@ -727,7 +727,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("bar ", "baz ", "bippy "))) ), test("Partial word 'b' should complete with 'bar', 'baz', 'bippy'")( - assertM( + assertZIO( Completion.complete( List("foo", "--quux", "b"), 2, @@ -737,7 +737,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("bar ", "baz ", "bippy "))) ), test("Partial word 'ba' should complete with 'bar' and 'baz'")( - assertM( + assertZIO( Completion.complete( List("foo", "--quux", "ba"), 2, @@ -747,7 +747,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("bar ", "baz "))) ), test("Partial word 'baz' should return 'baz'")( - assertM( + assertZIO( Completion.complete( List("foo", "--quux", "baz"), 2, @@ -757,7 +757,7 @@ object CompletionSpec extends ZIOSpecDefault { )(equalTo(List("baz "))) ), test("Partial word 'baz' should return 'baz' and 'bazinga'")( - assertM( + assertZIO( Completion.complete( List("foo", "--quux", "baz"), 2, @@ -771,7 +771,7 @@ object CompletionSpec extends ZIOSpecDefault { suite("Command with Options and Args")( suite("Tail")( test("Complete the '-n' option name")( - assertM( + assertZIO( Completion.complete( List("tail", "-"), 1, @@ -792,7 +792,7 @@ object CompletionSpec extends ZIOSpecDefault { Files.createDirectory(tempDir / "fooDir") *> Files.createDirectory(tempDir / "barDir") *> Files.createDirectory(tempDir / "bippyDir") *> - assertM( + assertZIO( Completion.complete( List("tail", "f"), 1, @@ -809,7 +809,7 @@ object CompletionSpec extends ZIOSpecDefault { ), suite("WC")( test("Complete the option names")( - assertM( + assertZIO( Completion.complete( List("wc", "-"), 1, @@ -830,7 +830,7 @@ object CompletionSpec extends ZIOSpecDefault { Files.createDirectory(tempDir / "fooDir") *> Files.createDirectory(tempDir / "barDir") *> Files.createDirectory(tempDir / "bippyDir") *> - assertM( + assertZIO( Completion.complete( List("wc", "-l", "-c", "f"), 3, @@ -855,7 +855,7 @@ object CompletionSpec extends ZIOSpecDefault { Files.createDirectory(tempDir / "fooDir") *> Files.createDirectory(tempDir / "barDir") *> Files.createDirectory(tempDir / "bippyDir") *> - assertM( + assertZIO( Completion.complete( List("wc", "-l", "-c", "blah.md", "f"), 4, diff --git a/zio-cli/shared/src/test/scala/zio/cli/completion/RegularLanguageSpec.scala b/zio-cli/shared/src/test/scala/zio/cli/completion/RegularLanguageSpec.scala index aaddbe32..af84662d 100644 --- a/zio-cli/shared/src/test/scala/zio/cli/completion/RegularLanguageSpec.scala +++ b/zio-cli/shared/src/test/scala/zio/cli/completion/RegularLanguageSpec.scala @@ -1,5 +1,6 @@ package zio.cli.completion +import zio._ import zio.test.Assertion._ import zio.test._ import zio.cli._ @@ -10,37 +11,37 @@ object RegularLanguageSpec extends ZIOSpecDefault { suite("Empty language")( test("Empty language rejects all strings")( check(Gen.listOfBounded(0, 5)(Gen.alphaNumericString))(tokens => - assertM( + assertZIO( RegularLanguage.Empty.contains(tokens) - )(equalTo(false)).provideService(CliConfig.default) + )(equalTo(false)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ) ), suite("Epsilon language")( test("Epsilon language accepts the empty string")( - assertM( + assertZIO( RegularLanguage.Epsilon.contains(List.empty) - )(equalTo(true)).provideService(CliConfig.default) + )(equalTo(true)).provideEnvironment(ZEnvironment(CliConfig.default)) ), test("Epsilon language rejects all nonempty strings")( check(Gen.listOfBounded(1, 5)(Gen.alphaNumericString))(tokens => - assertM( + assertZIO( RegularLanguage.Empty.contains(tokens) - )(equalTo(false)).provideService(CliConfig.default) + )(equalTo(false)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ) ), suite("StringToken language")( test("StringToken language accepts its target string")( - assertM( + assertZIO( RegularLanguage.StringToken("foo").contains(List("foo")) - )(equalTo(true)).provideService(CliConfig.default) + )(equalTo(true)).provideEnvironment(ZEnvironment(CliConfig.default)) ), test("StringToken language rejects anything other than its target string")( check(Gen.alphaNumericString.filter(_ != "foo"))(token => - assertM( + assertZIO( RegularLanguage.StringToken("foo").contains(List(token)) - )(equalTo(false)).provideService(CliConfig.default) + )(equalTo(false)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ) ), @@ -48,9 +49,9 @@ object RegularLanguageSpec extends ZIOSpecDefault { suite("PrimType.Bool language")( test("PrimType.Bool language accepts values that correspond to 'true' and 'false' ")( check(Gen.fromIterable(PrimType.Bool.TrueValues ++ PrimType.Bool.FalseValues))(token => - assertM( + assertZIO( RegularLanguage.PrimTypeToken(PrimType.Bool(None)).contains(List(token)) - )(equalTo(true)).provideService(CliConfig.default) + )(equalTo(true)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ), test("PrimType.Bool language rejects values that do not correspond to 'true'/'false'")( @@ -59,9 +60,9 @@ object RegularLanguageSpec extends ZIOSpecDefault { .map(s => s.toLowerCase) .filter(s => !PrimType.Bool.TrueValues(s) && !PrimType.Bool.FalseValues(s)) )(token => - assertM( + assertZIO( RegularLanguage.PrimTypeToken(PrimType.Bool(None)).contains(List(token)) - )(equalTo(false)).provideService(CliConfig.default) + )(equalTo(false)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ) ), @@ -85,18 +86,18 @@ object RegularLanguageSpec extends ZIOSpecDefault { ) ) )(token => - assertM( + assertZIO( RegularLanguage.PrimTypeToken(PrimType.ZoneId).contains(List(token)) - )(equalTo(true)).provideService(CliConfig.default) + )(equalTo(true)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ), test("PrimType.Bool language rejects some values that are not valid time zone IDs")( check( Gen.fromIterable(Iterable("invalid", "whatever", "foo")) )(token => - assertM( + assertZIO( RegularLanguage.PrimTypeToken(PrimType.ZoneId).contains(List(token)) - )(equalTo(false)).provideService(CliConfig.default) + )(equalTo(false)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ) ) @@ -104,10 +105,10 @@ object RegularLanguageSpec extends ZIOSpecDefault { suite("Cat language")( suite("'foo' 'bar' 'baz' language")( test("Accepts 'foo' 'bar' 'baz'")( - assertM( + assertZIO( ("foo" ~ "bar" ~ "baz") .contains(List("foo", "bar", "baz")) - )(equalTo(true)).provideService(CliConfig.default) + )(equalTo(true)).provideEnvironment(ZEnvironment(CliConfig.default)) ), test("Rejects everything that is not 'foo' 'bar' 'baz'")( check( @@ -121,10 +122,10 @@ object RegularLanguageSpec extends ZIOSpecDefault { ) ) )(tokens => - assertM( + assertZIO( ("foo" ~ "bar" ~ "baz") .contains(tokens) - )(equalTo(false)).provideService(CliConfig.default) + )(equalTo(false)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ) ) @@ -132,16 +133,16 @@ object RegularLanguageSpec extends ZIOSpecDefault { suite("Alt language")( suite("'foo' 'bar' | 'foo' 'baz' language")( test("Accepts 'foo' 'bar'")( - assertM( + assertZIO( ("foo" ~ "bar" | "foo" ~ "baz") .contains(List("foo", "bar")) - )(equalTo(true)).provideService(CliConfig.default) + )(equalTo(true)).provideEnvironment(ZEnvironment(CliConfig.default)) ), test("Accepts 'foo' 'baz'")( - assertM( + assertZIO( ("foo" ~ "bar" | "foo" ~ "baz") .contains(List("foo", "baz")) - )(equalTo(true)).provideService(CliConfig.default) + )(equalTo(true)).provideEnvironment(ZEnvironment(CliConfig.default)) ), test("Rejects everything that is not 'foo' 'bar' | 'foo' 'baz'")( check( @@ -154,10 +155,10 @@ object RegularLanguageSpec extends ZIOSpecDefault { ) ) )(tokens => - assertM( + assertZIO( ("foo" ~ "bar" | "foo" ~ "baz") .contains(tokens) - )(equalTo(false)).provideService(CliConfig.default) + )(equalTo(false)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ) ) @@ -180,9 +181,9 @@ object RegularLanguageSpec extends ZIOSpecDefault { ) ) )(tokens => - assertM( + assertZIO( ("foo" ~ "bar" | "foo" ~ "baz").*.contains(tokens) - )(equalTo(true)).provideService(CliConfig.default) + )(equalTo(true)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ), test("Rejects everything except zero or more repetitions of 'foo' 'bar' or 'foo' 'baz'")( @@ -198,9 +199,9 @@ object RegularLanguageSpec extends ZIOSpecDefault { ) ) )(tokens => - assertM( + assertZIO( ("foo" ~ "bar" | "foo" ~ "baz").*.contains(tokens) - )(equalTo(false)).provideService(CliConfig.default) + )(equalTo(false)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ) ), @@ -218,9 +219,9 @@ object RegularLanguageSpec extends ZIOSpecDefault { ) ) )(tokens => - assertM( + assertZIO( ("foo" ~ "bar" | "foo" ~ "baz").rep(Some(2), Some(4)).contains(tokens) - )(equalTo(true)).provideService(CliConfig.default) + )(equalTo(true)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ), test("Rejects everything except two to four or more repetitions of 'foo' 'bar' or 'foo' 'baz'")( @@ -240,9 +241,9 @@ object RegularLanguageSpec extends ZIOSpecDefault { ) ) )(tokens => - assertM( + assertZIO( ("foo" ~ "bar" | "foo" ~ "baz").rep(Some(2), Some(4)).contains(tokens) - )(equalTo(false)).provideService(CliConfig.default) + )(equalTo(false)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ) ) @@ -253,13 +254,13 @@ object RegularLanguageSpec extends ZIOSpecDefault { check( Gen.fromIterable(List("a", "b", "c", "d").permutations.toList) )(tokens => - assertM( + assertZIO( RegularLanguage .Permutation( List("a", "b", "c", "d").map(RegularLanguage.StringToken(_)): _* ) .contains(tokens) - )(equalTo(true)).provideService(CliConfig.default) + )(equalTo(true)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ), test("Rejects everything except for permutations of {'a', 'b', 'c', 'd'}")( @@ -277,13 +278,13 @@ object RegularLanguageSpec extends ZIOSpecDefault { ) ) )(tokens => - assertM( + assertZIO( RegularLanguage .Permutation( List("a", "b", "c", "d").map(RegularLanguage.StringToken(_)): _* ) .contains(tokens) - )(equalTo(false)).provideService(CliConfig.default) + )(equalTo(false)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ) ), @@ -306,7 +307,7 @@ object RegularLanguageSpec extends ZIOSpecDefault { ) ) )(tokens => - assertM( + assertZIO( RegularLanguage .Permutation( RegularLanguage.StringToken("a"), @@ -314,7 +315,7 @@ object RegularLanguageSpec extends ZIOSpecDefault { RegularLanguage.StringToken("d").* ) .contains(tokens) - )(equalTo(true)).provideService(CliConfig.default) + )(equalTo(true)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ), test("Rejects language non-members")( @@ -331,7 +332,7 @@ object RegularLanguageSpec extends ZIOSpecDefault { ) ) )(tokens => - assertM( + assertZIO( RegularLanguage .Permutation( RegularLanguage.StringToken("a"), @@ -339,7 +340,7 @@ object RegularLanguageSpec extends ZIOSpecDefault { RegularLanguage.StringToken("d").* ) .contains(tokens) - )(equalTo(false)).provideService(CliConfig.default) + )(equalTo(false)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ) ), @@ -360,7 +361,7 @@ object RegularLanguageSpec extends ZIOSpecDefault { ) ) )(tokens => - assertM( + assertZIO( ( RegularLanguage .Permutation( @@ -370,7 +371,7 @@ object RegularLanguageSpec extends ZIOSpecDefault { RegularLanguage.StringToken("d").? ) ~ "z" ).contains(tokens) - )(equalTo(true)).provideService(CliConfig.default) + )(equalTo(true)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ), test("Rejects language non-members")( @@ -389,7 +390,7 @@ object RegularLanguageSpec extends ZIOSpecDefault { ) ) )(tokens => - assertM( + assertZIO( ( RegularLanguage .Permutation( @@ -399,7 +400,7 @@ object RegularLanguageSpec extends ZIOSpecDefault { RegularLanguage.StringToken("d").? ) ~ "z" ).contains(tokens) - )(equalTo(false)).provideService(CliConfig.default) + )(equalTo(false)).provideEnvironment(ZEnvironment(CliConfig.default)) ) ) )