Skip to content

Commit

Permalink
Annotate pattern matches that may fail at runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
fthomas committed Jan 5, 2025
1 parent d6ba071 commit 523d12e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CliTest extends FunSuite {
List("--refresh-backoff-period", "1 day"),
List("--bitbucket-use-default-reviewers")
).flatten
)
): @unchecked

assertEquals(obtained.workspace, File("a"))
assertEquals(obtained.reposFiles, Nel.one(uri"b"))
Expand Down Expand Up @@ -85,7 +85,7 @@ class CliTest extends FunSuite {
test("parseArgs: minimal example") {
val Success(Usage.Regular(obtained)) = Cli.parseArgs(
minimumRequiredParams.flatten
)
): @unchecked

assert(!obtained.processCfg.sandboxCfg.enableSandbox)
assertEquals(obtained.workspace, File("a"))
Expand All @@ -105,7 +105,7 @@ class CliTest extends FunSuite {
List("--git-ask-pass", "f"),
List("--enable-sandbox")
).flatten
)
): @unchecked

assert(obtained.processCfg.sandboxCfg.enableSandbox)
}
Expand All @@ -121,7 +121,7 @@ class CliTest extends FunSuite {
List("--enable-sandbox"),
List("--disable-sandbox")
).flatten
)
): @unchecked

assert(clue(obtained).startsWith("Unexpected option"))
}
Expand All @@ -136,23 +136,23 @@ class CliTest extends FunSuite {
List("--git-ask-pass", "f"),
List("--disable-sandbox")
).flatten
)
): @unchecked

assert(!obtained.processCfg.sandboxCfg.enableSandbox)
}

test("parseArgs: fail if required option not provided") {
val Error(obtained) = Cli.parseArgs(Nil)
val Error(obtained) = Cli.parseArgs(Nil): @unchecked
assert(clue(obtained).startsWith("Missing expected"))
}

test("parseArgs: unrecognized argument") {
val Error(obtained) = Cli.parseArgs(List("--foo"))
val Error(obtained) = Cli.parseArgs(List("--foo")): @unchecked
assert(clue(obtained).startsWith("Unexpected option"))
}

test("parseArgs: --help") {
val Help(obtained) = Cli.parseArgs(List("--help"))
val Help(obtained) = Cli.parseArgs(List("--help")): @unchecked
assert(clue(obtained).startsWith("Usage"))
}

Expand All @@ -161,7 +161,7 @@ class CliTest extends FunSuite {
List("--gitlab-merge-when-pipeline-succeeds"),
List("--gitlab-required-reviewers", "5")
)
val Success(Usage.Regular(obtained)) = Cli.parseArgs(params.flatten)
val Success(Usage.Regular(obtained)) = Cli.parseArgs(params.flatten): @unchecked

assert(obtained.gitLabCfg.mergeWhenPipelineSucceeds)
assertEquals(obtained.gitLabCfg.requiredReviewers, Some(5))
Expand All @@ -172,7 +172,7 @@ class CliTest extends FunSuite {
List("--gitlab-merge-when-pipeline-succeeds"),
List("--gitlab-required-reviewers", "-3")
)
val Error(errorMsg) = Cli.parseArgs(params.flatten)
val Error(errorMsg) = Cli.parseArgs(params.flatten): @unchecked

assert(clue(errorMsg).startsWith("Required reviewers must be non-negative"))
}
Expand All @@ -182,7 +182,7 @@ class CliTest extends FunSuite {
List(
List("validate-repo-config", "file.conf")
).flatten
)
): @unchecked

assertEquals(file, File("file.conf"))
}
Expand All @@ -192,36 +192,36 @@ class CliTest extends FunSuite {
List("--forge-type", "azure-repos"),
List("--do-not-fork")
)
val Success(Usage.Regular(obtained)) = Cli.parseArgs(params.flatten)
val Success(Usage.Regular(obtained)) = Cli.parseArgs(params.flatten): @unchecked
assert(obtained.forgeCfg.doNotFork)
}

test("parseArgs: validate fork mode enabled") {
val params = minimumRequiredParams ++ List(
List("--forge-type", "azure-repos")
)
val Error(errorMsg) = Cli.parseArgs(params.flatten)
val Error(errorMsg) = Cli.parseArgs(params.flatten): @unchecked
assert(clue(errorMsg).startsWith("azure-repos, bitbucket-server do not support fork mode"))
}

test("parseArgs: validate pull request labeling disabled") {
val params = minimumRequiredParams ++ List(
List("--forge-type", "bitbucket")
)
val Success(Usage.Regular(obtained)) = Cli.parseArgs(params.flatten)
val Success(Usage.Regular(obtained)) = Cli.parseArgs(params.flatten): @unchecked
assert(!obtained.forgeCfg.addLabels)
}

test("parseArgs: exit code policy: --exit-code-success-if-any-repo-succeeds") {
val params = minimumRequiredParams ++ List(
List("--exit-code-success-if-any-repo-succeeds")
)
val Success(Usage.Regular(obtained)) = Cli.parseArgs(params.flatten)
val Success(Usage.Regular(obtained)) = Cli.parseArgs(params.flatten): @unchecked
assert(obtained.exitCodePolicy == SuccessIfAnyRepoSucceeds)
}

test("parseArgs: exit code policy: default") {
val Success(Usage.Regular(obtained)) = Cli.parseArgs(minimumRequiredParams.flatten)
val Success(Usage.Regular(obtained)) = Cli.parseArgs(minimumRequiredParams.flatten): @unchecked
assert(obtained.exitCodePolicy == SuccessOnlyIfAllReposSucceed)
}

Expand All @@ -230,7 +230,7 @@ class CliTest extends FunSuite {
List("--forge-type", "bitbucket"),
List("--add-labels")
)
val Error(errorMsg) = Cli.parseArgs(params.flatten)
val Error(errorMsg) = Cli.parseArgs(params.flatten): @unchecked
assert(
clue(errorMsg).startsWith("bitbucket, bitbucket-server do not support pull request labels")
)
Expand All @@ -255,7 +255,7 @@ class CliTest extends FunSuite {
List("--forge-type", "azure-repos"),
List("--azure-repos-organization")
)).flatten
)
): @unchecked
assert(error.startsWith("Missing value for option: --azure-repos-organization"))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MillDepParserTest extends FunSuite {
| ]
|}
|""".stripMargin
val Right(result) = parser.parseModules(data)
val Right(result) = parser.parseModules(data): @unchecked

val dep12 = List("com.lihaoyi".g % ("geny", "geny_2.12").a % "0.6.0")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class processTest extends FunSuite {

test("echo: fail, buffer size exceeded") {
val Left(t) =
slurp3(Nel.of("echo", "-n", "1\n2\n3\n4\n5\n6"), 4, Set.empty).attempt.unsafeRunSync()
slurp3(Nel.of("echo", "-n", "1\n2\n3\n4\n5\n6"), 4, Set.empty).attempt.unsafeRunSync(): @unchecked
assert(clue(t).isInstanceOf[ProcessBufferOverflowException])
}

test("echo: fail, line length > buffer size") {
val Left(t) =
slurp3(Nel.of("echo", "-n", "123456"), 4, Set.empty).attempt.unsafeRunSync()
slurp3(Nel.of("echo", "-n", "123456"), 4, Set.empty).attempt.unsafeRunSync(): @unchecked
assert(clue(t).isInstanceOf[ProcessLineTooLongException])
}

Expand All @@ -54,7 +54,7 @@ class processTest extends FunSuite {
}

test("ls: fail, non-zero exit code") {
val Left(t) = slurp1(Nel.of("ls", "--foo")).attempt.unsafeRunSync()
val Left(t) = slurp1(Nel.of("ls", "--foo")).attempt.unsafeRunSync(): @unchecked
assert(clue(t).isInstanceOf[ProcessFailedException])
}

Expand All @@ -66,7 +66,7 @@ class processTest extends FunSuite {
val timeout = 500.milliseconds
val sleep = timeout * 2
val p = slurp2(Nel.of("sleep", sleep.toSeconds.toInt.toString), timeout).attempt
val (Left(t), fd) = DateTimeAlg.create[IO].timed(p).unsafeRunSync()
val (Left(t), fd) = DateTimeAlg.create[IO].timed(p).unsafeRunSync(): @unchecked

assert(clue(t).isInstanceOf[ProcessTimedOutException])
assert(clue(fd) > timeout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ object MockConfig {
s"--github-app-key-file=$key",
"--refresh-backoff-period=1hour"
)
val Success(Cli.Usage.Regular(config)) = Cli.parseArgs(args)
val Success(Cli.Usage.Regular(config)) = Cli.parseArgs(args): @unchecked
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ class PullRequestFrequencyTest extends FunSuite {
val epoch: Timestamp = Timestamp(0L)

test("onSchedule") {
val Right(thursday) = PullRequestFrequency.fromString("0 * ? * THU")
val Right(notThursday) = PullRequestFrequency.fromString("0 * ? * MON-WED,FRI-SUN")
val Right(thursday) = PullRequestFrequency.fromString("0 * ? * THU"): @unchecked
val Right(notThursday) = PullRequestFrequency.fromString("0 * ? * MON-WED,FRI-SUN"): @unchecked
assert(thursday.onSchedule(epoch))
assert(!notThursday.onSchedule(epoch))
}

test("waitingTime: @asap") {
val Right(freq) = PullRequestFrequency.fromString("@asap")
val Right(freq) = PullRequestFrequency.fromString("@asap"): @unchecked
assertEquals(freq.waitingTime(epoch, Timestamp(18.hours.toMillis)), None)
}

test("waitingTime: @daily") {
val Right(freq) = PullRequestFrequency.fromString("@daily")
val Right(freq) = PullRequestFrequency.fromString("@daily"): @unchecked
assertEquals(freq.waitingTime(epoch, Timestamp(18.hours.toMillis)), Some(6.hours))
}

test("waitingTime: timespan") {
val Right(freq) = PullRequestFrequency.fromString("14 days")
val Right(freq) = PullRequestFrequency.fromString("14 days"): @unchecked
assertEquals(freq.waitingTime(epoch, Timestamp(18.hours.toMillis)), Some(6.hours + 13.days))
}

test("waitingTime: cron expr") {
val Right(freq) = PullRequestFrequency.fromString("0 1 ? * *")
val Right(freq) = PullRequestFrequency.fromString("0 1 ? * *"): @unchecked
assertEquals(freq.waitingTime(epoch, Timestamp(20.minutes.toMillis)), Some(40.minutes))
}

test("CronExpr encode and then decode") {
val Right(freq) = PullRequestFrequency.fromString("0 0 1,15 * ?")
val Right(freq) = PullRequestFrequency.fromString("0 0 1,15 * ?"): @unchecked
assertEquals(parser.decode[PullRequestFrequency](freq.asJson.spaces2), Right(freq))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PruningAlgTest extends FunSuite {
| }
| }
|}""".stripMargin
)
): @unchecked
val pullRequestsFile =
config.workspace / "store/pull_requests/v2/github/fthomas/scalafix-test/pull_requests.json"
val pullRequestsContent =
Expand Down Expand Up @@ -116,7 +116,7 @@ class PruningAlgTest extends FunSuite {
| }
| }
|}""".stripMargin
)
): @unchecked
val pullRequestsFile =
config.workspace / s"store/pull_requests/v2/github/${repo.toPath}/pull_requests.json"
val pullRequestsContent =
Expand Down Expand Up @@ -261,7 +261,7 @@ class PruningAlgTest extends FunSuite {
| }
| }
|}""".stripMargin
)
): @unchecked
val pullRequestsFile =
config.workspace / s"store/pull_requests/v2/github/${repo.toPath}/pull_requests.json"
val timestampNow = Instant.now().toEpochMilli
Expand Down Expand Up @@ -373,7 +373,7 @@ class PruningAlgTest extends FunSuite {
| }
| }
|}""".stripMargin
)
): @unchecked
val pullRequestsFile =
config.workspace / s"store/pull_requests/v2/github/${repo.toPath}/pull_requests.json"
val pullRequestsContent =
Expand Down Expand Up @@ -488,7 +488,7 @@ class PruningAlgTest extends FunSuite {
| }
| }
|}""".stripMargin
)
): @unchecked
val timestampNow = Instant.now().toEpochMilli
val pullRequestsFile =
config.workspace / s"store/pull_requests/v2/github/${repo.toPath}/pull_requests.json"
Expand Down

0 comments on commit 523d12e

Please sign in to comment.