-
Notifications
You must be signed in to change notification settings - Fork 32
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
Cross-build for Scala.js #272
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b63c24f
Cross-build for Scala.js
armanbilge e3c326e
Mark `scalacheck-effect` as test dependency
armanbilge ed43440
Only run coverage on JVM
armanbilge 3a97c5c
Revert "Only run coverage on JVM"
armanbilge 94d2cd6
Disable coverage for JS take 2
armanbilge 3449406
Fix CI take 3
armanbilge 137314d
Fix CI take 4
armanbilge d3b6e6e
Bump cats-effect-testing, remove hack
armanbilge 717ab29
Merge branch 'master' into js
armanbilge File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
package io.circe.fs2 | ||
|
||
import _root_.fs2.{ Pipe, Stream, text } | ||
import _root_.fs2.Pipe | ||
import _root_.fs2.Stream | ||
import _root_.fs2.text | ||
import cats.effect.IO | ||
import cats.effect.unsafe.implicits._ | ||
import io.circe.{ DecodingFailure, Json, ParsingFailure } | ||
import io.circe.DecodingFailure | ||
import io.circe.Json | ||
import io.circe.ParsingFailure | ||
import io.circe.fs2.examples._ | ||
import io.circe.generic.auto._ | ||
import io.circe.syntax._ | ||
import org.scalacheck.Prop | ||
import org.scalacheck.effect.PropF | ||
import org.scalatest.compatible.Assertion | ||
import org.scalatest.enablers.WheneverAsserting | ||
import org.scalatest.exceptions.DiscardedEvaluationException | ||
import org.typelevel.jawn.AsyncParser | ||
|
||
import scala.collection.immutable.{ Stream => StdStream } | ||
|
||
class Fs2Suite extends CirceSuite { | ||
|
@@ -34,14 +43,21 @@ class Fs2Suite extends CirceSuite { | |
} | ||
|
||
"stringParser" should "parse single value" in { | ||
forAll { (foo: Foo) => | ||
PropF.forAllF { (foo: Foo) => | ||
val stream = serializeFoos(AsyncParser.SingleValue, Stream.emit(foo)) | ||
assert( | ||
stream.through(stringParser(AsyncParser.SingleValue)).compile.toVector.attempt.unsafeRunSync() === Right( | ||
Vector(foo.asJson) | ||
stream | ||
.through(stringParser(AsyncParser.SingleValue)) | ||
.compile | ||
.toVector | ||
.attempt | ||
.map(r => | ||
assert( | ||
r === Right( | ||
Vector(foo.asJson) | ||
) | ||
) | ||
) | ||
) | ||
} | ||
}.check().map(r => assert(r.passed)) | ||
} | ||
|
||
"byteArrayParser" should "parse bytes wrapped in array" in { | ||
|
@@ -53,31 +69,27 @@ class Fs2Suite extends CirceSuite { | |
} | ||
|
||
"byteParser" should "parse single value" in { | ||
forAll { (foo: Foo) => | ||
PropF.forAllF { (foo: Foo) => | ||
val stream = serializeFoos(AsyncParser.SingleValue, Stream.emit(foo)) | ||
assert( | ||
stream | ||
.through(text.utf8Encode) | ||
.through(byteParser(AsyncParser.SingleValue)) | ||
.compile | ||
.toVector | ||
.attempt | ||
.unsafeRunSync() === Right(Vector(foo.asJson)) | ||
) | ||
} | ||
stream | ||
.through(text.utf8Encode) | ||
.through(byteParser(AsyncParser.SingleValue)) | ||
.compile | ||
.toVector | ||
.attempt | ||
.map(r => assert(r === Right(Vector(foo.asJson)))) | ||
}.check().map(r => assert(r.passed)) | ||
} | ||
|
||
"byteParser" should "parse single value, when run twice" in { | ||
forAll { (foo: Foo) => | ||
PropF.forAllF { (foo: Foo) => | ||
val stream = serializeFoos(AsyncParser.SingleValue, Stream.emit(foo)) | ||
|
||
val parseOnce = | ||
stream.through(text.utf8Encode).through(byteParser(AsyncParser.SingleValue)).compile.toVector | ||
|
||
parseOnce.attempt.unsafeRunSync() | ||
|
||
assert(parseOnce.attempt.unsafeRunSync() == Right(Vector(foo.asJson))) | ||
} | ||
(parseOnce.attempt >> parseOnce.attempt).map(r => assert(r == Right(Vector(foo.asJson)))) | ||
}.check().map(r => assert(r.passed)) | ||
} | ||
|
||
"byteArrayParserC" should "parse bytes wrapped in array" in { | ||
|
@@ -89,32 +101,38 @@ class Fs2Suite extends CirceSuite { | |
} | ||
|
||
"byteParserC" should "parse single value" in { | ||
forAll { (foo: Foo) => | ||
PropF.forAllF { (foo: Foo) => | ||
val stream = serializeFoos(AsyncParser.SingleValue, Stream.emit(foo)) | ||
assert( | ||
stream | ||
.through(text.utf8Encode) | ||
.chunks | ||
.through(byteParserC(AsyncParser.SingleValue)) | ||
.compile | ||
.toVector | ||
.attempt | ||
.unsafeRunSync() === Right(Vector(foo.asJson)) | ||
) | ||
} | ||
stream | ||
.through(text.utf8Encode) | ||
.chunks | ||
.through(byteParserC(AsyncParser.SingleValue)) | ||
.compile | ||
.toVector | ||
.attempt | ||
.map(r => assert(r === Right(Vector(foo.asJson)))) | ||
}.check().map(r => assert(r.passed)) | ||
} | ||
|
||
"decoder" should "decode enumerated JSON values" in | ||
forAll { (fooStdStream: StdStream[Foo], fooVector: Vector[Foo]) => | ||
PropF.forAllF { (fooStdStream: StdStream[Foo], fooVector: Vector[Foo]) => | ||
val stream = serializeFoos(AsyncParser.UnwrapArray, fooStream(fooStdStream, fooVector)) | ||
val foos = fooStdStream ++ fooVector | ||
|
||
assert( | ||
stream.through(stringArrayParser).through(decoder[IO, Foo]).compile.toVector.attempt.unsafeRunSync() === Right( | ||
foos.toVector | ||
stream | ||
.through(stringArrayParser) | ||
.through(decoder[IO, Foo]) | ||
.compile | ||
.toVector | ||
.attempt | ||
.map(r => | ||
assert( | ||
r === Right( | ||
foos.toVector | ||
) | ||
) | ||
) | ||
) | ||
} | ||
}.check().map(r => assert(r.passed)) | ||
|
||
"stringArrayParser" should "return ParsingFailure" in { | ||
testParsingFailure(_.through(stringArrayParser)) | ||
|
@@ -141,7 +159,7 @@ class Fs2Suite extends CirceSuite { | |
} | ||
|
||
"decoder" should "return DecodingFailure" in | ||
forAll { (fooStdStream: StdStream[Foo], fooVector: Vector[Foo]) => | ||
PropF.forAllF { (fooStdStream: StdStream[Foo], fooVector: Vector[Foo]) => | ||
sealed trait Foo2 | ||
case class Bar2(x: String) extends Foo2 | ||
|
||
|
@@ -152,29 +170,41 @@ class Fs2Suite extends CirceSuite { | |
.compile | ||
.toVector | ||
.attempt | ||
.unsafeRunSync() | ||
|
||
assert(result.isLeft && result.left.get.isInstanceOf[DecodingFailure]) | ||
result.map(r => assert(r.isLeft && r.left.get.isInstanceOf[DecodingFailure])) | ||
} | ||
} | ||
}.check().map(r => assert(r.passed)) | ||
|
||
private def testParser(mode: AsyncParser.Mode, through: Pipe[IO, String, Json]) = | ||
forAll { (fooStdStream: StdStream[Foo], fooVector: Vector[Foo]) => | ||
PropF.forAllF { (fooStdStream: StdStream[Foo], fooVector: Vector[Foo]) => | ||
val stream = serializeFoos(mode, fooStream(fooStdStream, fooVector)) | ||
val foos = (fooStdStream ++ fooVector).map(_.asJson) | ||
|
||
assert(stream.through(through).compile.toVector.attempt.unsafeRunSync() === Right(foos.toVector)) | ||
} | ||
stream.through(through).compile.toVector.attempt.map(r => assert(r === Right(foos.toVector))) | ||
}.check().asserting(r => assert(r.passed)) | ||
|
||
private def testParsingFailure(through: Pipe[IO, String, Json]) = | ||
forAll { (stringStdStream: StdStream[String], stringVector: Vector[String]) => | ||
val result = Stream("}") | ||
.append(stringStream(stringStdStream, stringVector)) | ||
.through(through) | ||
.compile | ||
.toVector | ||
.attempt | ||
.unsafeRunSync() | ||
assert(result.isLeft && result.left.get.isInstanceOf[ParsingFailure]) | ||
PropF.forAllF { (stringStdStream: StdStream[String], stringVector: Vector[String]) => | ||
val result = | ||
Stream("}").append(stringStream(stringStdStream, stringVector)).through(through).compile.toVector.attempt | ||
result.map(result => assert(result.isLeft && result.left.get.isInstanceOf[ParsingFailure])) | ||
}.check().asserting(r => assert(r.passed)) | ||
|
||
private implicit def assertionToProp: IO[Assertion] => PropF[IO] = { assertion => | ||
assertion.as(PropF.Result[IO](Prop.True, Nil, Set.empty, Set.empty): PropF[IO]).handleError { | ||
case _: DiscardedEvaluationException => PropF.Result[IO](Prop.Undecided, Nil, Set.empty, Set.empty) | ||
case t => PropF.Result[IO](Prop.Exception(t), Nil, Set.empty, Set.empty) | ||
} | ||
} | ||
Comment on lines
+232
to
+237
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this still needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes? |
||
|
||
private implicit def assertingNatureOfIO: WheneverAsserting[IO[Assertion]] { type Result = IO[Assertion] } = | ||
new WheneverAsserting[IO[Assertion]] { | ||
type Result = IO[Assertion] | ||
def whenever(condition: Boolean)(fun: => IO[Assertion]): IO[Assertion] = | ||
if (!condition) | ||
IO.raiseError[Assertion](new DiscardedEvaluationException) | ||
else | ||
fun | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at e.g. the circe-optics build, this seems to be done via
.jsSettings(coverageEnabled := false)
, which seems better, since it applies for people running the default commands locally, and not just in CI.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For whatever reason that doesn't seem to work here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh. I get why you're doing this, but this kind of thing is why I hate Scala.js so much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problems we are experiencing here are confounded by the fact this is a single-module project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@travisbrown I think moving the project into its own folder and having a designated
root
fixes it.