Code Monkey home page Code Monkey logo

scalatestplus-scalacheck's Introduction

ScalaTest

Build Status

ScalaTest is a free, open-source testing toolkit for Scala and Java programmers.

Official Website: http://www.scalatest.org/

Using ScalaTest

Setup

Please visit Download and Setup for download and setup instructions.

Quick Start

Please visit Quick Start for steps to get started quickly.

Building ScalaTest

Pre-Requisites

The followings are needed for building ScalaTest:

use the following SBT options instead:

SBT_OPTS="-Xms512M -Xmx3000M -Xss1M -XX:NewRatio=8"

Building and Running Tests

This command will build and run the regular tests:

$ sbt test

To include flicker tests, you'll need to set environment variable SCALATEST_RUN_FLICKER_TESTS=true:

> export SCALATEST_RUN_FLICKER_TESTS=true
> sbt test

To run generated all tests, you'll need to increase maximum heap size to at least -Xmx5000M, and use this command instead:

$ rm -rf gentests
$ sbt gentests/test

You can also run different groups generated tests separately:

$ rm -rf gentests
$ sbt genMustMatchersTests1/test
$ sbt genMustMatchersTests2/test
$ sbt genMustMatchersTests3/test
$ sbt genMustMatchersTests4/test
$ sbt genGenTests/test
$ sbt genTablesTests/test
$ sbt genInspectorsTests/test
$ sbt genInspectorsShorthandsTests1/test
$ sbt genInspectorsShorthandsTests2/test
$ sbt genTheyTests/test
$ sbt genContainTests1/test
$ sbt genContainTests2/test
$ sbt genSortedTests/test
$ sbt genLoneElementTests/test
$ sbt genEmptyTests/test

What it does is simply switch to gentests project and run test.

To run scala-js tests:

$ sbt scalatestAppJS/clean
$ sbt scalacticTestJS/test:compile
$ sbt scalacticTestJS/test
$ sbt scalatestTestJS/test:compile
$ sbt scalatestTestJS/test

To run scala-native tests:

$ sbt -Dscalatest.skip.jdk.check=true ++2.11.12 scalatestAppNative/clean
$ sbt -Dscalatest.skip.jdk.check=true ++2.11.12 scalacticTestNative/test:compile
$ sbt -Dscalatest.skip.jdk.check=true ++2.11.12 scalacticTestNative/test
$ sbt -Dscalatest.skip.jdk.check=true ++2.11.12 scalatestTestNative/test:compile
$ sbt -Dscalatest.skip.jdk.check=true ++2.11.12 scalatestTestNative/test

Building Examples

You can build examples project using this command:

$ sbt examples/compile

Packaging

You can package the ScalaTest JAR file using this command:

$ sbt package

The resulting JAR file will be produced in target/scala-2.11/.

You can also publish it to your local Ivy repository using this command:

$ sbt publishLocal

Or publish it to local maven repository using this command:

$ sbt publishM2

Publishing

To publish to Sonatype, you first need to make sure you have the following:

  • A GPG client is installed on your command line path. For more information, please refer to GNU Privacy Guard Website.
  • You have created your GPG keys and distributed your public key to hkp://pool.sks-keyservers.net/. For more information, please refer to How To Generate PGP Signatures With Maven.
  • You have been granted the right to publish using org.scalatest and org.scalactic domain.

By default, ScalaTest build will read your Sonatype credentials from ~/.ivy2/.credentials, which is a properties file that looks like this:

realm=Sonatype Nexus Repository Manager
host=oss.sonatype.org
user=xxxxxxxx
password=xxxxxxxx

You can use SCALATEST_NEXUS_LOGIN and SCALATEST_NEXUS_PASSWORD environment variables to override Sonatype credentials.

For signing, ScalaTest build will use ~/.gnupg/secring.gpg by default and prompt for GPG passphase if required. Alternatively you can use SCALATEST_GPG_FILE to use a different GPG file, and use SCALATEST_GPG_PASSPHASE to provide GPG passphase to avoid input prompt.

If you would like to export a particular private key into a separate GPG file, you can use the following command:

$ gpg --export-secret-keys [email protected] > example-secret-key.gpg

With Sonatype credentials and GPG file in place, you can now publish to Sonatype.

Before publishing any patch release, binary compatibility with previous version should be checked:

$ sbt ++2.11.12 scalactic/package scalactic/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestCore/package scalatestCore/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestFeatureSpec/package scalatestFeatureSpec/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestFlatSpec/package scalatestFlatSpec/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestFreeSpec/package scalatestFreeSpec/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestFunSuite/package scalatestFunSuite/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestFunSpec/package scalatestFunSpec/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestPropSpec/package scalatestPropSpec/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestRefSpec/package scalatestRefSpec/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestWordSpec/package scalatestWordSpec/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestDiagrams/package scalatestDiagrams/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestMatchersCore/package scalatestMatchersCore/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestShouldMatchers/package scalatestShouldMatchers/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestMustMatchers/package scalatestMustMatchers/mimaReportBinaryIssues
$ sbt ++2.11.12 scalacticJS/package scalacticJS/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestCoreJS/package scalatestCoreJS/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestFeatureSpecJS/package scalatestFeatureSpecJS/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestFlatSpecJS/package scalatestFlatSpecJS/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestFreeSpecJS/package scalatestFreeSpecJS/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestFunSuiteJS/package scalatestFunSuiteJS/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestFunSpecJS/package scalatestFunSpecJS/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestPropSpecJS/package scalatestPropSpecJS/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestWordSpecJS/package scalatestWordSpecJS/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestDiagramsJS/package scalatestDiagramsJS/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestMatchersCoreJS/package scalatestMatchersCoreJS/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestShouldMatchersJS/package scalatestShouldMatchersJS/mimaReportBinaryIssues
$ sbt ++2.11.12 scalatestMustMatchersJS/package scalatestMustMatchersJS/mimaReportBinaryIssues

$ sbt ++2.12.17 scalactic/package scalactic/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestCore/package scalatestCore/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestFeatureSpec/package scalatestFeatureSpec/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestFlatSpec/package scalatestFlatSpec/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestFreeSpec/package scalatestFreeSpec/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestFunSuite/package scalatestFunSuite/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestFunSpec/package scalatestFunSpec/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestPropSpec/package scalatestPropSpec/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestRefSpec/package scalatestRefSpec/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestWordSpec/package scalatestWordSpec/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestDiagrams/package scalatestDiagrams/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestMatchersCore/package scalatestMatchersCore/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestShouldMatchers/package scalatestShouldMatchers/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestMustMatchers/package scalatestMustMatchers/mimaReportBinaryIssues
$ sbt ++2.12.17 scalacticJS/package scalacticJS/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestCoreJS/package scalatestCoreJS/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestFeatureSpecJS/package scalatestFeatureSpecJS/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestFlatSpecJS/package scalatestFlatSpecJS/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestFreeSpecJS/package scalatestFreeSpecJS/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestFunSuiteJS/package scalatestFunSuiteJS/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestFunSpecJS/package scalatestFunSpecJS/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestPropSpecJS/package scalatestPropSpecJS/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestWordSpecJS/package scalatestWordSpecJS/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestDiagramsJS/package scalatestDiagramsJS/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestMatchersCoreJS/package scalatestMatchersCoreJS/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestShouldMatchersJS/package scalatestShouldMatchersJS/mimaReportBinaryIssues
$ sbt ++2.12.17 scalatestMustMatchersJS/package scalatestMustMatchersJS/mimaReportBinaryIssues

$ sbt ++2.13.12 scalactic/package scalactic/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestCore/package scalatestCore/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestFeatureSpec/package scalatestFeatureSpec/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestFlatSpec/package scalatestFlatSpec/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestFreeSpec/package scalatestFreeSpec/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestFunSuite/package scalatestFunSuite/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestFunSpec/package scalatestFunSpec/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestPropSpec/package scalatestPropSpec/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestRefSpec/package scalatestRefSpec/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestWordSpec/package scalatestWordSpec/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestDiagrams/package scalatestDiagrams/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestMatchersCore/package scalatestMatchersCore/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestShouldMatchers/package scalatestShouldMatchers/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestMustMatchers/package scalatestMustMatchers/mimaReportBinaryIssues
$ sbt ++2.13.12 scalacticJS/package scalacticJS/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestCoreJS/package scalatestCoreJS/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestFeatureSpecJS/package scalatestFeatureSpecJS/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestFlatSpecJS/package scalatestFlatSpecJS/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestFreeSpecJS/package scalatestFreeSpecJS/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestFunSuiteJS/package scalatestFunSuiteJS/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestFunSpecJS/package scalatestFunSpecJS/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestPropSpecJS/package scalatestPropSpecJS/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestWordSpecJS/package scalatestWordSpecJS/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestDiagramsJS/package scalatestDiagramsJS/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestMatchersCoreJS/package scalatestMatchersCoreJS/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestShouldMatchersJS/package scalatestShouldMatchersJS/mimaReportBinaryIssues
$ sbt ++2.13.12 scalatestMustMatchersJS/package scalatestMustMatchersJS/mimaReportBinaryIssues

To publish scalatest modules for jvm, js, native and dotty, use the following commands:

$ ./publish.sh

scalatestplus-scalacheck's People

Contributors

bvenners avatar cheeseng avatar inmost-light avatar larsrh avatar mdedetrich avatar raboof avatar sethtisue avatar sullis avatar travisbrown avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

scalatestplus-scalacheck's Issues

Release for ScalaTest 3.1.0

Hi there,

ScalaTest 3.1.0 release note states:

From now on these will be released as a separate, optional module to allow ScalaTest and its ScalaCheck integration library to evolve more independently.

Please correct me if I'm wrong, but I can't find any information regarding the correct version that should be used with scalatest 3.1.0 and it looks from the commit log here that this project hasn't released a compatible version. Same question for scalatestplus-mockito.

Thanks in advance.

Imports and various versions

For a long time I was having trouble w/ 3.0.x --> 3.1.x migration, but everywhere I'm using scalatest and scalatestplus been running pretty smoothly for a while now. I had an old repo that was still on 3.0.8, though, and today I upped to 3.1.2, and I hit an issue I used to have with one of the imports:

[error] <test-file-pathh>.scala:5:12: object scalatestplus is not a member of package org
[error] import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
[error]            ^
[error]  <test-file-path>.scala:12:58: not found: type ScalaCheckDrivenPropertyChecks
[error] class TestPhrases extends AnyFunSuite with Matchers with ScalaCheckDrivenPropertyChecks {

What was strange was that I'd matched imports in a test file and dependency declarations in the build file to files from a project where 3.1.2 working great:

build.sbt:

libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.3" % "test"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.1.2" % "test"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.1.2" % "test"

Imports in test file:

import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks

Yet, in one project the tests could run great through sbt and in the other I ran up against the import error. Turns out, in the project where things were working, I was also using discipline:

libraryDependencies += "org.typelevel" %% "discipline-scalatest" % "1.0.1"

Adding that dependency to the problematic project got things working. Is it known why that would be?

I guess not a big deal, but I'm definitely curious if anyone can point me toward the reason. Thanks in advance!

New artifact name

I noticed that the artifact name was changed to scalacheck-1.14. It was previously set to scalatest-scalacheck. Was this intentional? The convention for most Scala packages that provide extensions to upstream projects is to prefix their package name and suffix the upstream project. It probably helps avoid confusion about whether the project is a fork, or just an integration of a project.

ScalaCheckDrivenPropertyChecks migrating to scala 2.13.x

Dep Version

"org.scalatestplus" %% "scalacheck-1-15" % "3.2.10.0"

Overview

Migrating an existing project which is working fine on Scala 2.12 to cross compile/publish/release on Scala 2.13
Introduced the compiler settings sbt-tpolecat for Scala 2.13

//...
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
//...

class EventLoggingTest extends FunSuite with ScalaCheckDrivenPropertyChecks {
//...
test("Logs an event as json") {
    forAll { (evt: Event) =>
      val json = evt.asJson.noSpaces
      EventLogging.event(evt)
      verify(log).info(json)
    }
  }
// ...
}

Problem

I'm getting the following error:

Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method dispatch,
[error] or remove the empty argument list from its definition (Java-defined methods are exempt).
[error] In Scala 3, an unapplied method like this will be eta-expanded into a function.
[error]     forAll { (evt: Event) =>
[error]            ^

I see your test file that is using ScalaCheckDrivenPropertyChecks in this project has been commented out for a while.
I've tried adding () at various spots, adding type annotations, etc and nothing I do resolves this.
I assume there is a compiler flag I can filter out but don't really want to go down that route if I can fix it.

Question

Is this something you've seen and can recommend how to fix?

Support scalatest assertions in Checkers

As a follow up to scalatest/scalatest#251, ScalaCheckDrivenPropertyChecks isn't good for nested forAlls and is also missing features like forAllNoShrink.

It seems like Checkers is what I want anyway, to explicitly build up a Prop, then check it. But it currently doesn't work with normal scalatest assertions like

check {
  forAll { a: Int =>
    foo(a) shouldBe 42
  }
}

This currently throws a compile-time error:

No implicit view available from org.scalatest.Assertion => org.scalacheck.Prop.

It would be nice to augment Checkers or provide a separate class to include support for normal scalatest assertions.

Expose a function (scalacheck.Test.Result => scalatest.Assertion)

I'm implementing support for scalatest with scalacheck-effect and currently I need to copy/paste a lot of logic from CheckerAsserting#Check, in addition to placing my code in the org.scalatestplus.scalacheck package to get access to private[scalacheck] methods.

I could avoid all this if CheckerAsserting exposed a public method with the signature scalacheck.Test.Result => scalatest.Assertion

(for reference, here's my impl https://gist.github.com/Daenyth/67575575b5c1acc1d6ea100aae05b3a9#file-scalacheckeffectassertions-scala)

Dotty release

I see travis opened up #24 for dotty support, any chance we can can merge that and get a release?

Bug for shared tests running under JS under specific latest versions

Using library dependencies

"org.scalacheck" %%% "scalacheck" % "1.14.3" % "test",
"org.scalatest" %%% "scalatest" % "3.1.2" % "it,test",
"org.scalatestplus" %% "scalacheck-1-14" % "3.1.2.0" % "test"

In a scalajs 1.0.0 sbt cross-built project, there is a subtle bug where if the above-mentioned org.scalatestplus dependency is included in the project, tests in the standard "shared" directory (which are compiled to both JVM and JS flavors and the tests are then run by ScalaTest twice, once in each environment) fail to run in the JS environment (we are using jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv) with the error:

[info] Fast optimizing ...evilplot/js/target/scala-2.13/evilplot-test-fastopt.js
[info] ScalaTest
[info] Run completed in 88 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[error] Error: Total 1, Failed 0, Errors 1, Passed 0
[error] Error during tests:
[error] 	com.cibo.evilplot.numeric.KernelDensityEstimationSpec
[info] Closure: 0 error(s), 0 warning(s)

Dropping that one scalatestplus dependency restores running and passing of the test. Note that this test (and no tests in the repo) actually need to USE scalacheck or the ScalaCheckPropertyChecks trait for this bug to be triggered. Just including/excluding the dependency was sufficient.

I think this is the latest of all these dependencies, but it is not the README.md recommended set. Downgrading to ScalaTest 3.1.0 seems be be a no-go b/c it does not seem to be published for ScalaJS 1.0.0 + Scala 2.13. Downgrading to ScalaTest 3.1.1 is published for those two, but in combination with "scalacheck-1-14" % "3.1.1.0", produces the same mysterious error.

Thank you!

Need options to specify "-S" option in maven/gradle/bazel

According to the official document of scalatest + scalacheck integration:

https://www.scalatest.org/user_guide/property_based_testing

The only bay to specify randomisation seed is through sbt:

testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-S", "123456789")

In the meantime, many of the largest Scala project that uses scalatest + scalacheck (e.g. twitter's The Algorithm & Apache Spark) have chosen maven / bazel instead of sbt. This effectively blocked them from using this feature.

We need to expose this option to all build systems equally, not just sbt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.