Skip to content

Instantly share code, notes, and snippets.

@kubukoz
Created April 7, 2021 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kubukoz/3813701e9c4478cafeb60099e9ae0850 to your computer and use it in GitHub Desktop.
Save kubukoz/3813701e9c4478cafeb60099e9ae0850 to your computer and use it in GitHub Desktop.
circe-golden bloop-compatible paths
import java.io.File
import java.nio.file.Paths
import io.circe.Decoder
import io.circe.Encoder
import io.circe.Printer
import io.circe.testing.golden.GoldenCodecLaws
import io.circe.testing.golden.ResourceFileGoldenCodecLaws
import io.circe.testing.golden.Resources
import org.scalacheck.Arbitrary
object ResourceFileGoldenCodecLawsCompat {
import scala.reflect.runtime.universe.TypeTag
@SuppressWarnings(
Array(
"scalafix:DisableSyntax.defaultArgs"
)
)
def apply[A](
printer: Printer,
size: Int = 10,
count: Int = 10
)(
implicit decodeA: Decoder[A],
encodeA: Encoder[A],
arbitraryA: Arbitrary[A],
typeTagA: TypeTag[A]
): GoldenCodecLaws[A] =
ResourceFileGoldenCodecLaws[A](
name = Resources.inferName[A],
resourcePackage = Resources.inferPackage[A],
resourceRootDir = inferResourceDirectory,
size = size,
count = count,
printer = printer
)
// Workaround for the mismatch of default resource handling between bloop and sbt.
def inferResourceDirectory(implicit file: sourcecode.File): File =
Stream
.iterate(Paths.get(file.value))(_.getParent())
.find(_.endsWith("test"))
.getOrElse(
throw new Throwable(
s"""Couldn't find a parent directory of $file that would end with "test"!"""
)
)
.resolve("resources")
.toFile()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment