Created
April 7, 2021 22:52
-
-
Save kubukoz/3813701e9c4478cafeb60099e9ae0850 to your computer and use it in GitHub Desktop.
circe-golden bloop-compatible paths
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
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