Skip to content

Commit

Permalink
Upgrade to ScalaTest-3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
luben committed Sep 14, 2022
1 parent 37faee4 commit 451df09
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ logBuffered in Test := false
parallelExecution in Test := false

libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.0.9" % "test",
"org.scalacheck" %% "scalacheck" % "1.15.4" % "test"
"org.scalatest" %% "scalatest" % "3.2.13" % "test",
"org.scalatestplus" %% "scalacheck-1-16" % "3.2.13.0" % "test"
)

javacOptions ++= Seq("--release", "6", "-Xlint:unchecked")
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/Perf.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.luben.zstd

import org.scalatest.FlatSpec
import org.scalatest.flatspec.AnyFlatSpec

import scala.io._
import java.io._
Expand All @@ -9,7 +9,7 @@ import java.nio.ByteBuffer

import com.sun.management.ThreadMXBean

class ZstdPerfSpec extends FlatSpec {
class ZstdPerfSpec extends AnyFlatSpec {

class AllocTracker {
val tmx: ThreadMXBean = ManagementFactory.getThreadMXBean().asInstanceOf[ThreadMXBean]
Expand Down
38 changes: 18 additions & 20 deletions src/test/scala/Zstd.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.github.luben.zstd

import org.scalatest.{FlatSpec, Tag}
import org.scalatest.prop.Checkers
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop._
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatestplus.scalacheck.ScalaCheckPropertyChecks
import java.io._
import java.nio._
import java.nio.channels.FileChannel
Expand All @@ -14,7 +12,7 @@ import scala.io._
import scala.collection.mutable.WrappedArray
import scala.util.Using

class ZstdSpec extends FlatSpec with Checkers {
class ZstdSpec extends AnyFlatSpec with ScalaCheckPropertyChecks {

implicit override val generatorDrivenConfig =
PropertyCheckConfiguration(minSize = 0, sizeRange = 130 * 1024)
Expand All @@ -23,7 +21,7 @@ class ZstdSpec extends FlatSpec with Checkers {

for (level <- levels) {
"Zstd" should s"should round-trip compression/decompression at level $level" in {
check { input: Array[Byte] =>
forAll { input: Array[Byte] =>
{
val size = input.length
// Assumes that `Zstd.defaultCompressionLevel() == 3`.
Expand All @@ -35,7 +33,7 @@ class ZstdSpec extends FlatSpec with Checkers {
}

it should s"should round-trip compression/decompression with manual array buffers at level $level" in {
check { input: Array[Byte] =>
forAll { input: Array[Byte] =>
{
val size = input.length
val decompressed= new Array[Byte](size)
Expand All @@ -52,7 +50,7 @@ class ZstdSpec extends FlatSpec with Checkers {
}

it should s"round-trip compression/decompression with ByteBuffers at level $level" in {
check { input: Array[Byte] =>
forAll { input: Array[Byte] =>
{
val size = input.length
val inputBuffer = ByteBuffer.allocateDirect(size)
Expand Down Expand Up @@ -81,7 +79,7 @@ class ZstdSpec extends FlatSpec with Checkers {
}

it should s"compress with a byte[] and uncompress with a ByteBuffer $level" in {
check { input: Array[Byte] =>
forAll { input: Array[Byte] =>
val size = input.length
val compressed = Zstd.compress(input, level)

Expand All @@ -98,7 +96,7 @@ class ZstdSpec extends FlatSpec with Checkers {
}

it should s"compress with a ByteBuffer and uncompress with a byte[] $level" in {
check { input: Array[Byte] =>
forAll { input: Array[Byte] =>
val size = input.length
val inputBuffer = ByteBuffer.allocateDirect(size)
inputBuffer.put(input)
Expand All @@ -114,7 +112,7 @@ class ZstdSpec extends FlatSpec with Checkers {
}

it should s"honor non-zero position and limit values in ByteBuffers" in {
check { input: Array[Byte] =>
forAll { input: Array[Byte] =>
val size = input.length

//The test here is to compress the input at each of the designated levels, with each new compressed version
Expand Down Expand Up @@ -187,7 +185,7 @@ class ZstdSpec extends FlatSpec with Checkers {
}

it should "fail to compress when the destination buffer is too small" in {
check{ input: Array[Byte] =>
forAll { input: Array[Byte] =>
val size = input.length
val compressedSize = Zstd.compress(input, 3).length
val compressedBuffer = ByteBuffer.allocateDirect(compressedSize.toInt - 1)
Expand All @@ -204,8 +202,8 @@ class ZstdSpec extends FlatSpec with Checkers {
}

it should "fail to decompress when the destination buffer is too small" in {
check { input: Array[Byte] =>
(input.length > 0) ==> {
forAll { input: Array[Byte] =>
whenever (input.length > 0) {
val size = input.length
val compressedSize = Zstd.compressBound(size.toLong)
val inputBuffer = ByteBuffer.allocateDirect(size)
Expand All @@ -225,7 +223,7 @@ class ZstdSpec extends FlatSpec with Checkers {

for (level <- levels) {
"ZstdInputStream" should s"should round-trip compression/decompression at level $level" in {
check { input: Array[Byte] =>
forAll { input: Array[Byte] =>
val size = input.length
val os = new ByteArrayOutputStream(Zstd.compressBound(size.toLong).toInt)
val zos = new ZstdOutputStream(os).setLevel(level).setCloseFrameOnFlush(false)
Expand Down Expand Up @@ -262,7 +260,7 @@ class ZstdSpec extends FlatSpec with Checkers {

for (level <- levels) {
"ZstdInputStreamMT" should s"should round-trip compression/decompression at level $level" in {
check { input: Array[Byte] =>
forAll { input: Array[Byte] =>
val size = input.length
val os = new ByteArrayOutputStream(Zstd.compressBound(size.toLong).toInt)
val zos = new ZstdOutputStream(os)
Expand Down Expand Up @@ -301,7 +299,7 @@ class ZstdSpec extends FlatSpec with Checkers {

for (level <- levels) {
"ZstdDirectBufferDecompressingStream" should s"should round-trip compression/decompression at level $level" in {
check { input: Array[Byte] =>
forAll { input: Array[Byte] =>
val size = input.length
val os = ByteBuffer.allocateDirect(Zstd.compressBound(size.toLong).toInt)

Expand Down Expand Up @@ -345,7 +343,7 @@ class ZstdSpec extends FlatSpec with Checkers {

for (level <- levels) {
"ZstdInputStream in continuous mode" should s"should round-trip using streaming API with unfinished chunks at level $level" in {
check { input: Array[Byte] =>
forAll { input: Array[Byte] =>
val size = input.length
val os = new ByteArrayOutputStream(Zstd.compressBound(size.toLong).toInt)
val zos = new ZstdOutputStream(os, level)
Expand Down Expand Up @@ -380,7 +378,7 @@ class ZstdSpec extends FlatSpec with Checkers {
}

"ZstdInputStream in continuous mode" should s"not block when the stream ends unexpectedly at level $level" in {
check { input: Array[Byte] =>
forAll { input: Array[Byte] =>
val size = input.length
val os = new ByteArrayOutputStream(Zstd.compressBound(size.toLong).toInt)
val zos = new ZstdOutputStream(os, level)
Expand Down Expand Up @@ -884,7 +882,7 @@ class ZstdSpec extends FlatSpec with Checkers {
Using.Manager { use =>
val cctx = use(new ZstdCompressCtx())
val dctx = use(new ZstdDecompressCtx())
check { input: Array[Byte] =>
forAll { input: Array[Byte] =>
{
val size = input.length
val inputBuffer = ByteBuffer.allocateDirect(size)
Expand Down
7 changes: 2 additions & 5 deletions src/test/scala/ZstdDict.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.github.luben.zstd

import org.scalatest.FlatSpec
import org.scalatest.prop.Checkers
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop._
import org.scalatest.flatspec.AnyFlatSpec
import java.io._
import java.nio._
import java.nio.channels.FileChannel
Expand All @@ -13,7 +10,7 @@ import java.nio.file.StandardOpenOption
import scala.io._
import scala.collection.mutable.WrappedArray

class ZstdDictSpec extends FlatSpec {
class ZstdDictSpec extends AnyFlatSpec {

def source = Source.fromFile("src/test/resources/xml")(Codec.ISO8859).map{_.toByte}

Expand Down

0 comments on commit 451df09

Please sign in to comment.