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

Run tut in Travis builds (fix #362) #363

Merged
merged 8 commits into from
Oct 19, 2016
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
23 changes: 7 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,21 @@ lazy val doobie = project.in(file("."))
}
)

// Workaround to avoid cyclic dependency
// TODO remove after tut-core and argonaut for Scala 2.12 is released
lazy val tuut = taskKey[Seq[(File, String)]]("Temporary task to conditionally skip tut")

// Temporarily skip tut for Scala 2.12
// TODO remove after tut-core and argonaut for Scala 2.12 is released
lazy val docSkipScala212Settings = Seq(
libraryDependencies ++= {
if (scalaVersion.value startsWith "2.12") Nil
else {
val circeVersion = "0.5.0-M2"
val circeVersion = "0.5.3"
Seq(
"io.circe" %% "circe-core",
"io.circe" %% "circe-generic",
"io.circe" %% "circe-parser"
).map(_ % circeVersion) ++
Seq("io.argonaut" %% "argonaut" % "6.2-M1")
Seq("io.argonaut" %% "argonaut" % "6.2-M3")
}
},
tuut := Def.taskDyn {
if (scalaVersion.value startsWith "2.12")
Def.task(Seq.empty[(File, String)])
else
Def.task(tut.value)
}.value
}
)

lazy val noPublishSettings = Seq(
Expand Down Expand Up @@ -247,16 +237,16 @@ lazy val example_cats = project.in(file("modules-cats/example"))
/// POSTGRES
///

val postgisDep = "org.postgis" % "postgis-jdbc" % "1.3.3"
val postgisDep = "net.postgis" % "postgis-jdbc" % "2.2.1"

def postgresSettings(mod: String): Seq[Setting[_]] =
doobieSettings ++
publishSettings ++ Seq(
name := "doobie-" + mod,
description := "Postgres support for doobie.",
libraryDependencies ++= Seq(
"org.postgresql" % "postgresql" % "9.4.1211",
postgisDep % "provided" exclude("org.postgis", "postgis-stubs")
"org.postgresql" % "postgresql" % "9.4.1211",
postgisDep % "provided"
),
initialCommands := """
import doobie.imports._
Expand Down Expand Up @@ -447,6 +437,7 @@ def docsSettings(token: String, tokens: String*): Seq[Setting[_]] =
yax.walk(file("yax/docs/src/main/tut"), sourceManaged.value / "main", tokens.toSet + token)
tutPluginJars.value
},
fork in Test := true,
// postgis is `provided` dependency for users, and section from book of doobie needs it
libraryDependencies += postgisDep
)
Expand Down
4 changes: 1 addition & 3 deletions project/travis-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ fi

if [ "$TRAVIS_SCALA_VERSION" = "$MAIN_SCALA_VERSION" ]; then
echo "Testing with docs for Scala $MAIN_SCALA_VERSION"
exec sbt ++$MAIN_SCALA_VERSION scalastyle compile test:compile test && \
exec sbt ++$MAIN_SCALA_VERSION docs/tut && \
exec sbt ++$MAIN_SCALA_VERSION docs_cats/tut
exec sbt ++$MAIN_SCALA_VERSION scalastyle compile test:compile test docs/tut docs_cats/tut
else
echo "Testing without docs for Scala $TRAVIS_SCALA_VERSION"
exec sbt ++$TRAVIS_SCALA_VERSION core/test h2/test hikari/test postgres/test specs2/test
Expand Down
5 changes: 0 additions & 5 deletions yax/core/src/main/scala/doobie/syntax/catchable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ object catchable {
class DoobieCatchableOps[M[_], A](self: M[A])(implicit c: Catchable[M]) {
#-fs2

#+cats
def attempt: M[Throwable \/ A] =
c.attempt(self)
#-cats

def attemptSome[B](handler: PartialFunction[Throwable, B]): M[B \/ A] =
C.attemptSome(self)(handler)

Expand Down
4 changes: 2 additions & 2 deletions yax/core/src/main/scala/doobie/util/yolo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import scalaz.stream.Process. { eval, eval_, halt }
#-scalaz
#+cats
import cats.Monad
import cats.data.Xor.{ Left => -\/, Right => \/- }
import cats.implicits._
import scala.util.{ Left => -\/, Right => \/- }
import fs2.interop.cats.reverse._
import fs2.interop.cats._
#-cats
#+fs2
import fs2.util.{ Catchable, Suspendable }
Expand Down
10 changes: 9 additions & 1 deletion yax/core/src/test/scala/doobie/syntax/catchable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import scalaz.syntax.monad._
import scalaz.syntax.catchable._
#-scalaz
#+cats
import doobie.util.catchable._
#+fs2
import fs2.interop.cats._
#-fs2
import cats.implicits._
#-cats

Expand All @@ -22,7 +24,13 @@ object catchablespec extends Specification {
}

"work on unaliased IConnection" in {
#+scalaz
42.pure[ConnectionIO].map(_ + 1).attempt
#-scalaz
#+cats
// TODO Remove yax (https://github.com/tpolecat/doobie/issues/369)
(42.pure[ConnectionIO].map(_ + 1): ConnectionIO[Int]).attempt
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional indirection confuses type inference here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave this test as-is and yax it out for cats, then open a separate issue to sort this out. I know Adelbert is pretty focused on it so maybe he'll have some ideas.

#-cats
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to ping @tpolecat, is this what you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, perfect. Thanks!

true
}

Expand Down
5 changes: 5 additions & 0 deletions yax/docs/src/main/tut/01-Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ After that there is text interspersed with code examples. Sometimes definitions

case class Person(name: String, age: Int)

#+scalaz
val nel = NonEmptyList(Person("Bob", 12), Person("Alice", 14))
#-scalaz
#+cats
val nel = NonEmptyList.of(Person("Bob", 12), Person("Alice", 14))
#-cats
```
And sometimes they will appear as a REPL interaction.

Expand Down
4 changes: 2 additions & 2 deletions yax/docs/src/main/tut/03-Connecting.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import doobie.imports._
import scalaz._, Scalaz._
#-scalaz
#+cats
import doobie.util.compat.cats.monad._ // todo: make this automatic
import cats._, cats.data._, cats.implicits._
import fs2.interop.cats._
#-cats
```

Expand Down Expand Up @@ -120,7 +120,7 @@ program3a.replicateM(5).transact(xa).unsafePerformIO.foreach(println)
#-scalaz
#+cats
```tut
program3a.replicateA(5).transact(xa).unsafePerformIO.foreach(println)
Applicative[ConnectionIO].replicateA(5, program3a).transact(xa).unsafePerformIO.foreach(println)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Urgh.

```
#-cats

Expand Down
5 changes: 5 additions & 0 deletions yax/docs/src/main/tut/05-Parameterized.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ There are a few things to notice here:
Running this query gives us the desired result.

```tut
#+scalaz
populationIn(100000000 to 300000000, NonEmptyList("USA", "BRA", "PAK", "GBR")).quick.unsafePerformIO
#-scalaz
#+cats
populationIn(100000000 to 300000000, NonEmptyList.of("USA", "BRA", "PAK", "GBR")).quick.unsafePerformIO
#-cats
```

### Diving Deeper
Expand Down
1 change: 1 addition & 0 deletions yax/docs/src/main/tut/07-Updating.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import scalaz._, Scalaz._
#-scalaz
#+cats
import cats._, cats.data._, cats.implicits._
import fs2.interop.cats._
#-cats
val xa = DriverManagerTransactor[IOLite](
"org.postgresql.Driver", "jdbc:postgresql:world", "postgres", ""
Expand Down
7 changes: 4 additions & 3 deletions yax/docs/src/main/tut/08-Error-Handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import scalaz._, Scalaz._
#-scalaz
#+cats
import cats._, cats.data._, cats.implicits._
import fs2.interop.cats._
#-cats
val xa = DriverManagerTransactor[IOLite](
"org.postgresql.Driver", "jdbc:postgresql:world", "postgres", ""
Expand All @@ -40,7 +41,7 @@ All **doobie** monads have associated instances of the `Catchable` typeclass, an
- `attempt` converts `M[A]` into `M[Throwable \/ A]`
#-scalaz
#+cats
- `attempt` converts `M[A]` into `M[Throwable Xor A]`
- `attempt` converts `M[A]` into `M[Either[Throwable, A]]`
#-cats
- `fail` constructs an `M[A]` that fails with a provided `Throwable`

Expand Down Expand Up @@ -72,7 +73,7 @@ And finally we have a set of combinators that focus on `SQLState`s.
- `attemptSqlState` is like `attemptSql` but yields `M[SQLState \/ A]`.
#-scalaz
#+cats
- `attemptSqlState` is like `attemptSql` but yields `M[SQLState Xor A]`.
- `attemptSqlState` is like `attemptSql` but yields `M[Either[SQLState, A]]`.
#-cats
- `attemptSomeSqlState` traps only specified `SQLState`s.
- `exceptSqlState` recovers from a `SQLState` with a new action.
Expand Down Expand Up @@ -132,7 +133,7 @@ import doobie.postgres.sqlstate.class23.UNIQUE_VIOLATION
def safeInsert(s: String): ConnectionIO[String \/ Person] =
#-scalaz
#+cats
def safeInsert(s: String): ConnectionIO[String Xor Person] =
def safeInsert(s: String): ConnectionIO[Either[String, Person]] =
#-cats
insert(s).attemptSomeSqlState {
case UNIQUE_VIOLATION => "Oops!"
Expand Down
1 change: 1 addition & 0 deletions yax/docs/src/main/tut/09-Arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import scalaz._, Scalaz._
#-scalaz
#+cats
import cats._, cats.data._, cats.implicits._
import fs2.interop.cats._
#-cats
val xa = DriverManagerTransactor[IOLite](
"org.postgresql.Driver", "jdbc:postgresql:world", "postgres", ""
Expand Down
26 changes: 21 additions & 5 deletions yax/docs/src/main/tut/10-Custom-Mappings.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ In this chapter we learn how to use custom `Meta` instances to map arbitrary dat

### Setting Up

The examples in this chapter require the `contrib-postgresql` add-on, as well as the [argonaut](http://argonaut.io/) JSON library, which you can add to your build thus:
#+scalaz
The examples in this chapter require the `postgres` add-on, as well as the [argonaut](http://argonaut.io/) JSON library, which you can add to your build thus:
#-scalaz
#+cats
The examples in this chapter require the `postgres` add-on, as well as the [circe](http://circe.io/) JSON library, which you can add to your build thus:
#-cats

```scala
#+scalaz
libraryDependencies += "io.argonaut" %% "argonaut" % "6.2-M1" // as of date of publication
libraryDependencies += "io.argonaut" %% "argonaut" % "6.2-M3" // as of date of publication
#-scalaz
#+cats
val circeVersion = "0.4.1"
val circeVersion = "0.5.3"

libraryDependencies ++= Seq(
"io.circe" %% "circe-core",
Expand Down Expand Up @@ -44,6 +49,7 @@ import scalaz._, Scalaz._
#-scalaz
#+cats
import cats._, cats.implicits._
import fs2.interop.cats._
#-cats

val xa = DriverManagerTransactor[IOLite](
Expand Down Expand Up @@ -141,7 +147,12 @@ Note that the `Composite` width is now a single column. The rule is: if there ex

Some modern databases support a `json` column type that can store structured data as a JSON document, along with various SQL extensions to allow querying and selecting arbitrary sub-structures. So an obvious thing we might want to do is provide a mapping from Scala model objects to JSON columns, via some kind of JSON serialization library.

#+scalaz
We can construct a `Meta` instance for the argonaut `Json` type by using the `Meta.other` constructor, which constructs a direct object mapping via JDBC's `.getObject` and `.setObject`. In the case of PostgreSQL the JSON values are marshalled via the `PGObject` type, which encapsulates an uninspiring `(String, String)` pair representing the schema type and its string value.
#-scalaz
#+cats
We can construct a `Meta` instance for the circe `Json` type by using the `Meta.other` constructor, which constructs a direct object mapping via JDBC's `.getObject` and `.setObject`. In the case of PostgreSQL the JSON values are marshalled via the `PGObject` type, which encapsulates an uninspiring `(String, String)` pair representing the schema type and its string value.
#-cats

Here we go:

Expand All @@ -153,7 +164,7 @@ implicit val JsonMeta: Meta[Json] =
a => {
val o = new PGobject
o.setType("json")
o.setValue(a.noSpaces)
o.setValue(a.nospaces)
o
}
#-scalaz
Expand Down Expand Up @@ -192,7 +203,12 @@ def codecMeta[A >: Null : Encoder : Decoder : TypeTag]: Meta[A] =
#-cats
```

Let's make sure it works. Here is a simple data type with an argonaut serializer, taken straight from the website, and a `Meta` instance derived from the code above.
#+scalaz
Let's make sure it works. Here is a simple data type with an argonaut encoder, taken straight from the website, and a `Meta` instance derived from the code above.
#-scalaz
#+cats
Let's make sure it works. Here is a simple data type with an circe encoder, taken straight from the website, and a `Meta` instance derived from the code above.
#-cats

```tut:silent
case class Person(name: String, age: Int, things: List[String])
Expand Down
1 change: 1 addition & 0 deletions yax/docs/src/main/tut/11-Unit-Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import scalaz._, Scalaz._
#-scalaz
#+cats
import cats._, cats.data._, cats.implicits._
import fs2.interop.cats._
#-cats
val xa = DriverManagerTransactor[IOLite](
"org.postgresql.Driver", "jdbc:postgresql:world", "postgres", ""
Expand Down
1 change: 1 addition & 0 deletions yax/docs/src/main/tut/13-Extensions-PostgreSQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import scalaz._, Scalaz._
#-scalaz
#+cats
import cats._, cats.data._, cats.implicits._
import fs2.interop.cats._
#-cats
val xa = DriverManagerTransactor[IOLite](
"org.postgresql.Driver", "jdbc:postgresql:world", "postgres", ""
Expand Down
2 changes: 1 addition & 1 deletion yax/docs/src/main/tut/14-Extensions-H2.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: Extensions for H2
In this chapter we discuss the extended support that **doobie** offers for users of [H2](http://www.h2database.com/html/main.html) . To use these extensions you must add an additional dependency to your project:

```scala
libraryDependencies += "org.tpolecat" %% "doobie-contrib-h2" % "0.2.2"
libraryDependencies += "org.tpolecat" %% "doobie-contrib-h2" % "0.3.0-M1"
```

This library pulls in [H2 Version 1.3.170](http://www.h2database.com/html/main.html) as a transitive dependency.
Expand Down