Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Scala.js support #166

Merged
merged 4 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .jvmopts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
-XX:+TieredCompilation
-XX:-UseGCOverheadLimit
# effectively adds GC to Perm space
-XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled
# must be enabled for CMSClassUnloadingEnabled to work
74 changes: 58 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import sbt.internal.ProjectMatrix
import scoverage.ScoverageKeys.coverageEnabled

val scala2_11 = "2.11.12"
val scala2_12 = "2.12.12"
val scala2_13 = "2.13.3"
val allScalaVersions = List(scala2_11, scala2_12, scala2_13)

ThisBuild / organization := "com.47deg"
ThisBuild / scalaVersion := "2.13.2"
ThisBuild / crossScalaVersions := Seq("2.11.12", "2.12.11", "2.13.2")
ThisBuild / scalaVersion := scala2_13

addCommandAlias("ci-test", "scalafmtCheckAll; scalafmtSbtCheck; mdoc; testCovered")
addCommandAlias("ci-docs", "github; mdoc; headerCreateAll; publishMicrosite")
Expand All @@ -9,23 +16,58 @@ addCommandAlias("ci-publish", "github; ci-release")
lazy val microsite = project
.enablePlugins(MicrositesPlugin)
.enablePlugins(ScalaUnidocPlugin)
.dependsOn(allModules: _*)
.dependsOn(
core.jvm(scala2_13),
`scalacheck-toolbox-magic`.jvm(scala2_13),
`scalacheck-toolbox-combinators`.jvm(scala2_13)
)
.settings(
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(
Seq(
core.jvm(scala2_13),
`scalacheck-toolbox-magic`.jvm(scala2_13),
`scalacheck-toolbox-combinators`.jvm(scala2_13)
).map(_.project): _*
)
)

lazy val documentation = project
.settings(mdocOut := file("."))
.enablePlugins(MdocPlugin)

lazy val `scalacheck-toolbox-datetime` = module
lazy val core: ProjectMatrix = (projectMatrix in file("modules/scalacheck-toolbox-datetime"))
.settings(description := "A library for helping use date and time libraries with ScalaCheck")
.settings(libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.3")
.settings(libraryDependencies += "joda-time" % "joda-time" % "2.10.6")
.settings(libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "2.2.0")

lazy val `scalacheck-toolbox-magic` = module
.enablePlugins(BigListOfNaughtyStringsPlugin)
.settings(description := "ScalaCheck Generators for magic values")
.settings(libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.3")

lazy val `scalacheck-toolbox-combinators` = module
.settings(description := "Useful generic combinators for ScalaCheck")
.settings(libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.3")
.settings(
libraryDependencies ++= Seq(
"org.scalacheck" %%% "scalacheck" % "1.14.3",
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.2.0"
)
)
.jvmPlatform(
scalaVersions = allScalaVersions,
libraryDependencies += "joda-time" % "joda-time" % "2.10.6"
)
.jsPlatform(
scalaVersions = allScalaVersions,
settings = Seq(
coverageEnabled := false,
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % "2.0.0" % Test
)
)

lazy val `scalacheck-toolbox-magic`: ProjectMatrix =
(projectMatrix in file("modules/scalacheck-toolbox-magic"))
.enablePlugins(BigListOfNaughtyStringsPlugin)
.settings(description := "ScalaCheck Generators for magic values")
.settings(libraryDependencies += "org.scalacheck" %%% "scalacheck" % "1.14.3")
.jvmPlatform(scalaVersions = allScalaVersions)

lazy val `scalacheck-toolbox-combinators`: ProjectMatrix =
(projectMatrix in file("modules/scalacheck-toolbox-combinators"))
.settings(description := "Useful generic combinators for ScalaCheck")
.settings(libraryDependencies += "org.scalacheck" %%% "scalacheck" % "1.14.3")
.jvmPlatform(scalaVersions = allScalaVersions)
.jsPlatform(
scalaVersions = allScalaVersions,
settings = coverageEnabled := false
)
2 changes: 1 addition & 1 deletion microsite/docs/docs/datetime/granularity.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ val prop = forAll { zdt: ZonedDateTime =>
(zdt.getNano == 0)
}

prop.check
prop.check()
```

2 changes: 1 addition & 1 deletion microsite/docs/docs/datetime/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ val prop = forAll { dt: DateTime =>
passed
}

prop.check
prop.check()
```

## A note on imports
Expand Down
4 changes: 2 additions & 2 deletions microsite/docs/docs/datetime/range.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ val range = Period.years(1)

forAll(genDateTimeWithinRange(from, range)) { dt =>
dt.getYear == 2016
}.check
}.check()
```

# Using Granularity and Ranges Together
Expand All @@ -35,5 +35,5 @@ forAll(genDateTimeWithinRange(from, range)) { dt =>
(dt.getMinuteOfHour == 0) &&
(dt.getSecondOfMinute == 0) &&
(dt.getMillisOfSecond == 0)
}.check
}.check()
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@

package com.fortysevendeg.scalacheck.combinators

import org.scalacheck._
import org.scalacheck.Prop._

import Combinators._

object CombinatorProperties extends Properties("Combinator Generators") {

override def overrideParameters(p: Test.Parameters): Test.Parameters =
p.withMinSuccessfulTests(100000)
object CombinatorProperties extends BaseCombinatorProperties {

property(
"genPickFromMapWithSuccessAndFailure should return a list of elements in the map, and a list of elements not in the map"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2016-2020 47 Degrees Open Source <https://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.fortysevendeg.scalacheck.combinators

import org.scalacheck._

abstract class BaseCombinatorProperties extends Properties("Combinator Generators") {

override def overrideParameters(p: Test.Parameters): Test.Parameters =
// These tests run much slower on Node.js compared to the JVM so we have to live with smaller number of
// minSuccessfulTests here
p.withMinSuccessfulTests(10000)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2016-2020 47 Degrees Open Source <https://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.fortysevendeg.scalacheck.combinators

import org.scalacheck._

abstract class BaseCombinatorProperties extends Properties("Combinator Generators") {

override def overrideParameters(p: Test.Parameters): Test.Parameters =
p.withMinSuccessfulTests(100000)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2016-2020 47 Degrees Open Source <https://www.47deg.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.fortysevendeg.scalacheck.datetime

package object instances {
object jdk8 extends Jdk8Instances
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object Magic {

private[magic] val strings = scala.io.Source
.fromInputStream(stream)
.getLines
.getLines()
.filterNot { s =>
val trimmed = s.trim
trimmed.startsWith("#") || trimmed.isEmpty
Expand Down
4 changes: 1 addition & 3 deletions project/MicrositeSettingsPlugin.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import com.alejandrohdezma.sbt.modules.ModulesPlugin.autoImport.allModules
import com.typesafe.sbt.site.jekyll.JekyllPlugin.autoImport._
import com.typesafe.sbt.site.SitePlugin.autoImport._
import microsites.MicrositesPlugin
Expand Down Expand Up @@ -36,8 +35,7 @@ object MicrositeSettingsPlugin extends AutoPlugin {
addMappingsToSiteDir(
mappings in (ScalaUnidoc, packageDoc),
docsMappingsAPIDir in ScalaUnidoc
),
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(allModules.map(_.project): _*)
)
)

}
3 changes: 2 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ addSbtPlugin("com.alejandrohdezma" % "sbt-github" % "0.8.2")
addSbtPlugin("com.alejandrohdezma" % "sbt-github-header" % "0.8.2")
addSbtPlugin("com.alejandrohdezma" % "sbt-github-mdoc" % "0.8.2")
addSbtPlugin("com.alejandrohdezma" % "sbt-remove-test-from-pom" % "0.1.0")
addSbtPlugin("com.alejandrohdezma" % "sbt-modules" % "0.1.0")
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.13")
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.6.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.2.0")