Skip to content

Commit ad1e25a

Browse files
authored
Test FileAlg.isRegularFile (#1896)
1 parent 88eacf9 commit ad1e25a

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

modules/core/src/main/scala/org/scalasteward/core/application/SelfCheckAlg.scala

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ import cats.syntax.all._
2121
import io.chrisdavenport.log4cats.Logger
2222
import org.http4s.Uri
2323
import org.scalasteward.core.git.GitAlg
24-
import org.scalasteward.core.scalafmt.ScalafmtAlg
24+
import org.scalasteward.core.scalafmt.{scalafmtBinary, ScalafmtAlg}
2525
import org.scalasteward.core.util.UrlChecker
26+
import org.scalasteward.core.util.logger.LoggerOps
2627

2728
final class SelfCheckAlg[F[_]](implicit
2829
gitAlg: GitAlg[F],
@@ -40,23 +41,18 @@ final class SelfCheckAlg[F[_]](implicit
4041
} yield ()
4142

4243
private def checkGitBinary: F[Unit] =
43-
gitAlg.version.attempt.flatMap {
44-
case Right(output) => logger.info(s"Using $output")
45-
case Left(throwable) =>
46-
logger.warn(throwable)(
47-
"Failed to execute git -- make sure it is on the PATH; following the detailed exception:"
48-
)
44+
logger.attemptLogWarn_(execFailedMessage("git")) {
45+
gitAlg.version.flatMap(output => logger.info(s"Using $output"))
4946
}
5047

5148
private def checkScalafmtBinary: F[Unit] =
52-
scalafmtAlg.version.attempt.flatMap {
53-
case Right(output) => logger.info(s"Using $output")
54-
case Left(throwable) =>
55-
logger.warn(throwable)(
56-
"Failed to execute scalafmt -- make sure it is on the PATH; following the detailed exception:"
57-
)
49+
logger.attemptLogWarn_(execFailedMessage(scalafmtBinary)) {
50+
scalafmtAlg.version.flatMap(output => logger.info(s"Using $output"))
5851
}
5952

53+
private def execFailedMessage(binary: String): String =
54+
s"Failed to execute $binary -- make sure it is on the PATH; following the detailed exception:"
55+
6056
private def checkUrlChecker: F[Unit] =
6157
for {
6258
url <- F.fromEither(Uri.fromString("https://github.com"))

modules/core/src/test/scala/org/scalasteward/core/io/FileAlgTest.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,8 @@ class FileAlgTest extends FunSuite {
5858
edited <- fileAlg.editFile(home / "does-not-exists.txt", Some.apply)
5959
} yield edited).run(MockState.empty).unsafeRunSync()
6060

61-
val expected = MockState.empty.copy(
62-
commands = Vector(
63-
List("read", "/tmp/steward/does-not-exists.txt")
64-
)
65-
)
61+
val expected =
62+
MockState.empty.copy(commands = Vector(List("read", "/tmp/steward/does-not-exists.txt")))
6663
assertEquals(state, expected)
6764
assert(!edited)
6865
}
@@ -113,6 +110,18 @@ class FileAlgTest extends FunSuite {
113110
} yield read
114111
assertEquals(p.unsafeRunSync(), content)
115112
}
113+
114+
test("isRegularFile") {
115+
val dir = File.temp / "steward" / "regular"
116+
val file = dir / "file.txt"
117+
val p = for {
118+
_ <- ioFileAlg.deleteForce(dir)
119+
r1 <- ioFileAlg.isRegularFile(file)
120+
_ <- ioFileAlg.writeFileData(dir, FileData("file.txt", "content"))
121+
r2 <- ioFileAlg.isRegularFile(file)
122+
} yield (r1, r2)
123+
assertEquals(p.unsafeRunSync(), (false, true))
124+
}
116125
}
117126

118127
object FileAlgTest {

0 commit comments

Comments
 (0)