Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Fixed #197 #198

Merged
merged 2 commits into from
Nov 5, 2017
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
6 changes: 5 additions & 1 deletion core/src/main/scala/tut/FileIO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ object FileIO {
}}}}}}

private def newInterpreter(pw: PrintWriter, opts: List[String]): IO[IMain] =
IO(new IMain(new Settings <| (_.embeddedDefaults[TutMain.type]) <| (_.processArguments(opts, true)), pw))
IO(new IMain(new Settings <|
(_.embeddedDefaults[TutMain.type]) <|
(_.usejavacp.value = !sys.props("java.class.path").contains("sbt-launch")) <|
(_.processArguments(opts, true)), pw)
)

private[tut] def ls(dir: File): IO[List[File]] =
IO(Option(dir.listFiles).fold(List.empty[File])(_.toList))
Expand Down
6 changes: 3 additions & 3 deletions plugin/src/main/scala/tut/TutPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object TutPlugin extends AutoPlugin {
}.flatMap(_.artifacts.map(_._2))
},
tut := {
val r = (runner in Tut).value
val r = (runner in (Tut, run)).value
val in = tutSourceDirectory.value
val out = tutTargetDirectory.value
val cp = (fullClasspath in Tut).value
Expand All @@ -65,7 +65,7 @@ object TutPlugin extends AutoPlugin {
},
tutOnly := {
val in = tutFilesParser.parsed
val r = (runner in Tut).value
val r = (runner in (Tut, run)).value
val inR = tutSourceDirectory.value // input root
val inDir = if (in.isDirectory) in
else in.getParentFile // input dir
Expand All @@ -78,7 +78,7 @@ object TutPlugin extends AutoPlugin {
tutOne(streams.value, r, in, out, cp, opts, pOpts, re)
},
tutQuick := {
val r = (runner in Tut).value
val r = (runner in (Tut, run)).value
val inR = tutSourceDirectory.value
val outR = tutTargetDirectory.value
val cp = (fullClasspath in Tut).value
Expand Down
14 changes: 14 additions & 0 deletions tests/src/sbt-test/tut/test-13-handles-fork/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
enablePlugins(TutPlugin)

scalaVersion := sys.props("scala.version")

lazy val check = TaskKey[Unit]("check")

fork in (Tut, run) := true

check := {
val expected = IO.readLines(file("expect.md"))
val actual = IO.readLines(crossTarget.value / "tut"/ "test.md")
if (expected != actual)
sys.error("Output doesn't match expected: \n" + actual.mkString("\n"))
}
134 changes: 134 additions & 0 deletions tests/src/sbt-test/tut/test-13-handles-fork/expect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
Foo

```scala
scala> 1 + 1
res0: Int = 2
```

Bar

```scala
2 + 2
```

Baz

```scala
scala> wut
<console>:13: error: not found: value wut
wut
^
```

Qux

```scala
qut
```

Quux

```
scala> 42
res4: Int = 42
```

Should get a warning

```scala
scala> class Functor[F[_]]
warning: there was one feature warning; re-run with -feature for details
defined class Functor
```

Should get an error

```scala
scala> new Functor[Either[String, ?]]
<console>:14: error: not found: type ?
new Functor[Either[String, ?]]
^
<console>:14: error: Either[String,<error>] takes no type parameters, expected: one
new Functor[Either[String, ?]]
^
```

Should be hidden




Should be evaluated

```
Hi, I'm an evaluated expression
```

Should be evaluated and the result is shown

```
sum: Int = 4
```

Expr-interior newlines preserved in normal mode.

```scala
scala> val a = 1
a: Int = 1

scala> val b = 2
b: Int = 2

scala> val c = 3
c: Int = 3

scala> def foo(n: Int): String = {
|
| // interior space
| "bar"
|
| }
foo: (n: Int)String
```

Multiple expressions in an :evaluated block are interpreted according to the code block, where the new lines are preserved

```
a: Int = 4
b: Int = 6
bar: (c: Int)Int
result: Int = 14
14
res9: Int = 14
```

All newlines preserved in silent mode.

```scala
val a = 1
val b = 2
val c = 3

def foo(n: Int): String = {

// interior space
"bar"

}
```

This result is so long that the REPL truncates it to a bunch of `a`s with a `...` at the end.

```scala
scala> val thing = "a" * 1000
thing: String = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
```

```scala
scala> thing
<console>:13: error: not found: value thing
thing
^
```

The end
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("org.tpolecat" % "tut-plugin" % sys.props("project.version"))
117 changes: 117 additions & 0 deletions tests/src/sbt-test/tut/test-13-handles-fork/src/main/tut/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Foo

```tut
1 + 1
```

Bar

```tut:silent
2 + 2
```

Baz

```tut:nofail
wut
```

Qux

```tut:silent:nofail
qut
```

Quux

```tut:plain
42
```

Should get a warning

```tut
class Functor[F[_]]
```

Should get an error

```tut:nofail
new Functor[Either[String, ?]]
```

Should be hidden

```tut:invisible
println("hi")
```

Should be evaluated

```tut:evaluated
println("Hi, I'm an evaluated expression")
```

Should be evaluated and the result is shown

```tut:evaluated
val sum = 2 + 2
```

Expr-interior newlines preserved in normal mode.

```tut
val a = 1
val b = 2
val c = 3

def foo(n: Int): String = {

// interior space
"bar"

}
```

Multiple expressions in an :evaluated block are interpreted according to the code block, where the new lines are preserved

```tut:evaluated
val a = 2 + 2
val b = 3 + 3

def bar(c: Int): Int = {

// interior space
a + b + c
}
val result = bar(4)
println(result)
result
```

All newlines preserved in silent mode.

```tut:silent
val a = 1
val b = 2
val c = 3

def foo(n: Int): String = {

// interior space
"bar"

}
```

This result is so long that the REPL truncates it to a bunch of `a`s with a `...` at the end.

```tut
val thing = "a" * 1000
```

```tut:fail:reset
thing
```

The end
2 changes: 2 additions & 0 deletions tests/src/sbt-test/tut/test-13-handles-fork/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> tut
> check