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

Extract testkit project #211

Merged
merged 2 commits into from
Jun 21, 2018
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
29 changes: 25 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

lazy val paradox = project
.in(file("."))
.aggregate(core, plugin, themePlugin, themes, docs)
.aggregate(core, testkit, tests, plugin, themePlugin, themes, docs)
.enablePlugins(NoPublish)
.settings(inThisBuild(List(
organization := "com.lightbend.paradox",
Expand All @@ -42,13 +42,34 @@ lazy val core = project
name := "paradox",
libraryDependencies ++= Seq(
Library.pegdown,
Library.st4,
Library.scalatest % "test",
Library.jtidy % "test"
Library.st4
),
parallelExecution in Test := false
)

lazy val testkit = project
.in(file("testkit"))
.dependsOn(core)
.disablePlugins(BintrayPlugin)
.enablePlugins(SonatypePublish)
.settings(
name := "testkit",
libraryDependencies ++= Seq(
Library.jtidy
)
)

lazy val tests = project
.in(file("tests"))
.dependsOn(core, testkit)
.enablePlugins(NoPublish)
.settings(
name := "tests",
libraryDependencies ++= Seq(
Library.scalatest % "test"
)
)

lazy val plugin = project
.in(file("plugin"))
.dependsOn(core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ package com.lightbend.paradox.markdown

import com.lightbend.paradox.tree.Tree.{ Forest, Location }
import java.io.{ File, PrintWriter }
import org.scalatest.{ FlatSpec, Matchers }
import com.lightbend.paradox.template.PageTemplate
import java.nio.file._

abstract class MarkdownBaseSpec extends FlatSpec with Matchers {
abstract class MarkdownTestkit {

val markdownReader = new Reader
val markdownWriter = new Writer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.lightbend.paradox.markdown
class FiddleDirectiveSpec extends MarkdownBaseSpec {

// #fiddle_code
val sourcePath = new java.io.File(".").getAbsolutePath + "/core/src/test/scala/"
val sourcePath = new java.io.File(".").getAbsolutePath + "/tests/src/test/scala/"
// #fiddle_code

"Fiddle directive" should "generate fiddle iframe" in {
Expand All @@ -28,7 +28,7 @@ class FiddleDirectiveSpec extends MarkdownBaseSpec {
|@@fiddle [FiddleDirectiveSpec.scala](./FiddleDirectiveSpec.scala) { #fiddle_code extraParams=theme=light&layout=v75 cssStyle=width:100%; }
""").values.head shouldEqual html("""
|<iframe class="fiddle" src=
"https://embed.scalafiddle.io/embed?theme=light&amp;layout=v75&amp;source=import%20fiddle.Fiddle%2C%20Fiddle.println%0A%40scalajs.js.annotation.JSExport%0Aobject%20ScalaFiddle%20%7B%0A%20%20%2F%2F%20%24FiddleStart%0Aval%20sourcePath%20%3D%20new%20java.io.File%28%22.%22%29.getAbsolutePath%20%2B%20%22%2Fcore%2Fsrc%2Ftest%2Fscala%2F%22%0A%20%20%2F%2F%20%24FiddleEnd%0A%7D%0A"
"https://embed.scalafiddle.io/embed?theme=light&amp;layout=v75&amp;source=import%20fiddle.Fiddle%2C%20Fiddle.println%0A%40scalajs.js.annotation.JSExport%0Aobject%20ScalaFiddle%20%7B%0A%20%20%2F%2F%20%24FiddleStart%0Aval%20sourcePath%20%3D%20new%20java.io.File%28%22.%22%29.getAbsolutePath%20%2B%20%22%2Ftests%2Fsrc%2Ftest%2Fscala%2F%22%0A%20%20%2F%2F%20%24FiddleEnd%0A%7D%0A"
frameborder="0" style="width:100%;"></iframe>
""".stripMargin)
}
Expand All @@ -39,7 +39,7 @@ class FiddleDirectiveSpec extends MarkdownBaseSpec {
|@@fiddle [FiddleDirectiveSpec.scala](./FiddleDirectiveSpec.scala) { #fiddle_code width=100px height=100px extraParams=theme=light&layout=v75 cssStyle=width:100%; }
""").values.head shouldEqual html("""
|<iframe class="fiddle" width="100px" height="100px" src=
"https://embed.scalafiddle.io/embed?theme=light&amp;layout=v75&amp;source=import%20fiddle.Fiddle%2C%20Fiddle.println%0A%40scalajs.js.annotation.JSExport%0Aobject%20ScalaFiddle%20%7B%0A%20%20%2F%2F%20%24FiddleStart%0Aval%20sourcePath%20%3D%20new%20java.io.File%28%22.%22%29.getAbsolutePath%20%2B%20%22%2Fcore%2Fsrc%2Ftest%2Fscala%2F%22%0A%20%20%2F%2F%20%24FiddleEnd%0A%7D%0A"
"https://embed.scalafiddle.io/embed?theme=light&amp;layout=v75&amp;source=import%20fiddle.Fiddle%2C%20Fiddle.println%0A%40scalajs.js.annotation.JSExport%0Aobject%20ScalaFiddle%20%7B%0A%20%20%2F%2F%20%24FiddleStart%0Aval%20sourcePath%20%3D%20new%20java.io.File%28%22.%22%29.getAbsolutePath%20%2B%20%22%2Ftests%2Fsrc%2Ftest%2Fscala%2F%22%0A%20%20%2F%2F%20%24FiddleEnd%0A%7D%0A"
frameborder="0" style="width:100%;"></iframe>
""".stripMargin)
}
Expand All @@ -50,7 +50,7 @@ class FiddleDirectiveSpec extends MarkdownBaseSpec {
|@@fiddle [FiddleDirectiveSpec.scala](./FiddleDirectiveSpec.scala) { #fiddle_code baseUrl=http://shadowscalafiddle.io width=100px height=100px extraParams=theme=light&layout=v75 cssStyle=width:100%; }
""").values.head shouldEqual html("""
|<iframe class="fiddle" width="100px" height="100px" src=
"http://shadowscalafiddle.io?theme=light&amp;layout=v75&amp;source=import%20fiddle.Fiddle%2C%20Fiddle.println%0A%40scalajs.js.annotation.JSExport%0Aobject%20ScalaFiddle%20%7B%0A%20%20%2F%2F%20%24FiddleStart%0Aval%20sourcePath%20%3D%20new%20java.io.File%28%22.%22%29.getAbsolutePath%20%2B%20%22%2Fcore%2Fsrc%2Ftest%2Fscala%2F%22%0A%20%20%2F%2F%20%24FiddleEnd%0A%7D%0A"
"http://shadowscalafiddle.io?theme=light&amp;layout=v75&amp;source=import%20fiddle.Fiddle%2C%20Fiddle.println%0A%40scalajs.js.annotation.JSExport%0Aobject%20ScalaFiddle%20%7B%0A%20%20%2F%2F%20%24FiddleStart%0Aval%20sourcePath%20%3D%20new%20java.io.File%28%22.%22%29.getAbsolutePath%20%2B%20%22%2Ftests%2Fsrc%2Ftest%2Fscala%2F%22%0A%20%20%2F%2F%20%24FiddleEnd%0A%7D%0A"
frameborder="0" style="width:100%;"></iframe>
""".stripMargin)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ class GitHubDirectiveSpec extends MarkdownBaseSpec {
it should "support line labels" in {
markdown("""
|@github[example.scala] { #github-path-link }
|@github[neither](core/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #github-neither-path-link }
|@github[neither](/core/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #github-neither-path-link }
|@github[neither](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #github-neither-path-link }
|@github[neither](/tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #github-neither-path-link }
|
| [example.scala]: core/src/test/scala/com/lightbend/paradox/markdown/example.scala
| [example.scala]: tests/src/test/scala/com/lightbend/paradox/markdown/example.scala
|""") shouldEqual html("""
|<p><a href="https://github.com/lightbend/paradox/tree/v0.2.1/core/src/test/scala/com/lightbend/paradox/markdown/example.scala#L20-L24">example.scala</a>
|<a href="https://github.com/lightbend/paradox/tree/v0.2.1/core/src/test/scala/com/lightbend/paradox/markdown/example.scala#L22">neither</a>
|<a href="https://github.com/lightbend/paradox/tree/v0.2.1/core/src/test/scala/com/lightbend/paradox/markdown/example.scala#L22">neither</a></p>
|<p><a href="https://github.com/lightbend/paradox/tree/v0.2.1/tests/src/test/scala/com/lightbend/paradox/markdown/example.scala#L20-L24">example.scala</a>
|<a href="https://github.com/lightbend/paradox/tree/v0.2.1/tests/src/test/scala/com/lightbend/paradox/markdown/example.scala#L22">neither</a>
|<a href="https://github.com/lightbend/paradox/tree/v0.2.1/tests/src/test/scala/com/lightbend/paradox/markdown/example.scala#L22">neither</a></p>
|""")
}

Expand All @@ -148,12 +148,12 @@ class GitHubDirectiveSpec extends MarkdownBaseSpec {
it should "throw exceptions for non-existing GitHub tree path with invalid label" in {
val ex = the[ExternalLinkDirective.LinkException] thrownBy {
markdown("""
|@github[neither](core/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #does-not-exist }
|@github[neither](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #does-not-exist }
|""")
}

ex.getMessage.replace('\\', '/') shouldBe
"Failed to resolve [core/src/test/scala/com/lightbend/paradox/markdown/example.scala] referenced from [test.html]: Label [does-not-exist] not found in [core/src/test/scala/com/lightbend/paradox/markdown/example.scala]"
"Failed to resolve [tests/src/test/scala/com/lightbend/paradox/markdown/example.scala] referenced from [test.html]: Label [does-not-exist] not found in [tests/src/test/scala/com/lightbend/paradox/markdown/example.scala]"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright © 2015 - 2017 Lightbend, Inc. <http://www.lightbend.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.lightbend.paradox.markdown

import org.scalatest.{ FlatSpecLike, Matchers }

abstract class MarkdownBaseSpec extends MarkdownTestkit with Matchers with FlatSpecLike {

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
}

"The `snip` directive" should "render code snippets" in {
markdown("""@@snip[example.scala](core/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example }""") shouldEqual html("""
markdown("""@@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example }""") shouldEqual html("""
|<pre class="prettyprint">
|<code class="language-scala">
|object example extends App {
Expand All @@ -39,10 +39,10 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
it should "render code snippets in definition lists" in {
markdown("""
|Scala
|: @@snip[example.scala](core/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example }
|: @@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example }
|
|Java
|: @@snip[example2.java](core/src/test/scala/com/lightbend/paradox/markdown/example2.java) { #example2 }
|: @@snip[example2.java](tests/src/test/scala/com/lightbend/paradox/markdown/example2.java) { #example2 }
|""") shouldEqual html("""
|<dl>
|<dt>Scala</dt>
Expand Down Expand Up @@ -70,7 +70,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {

it should "support custom CSS classes" in {
markdown("""
|@@snip[example2.java](core/src/test/scala/com/lightbend/paradox/markdown/example2.java){ #example2 .red .blue }
|@@snip[example2.java](tests/src/test/scala/com/lightbend/paradox/markdown/example2.java){ #example2 .red .blue }
|""") shouldEqual html("""
|<pre class="prettyprint red blue">
|<code class="language-java">
Expand All @@ -83,7 +83,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
}

it should "trim indentation from snippets" in {
markdown("""@@snip[example.scala](core/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #indented-example }""") shouldEqual html("""
markdown("""@@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #indented-example }""") shouldEqual html("""
|<pre class="prettyprint">
|<code class="language-scala">
|case object Dent
Expand All @@ -97,14 +97,14 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
"github.root.base_dir" -> ".",
"snip.github_link" -> "true")

markdown("""@@snip[example.scala](core/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example }""") shouldEqual html(
markdown("""@@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example }""") shouldEqual html(
"""<pre class="prettyprint">
|<code class="language-scala">
|object example extends App {
| println("Hello, World!")
|}</code>
|</pre>
|<a href="https://github.com/lightbend/paradox/tree/v0.2.1/core/src/test/scala/com/lightbend/paradox/markdown/example.scala#L28-L30">Full source at GitHub</a>""")
|<a href="https://github.com/lightbend/paradox/tree/v0.2.1/tests/src/test/scala/com/lightbend/paradox/markdown/example.scala#L28-L30">Full source at GitHub</a>""")
}

it should "not link to source if config says so" in {
Expand All @@ -113,7 +113,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
"github.root.base_dir" -> ".",
"snip.github_link" -> "false")

markdown("""@@snip[example.scala](core/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example }""") shouldEqual html(
markdown("""@@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example }""") shouldEqual html(
"""<pre class="prettyprint">
|<code class="language-scala">
|object example extends App {
Expand Down