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 support for scala-native and scalajs 1.0 #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
target/
*.hnir
23 changes: 17 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ import sbtcrossproject.CrossPlugin.autoImport.crossProject
organization in ThisBuild := "io.estatico"

lazy val root = project.in(file("."))
.aggregate(newtypeJS, newtypeJVM, catsTestsJVM)
.aggregate(newtypeJS, newtypeJVM, newtypeNative, catsTestsJVM)
.settings(noPublishSettings)

lazy val newtype = crossProject(JSPlatform, JVMPlatform).in(file("."))
lazy val newtype = crossProject(JSPlatform, JVMPlatform, NativePlatform).in(file("."))
.settings(defaultSettings)
.settings(releasePublishSettings)
.settings(name := "newtype")
.nativeSettings(
crossScalaVersions := List("2.11.12"),
scalaVersion := "2.11.12",
nativeLinkStubs := true,
Compile / scalacOptions += "-Yno-predef" // needed to ensure users can use -Yno-predef
)

lazy val newtypeJVM = newtype.jvm
lazy val newtypeNative = newtype.native
lazy val newtypeJS = newtype.js

lazy val catsTests = crossProject(JVMPlatform).in(file("cats-tests"))
Expand Down Expand Up @@ -116,7 +123,6 @@ lazy val defaultSettings = Seq(

lazy val defaultScalacOptions = scalacOptions ++= Seq(
"-Xfatal-warnings",
"-Yno-predef", // needed to ensure users can use -Yno-predef
"-unchecked",
"-feature",
"-deprecation",
Expand All @@ -129,12 +135,17 @@ lazy val defaultScalacOptions = scalacOptions ++= Seq(
case _ =>
// on scala 2.12+ some spurious unused warnings get triggered
Seq("-Xlint:-unused,_")
})
}) ++ (if (crossProjectPlatform.value == NativePlatform)
Seq() // Removing the 'predef' on scala native-tests, breaks the test integration with sbt
else
Seq("-Yno-predef")) // needed to ensure users can use -Yno-predef

lazy val defaultLibraryDependencies = libraryDependencies ++= Seq(
scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided,
scalaOrganization.value % "scala-compiler" % scalaVersion.value % Provided,
"org.scalacheck" %%% "scalacheck" % "1.14.3" % Test,
"org.scalatest" %%% "scalatest" % "3.1.1" % Test,
"org.scalatestplus" %%% "scalacheck-1-14" % "3.1.1.1" % Test,
"org.scalatest" %%% "scalatest" % "3.2.0-M4" % Test,
"org.scalatestplus" %%% "scalacheck-1-14" % "3.2.0.0-M4" % Test
)


Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.estatico.newtype.macros

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import io.estatico.newtype.ops._
import org.scalacheck.Arbitrary

class NonNativeNewTypeMacrosTest extends AnyFlatSpec with Matchers {

import NewTypeMacrosTest._

behavior of "@newtype with type bounds"

it should "enforce type bounds" in {
val x = Sub(new java.util.HashMap[String, Int]): Sub[java.util.HashMap[String, Int]]
val y = Sub(new java.util.concurrent.ConcurrentHashMap[String, Int])

assertCompiles("x: Sub[java.util.HashMap[String, Int]]")
assertCompiles("y: Sub[java.util.concurrent.ConcurrentHashMap[String, Int]]")

assertDoesNotCompile("x: Sub[java.util.concurrent.ConcurrentHashMap[String, Int]]")
assertDoesNotCompile("y: Sub[java.util.HashMap[String, Int]]")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.estatico.newtype.macros

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import io.estatico.newtype.ops._
import org.scalacheck.Arbitrary

class NonNativeNewTypeMacrosTest extends AnyFlatSpec with Matchers {

import NewTypeMacrosTest._

behavior of "@newtype with type bounds"

it should "enforce type bounds" in {
val x = Sub(new java.util.HashMap[String, Int]): Sub[java.util.HashMap[String, Int]]
val y = Sub(new java.util.concurrent.ConcurrentHashMap[String, Int])

assertCompiles("x: Sub[java.util.HashMap[String, Int]]")
assertCompiles("y: Sub[java.util.concurrent.ConcurrentHashMap[String, Int]]")

assertDoesNotCompile("x: Sub[java.util.concurrent.ConcurrentHashMap[String, Int]]")
assertDoesNotCompile("y: Sub[java.util.HashMap[String, Int]]")
}

}
7 changes: 5 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")
addSbtPlugin("com.dwijnand" % "sbt-travisci" % "1.2.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.8.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.1")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0-M2")
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,9 @@ class NewTypeMacrosTest extends AnyFlatSpec with Matchers {

it should "enforce type bounds" in {
val x = Sub(new java.util.HashMap[String, Int]): Sub[java.util.HashMap[String, Int]]
val y = Sub(new java.util.concurrent.ConcurrentHashMap[String, Int])

assertCompiles("x: Sub[java.util.HashMap[String, Int]]")
assertCompiles("y: Sub[java.util.concurrent.ConcurrentHashMap[String, Int]]")

assertDoesNotCompile("x: Sub[java.util.concurrent.ConcurrentHashMap[String, Int]]")
assertDoesNotCompile("y: Sub[java.util.HashMap[String, Int]]")
}

Expand Down