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

Fix #65: assure incomplete input doesn't pass compilation #211

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
43a0f23
port tut plugin to sbt 1.0.x
larsrh Aug 1, 2017
8d6b2a9
Merge pull request #175 from larsrh/topic/sbt-1.0-redux
tpolecat Aug 4, 2017
3529bfc
Merge remote-tracking branch 'origin/master' into topic/port-168
larsrh Aug 4, 2017
f559d82
Merge pull request #176 from larsrh/topic/port-168
tpolecat Aug 4, 2017
dac0f65
update readme
tpolecat Aug 5, 2017
ad862e2
version 0.6.0
tpolecat Aug 5, 2017
81e8bff
set version to 0.6.1-SNAPSHOT
tpolecat Aug 5, 2017
87df9dc
Merge pull request #177 from tpolecat/0.6.0-staging
tpolecat Aug 5, 2017
a73e574
Build tut-core for Scala 2.10 again
fthomas Aug 20, 2017
3099991
Update scala-xml to 1.0.6 to support 2.13.0-M1
fthomas Aug 29, 2017
d7eb7cc
Merge pull request #180 from fthomas/topic/scala-2.10
tpolecat Aug 29, 2017
899963d
v0.6.1
tpolecat Aug 29, 2017
00689af
set version to 0.6.2-SNAPSHOT
tpolecat Aug 29, 2017
304a05c
Merge pull request #185 from tpolecat/v0.6.1-staging
tpolecat Aug 29, 2017
8479a77
stack safety
tpolecat Sep 6, 2017
03a95db
import
tpolecat Sep 6, 2017
24912ff
Merge pull request #200 from tpolecat/forward-port-190
tpolecat Nov 5, 2017
f48d7c9
sbt-1.0.3
tpolecat Nov 5, 2017
5d272ed
Merge pull request #201 from tpolecat/sbt-1.0.3
tpolecat Nov 5, 2017
076031a
Implemented `passthrough` modifier, allowing for markdown generating …
metasim Aug 31, 2017
8c7d6a4
Merge pull request #202 from tpolecat/forward-port-188
tpolecat Nov 5, 2017
e75800e
go back to use Test scalacOptions in tut
kailuowang Oct 13, 2017
060f9f3
Update build.sbt
kailuowang Oct 17, 2017
84136b1
Merge pull request #203 from tpolecat/forward-port-195
tpolecat Nov 5, 2017
246a5a6
readme, changelog
tpolecat Nov 5, 2017
56ebbc8
set version to 0.6.2
tpolecat Nov 5, 2017
767c137
set version to 0.6.3-SNAPSHOT
tpolecat Nov 5, 2017
bd16a82
Merge pull request #204 from tpolecat/v0.6.2-staging
tpolecat Nov 5, 2017
e67f695
Fixed #197 and enabled ability to fork tut via `fork in (Tut, run) :=…
metasim Nov 2, 2017
7f6e3ff
State of `usejavacp` has to be dependent upon whether run is in sbt o…
metasim Nov 2, 2017
6630b92
Merge pull request #207 from metasim/fix-206
tpolecat Feb 25, 2018
e70d365
unibuild
tpolecat Feb 25, 2018
07e8313
sbt-release attempt 1
tpolecat Feb 25, 2018
dcdba3b
Setting version to 0.6.3-M1
tpolecat Feb 25, 2018
f6b7568
Setting version to 0.6.3-SNAPSHOT
tpolecat Feb 25, 2018
806c296
versions
tpolecat Feb 25, 2018
315fddd
Merge pull request #214 from tpolecat/build
tpolecat Feb 25, 2018
1c2888c
moved subprojects into modules
tpolecat Feb 25, 2018
f257a11
microsite
tpolecat Feb 26, 2018
f560c61
clarify 2.13 version
tpolecat Feb 26, 2018
5ba2468
stinkin badges
tpolecat Feb 26, 2018
d02c12d
Merge pull request #215 from tpolecat/microsite
tpolecat Feb 26, 2018
71a1a25
2.13.0-M3
tpolecat Feb 26, 2018
e816496
Setting version to 0.6.3-M2
tpolecat Feb 26, 2018
a9eda79
Setting version to 0.6.3-SNAPSHOT
tpolecat Feb 26, 2018
ea35cf7
Setting version to 0.6.3-M3
tpolecat Feb 26, 2018
d892aee
Setting version to 0.6.3-SNAPSHOT
tpolecat Feb 26, 2018
b290a48
hackity-hack
tpolecat Feb 26, 2018
6ddcbb3
Setting version to 0.6.3-M4
tpolecat Feb 26, 2018
7fcb33a
Setting version to 0.6.3-SNAPSHOT
tpolecat Feb 26, 2018
a19ad0b
hackity-hack
tpolecat Feb 26, 2018
980a715
Setting version to 0.6.3-M5
tpolecat Feb 26, 2018
b5091e6
Setting version to 0.6.3-SNAPSHOT
tpolecat Feb 26, 2018
9360005
faaahk ok. thx eugene
tpolecat Feb 26, 2018
8f8b605
Merge pull request #216 from tpolecat/2.13.0-M3
tpolecat Mar 1, 2018
4dc0db5
Docs: scalacOptions for unused imports
daddykotex Mar 12, 2018
9c2d314
Merge pull request #217 from daddykotex/faq-fix
tpolecat Mar 13, 2018
6d31dc4
Fix #65: assure incomplete input doesn't pass compilation
felixmulder Mar 20, 2018
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
21 changes: 11 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ before_cache:
- find $HOME/.ivy2 -name "ivydata-*.properties" -delete
- find $HOME/.sbt -name "*.lock" -delete

jdk:
- oraclejdk8

scala:
- 2.10.6
- 2.12.2
- 2.13.0-M1

matrix:
include:
- scala: 2.11.8
- scala: 2.10.6
env: TEST_SCRIPTED=0
jdk: oraclejdk8
- scala: 2.11.12
env: TEST_SCRIPTED=1
jdk: oraclejdk8
- scala: 2.12.4
env: TEST_SCRIPTED=0
jdk: oraclejdk8
- scala: 2.13.0-M3
env: TEST_SCRIPTED=0
jdk: oraclejdk8

script:
- sbt ++$TRAVIS_SCALA_VERSION core/compile core/publishLocal
- sbt plugin/compile plugin/publishLocal
- "if [[ $TEST_SCRIPTED = 1 ]]; then sbt scripted; fi"
- "if [[ $TEST_SCRIPTED = 1 ]]; then sbt tests/scripted; fi"

notifications:
webhooks:
Expand Down
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

This file summarizes **notable** changes for each release, but does not describe internal changes unless they are particularly exciting. For complete details please see the corresponding [milestones](https://github.com/tpolecat/tut/milestones?state=closed) and their associated issues.

### <a name="0.6.2"></a>Work in Progress for Version 0.6.3

- `fork in (Tut, run) := true` now works for real, sorry (thanks again @metasim).
- Build is now modern and uses `sbt-release` (finally!) so publishing is no longer a nightmare.


### <a name="0.6.2"></a>New and Noteworthy for Version 0.6.2

This release forward-ports improvements from 0.5.5 and 0.5.6.

- New `passthrough` modifier for code that generates markdown (thanks @metasim).
- `fork in (Tut, run) := true` now works (thanks again @metasim).
- `scalacOptions in Tut` now defaults to `scalacOptions in Test` which allows Scalameta to work properly (it doesn't work in console for some reason ... thanks @kailuowang and @suhasgaddam).
- Fixes stack overflows with large input files and cleans up the FP micro-library.

### <a name="0.6.1"></a>New and Noteworthy for Version 0.6.1

This updates scala-xml to 1.0.6 as required by Scala 2.13.0-M1, and reverts removal of 2.10 support. Thanks :sparkles: Frank Thomas :sparkles: for this contribution.

### <a name="0.6.0"></a>New and Noteworthy for Version 0.6.0

First release for sbt 1.0, courtesy of sparkly :sparkles: Lars Hupel :sparkles:.

------

*See the `master` branch for further developments in the 0.5.x series.*

### <a name="0.5.2"></a>New and Noteworthy for Version 0.5.2

Somehow :confused: tpolecat :confused: botched the 0.5.1 release, which didn't actually include the only change it was intended to include. This uh, fixes that.
Expand Down
187 changes: 2 additions & 185 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,193 +1,10 @@
# tut

<img src="https://api.travis-ci.org/tpolecat/tut.svg?branch=master"/><br>
[![Travis CI](https://travis-ci.org/tpolecat/tut.svg?branch=series%2F0.6.x)](https://travis-ci.org/tpolecat/tut)
[![Join the chat at https://gitter.im/tpolecat/tut](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/tpolecat/tut?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

<img alt="How'd you get so funky?" align=right src="tut.jpg"/>

**tut** is a very simple documentation tool for Scala that reads Markdown files and interprets Scala code in `tut` sheds, allowing you to write documentation that is typechecked and run as part of your build.

The current version is **0.5.2** (changelog [here](CHANGELOG.md), upgrade instructions for 0.5.x series [here](#0.5.x)) which runs on **Scala 2.10**, **2.11**, and **2.12**.

Projects using **tut** include [doobie](https://github.com/tpolecat/doobie), [frameless](https://github.com/typelevel/frameless) and [cats](https://github.com/typelevel/cats). If you're using it and would like be added to the list, please submit a PR!

**tut** is a [Typelevel](http://typelevel.org/) project. This means we embrace pure, typeful, functional programming, and provide a safe and friendly environment for teaching, learning, and contributing as described in the Typelevel [Code of Conduct](http://typelevel.org/conduct.html).

### Quick Start (sbt)

**1**. Add the following to `project/plugins.sbt`:

```scala
addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.5.2")
```

**2**. And add the following to `build.sbt`:

```scala
enablePlugins(TutPlugin)
```

**3**. Write a tutorial in `src/main/tut/Foo.md`:

Here is how you add numbers:
```tut
1 + 1
```

**4**. At the `sbt>` prompt type `tut`, then look at the output in `target/<scala-version>/tut/Foo.md`:

Here is how you add numbers:
```scala
scala> 1 + 1
res0: Int = 2
```

### Quick Start (standalone)

In case you want to run **tut** without sbt, you can use **coursier** instead.

**1**. Install the **coursier** [command-line launcher](https://github.com/alexarchambault/coursier#command-line-1).

**2**. Run **tut**:

```
coursier launch -r "https://dl.bintray.com/tpolecat/maven/" org.tpolecat:tut-core_2.11:0.5.2 -- \
in out '.*\.md$' -classpath $(coursier fetch -p com.chuusai:shapeless_2.11:2.3.1)
```

This will process all `*.md` files in `in`, write them to `out`, while providing `com.chuusai:shapeless_2.11:2.3.1` in the classpath.
Note that the Scala library always needs to be in the classpath.

### Commands

**tut** adds the following commands:

| Command | Explanation |
|----------|-------------|
| `tut` | Moves the contents of `tutSourceDirectory` into `tutTargetDirectory`, interpreting code in `tut` sheds in any file whose name matches `tutNameFilter` (other files are copied but not interpreted). |
| `tutQuick` | Like `tut` but compiles only files that have changed since last compilation. Note that this does *not* detect changes in Scala sources; it only looks at tut sources. |
| <code>tutOnly&nbsp;&lt;path&gt;</code> | Does the same thing as `tut` but only for the specified path under `tutSourceDirectory`. Note that tab completion works for this command |

Interpretation obeys the following particulars:

- Each file is interpreted with an independent REPL session. Definitions earlier in the file are available later in the file.
- Each REPL has the same classpath as your build's `Test` configuration, and by default also has the same scalac options and compiler plugins.
- By default any error in interpretation (compilation failure or runtime exception) will cause the `tut` command to fail. If this command is part of your CI configuration then your build will fail. Yay!
- **tut** captures output from the REPL, as well as anything your code writes to standard output (`System.out`). ANSI escapes are removed from this output, so colorized console output will show up as plaintext.
- In modes that show REPL prompts (see below) blank lines *in between statements* are discarded and a single blank line is introduced between prompts, as in the normal REPL. Otherwise blank lines are neither introduced nor discarded. This is a change from prior versions.


### Modifiers

By default **tut** will interpret code in `tut` sheds as if it had been pasted into a Scala REPL. However sometimes you might want a definition without REPL noise, or might want to demonstrate non-compiling code (which would normally cause the build to fail). For these occasions **tut** provides a number of modifiers that you can add to the shed declaration. For instance,

```tut:silent
import com.woozle.fnord._
```

will produce the following output, suppressing REPL noise:

```scala
import com.woozle.fnord._
```

The following modifiers are supported. Note that you can use multiples if you like; for example you could use `tut:silent:fail` to show code that doesn't compile, without showing the compilation error.

| Modifier | Explanation |
|-------------|-------------|
| `:fail` | Code in the shed *must* throw an exception or fail to compile. Successful interpretation will cause a build failure. |
| `:nofail` | Code in the shed *might* throw an exception or fail to compile. Such failure will *not* cause a build failure. Note that this modifier is **deprecated** in favor of `:fail`. |
| `:silent` | Suppresses REPL prompts and output; under this modifier the input and output text are identical. |
| `:plain` | Output will not have `scala` syntax highlighting. |
| `:invisible` | Suppresses all output. This is not recommended since the point of **tut** is to provide code that the user can type in and expect to work. But in rare cases you might want one of these at the bottom of your file to clean up filesystem mess that your code left behind. |
| `:book` | Output will be suitable for copy and paste into the REPL. That is, there are no REPL prompts or margins, and output from the REPL is commented. |
| `:evaluated` | Suppresses REPL prompts and input statement, output only will be the evaluated statement. |
| `:decorate(param)` | Decorates the output scala code block with `param`, enclosed in this way: `{: param }`, for use with Kramdown. You can add several `decorate` modifiers if you wish. |
| `:reset` | Resets the REPL state prior to evaluating the code block. Use this option with care, as it has no visible indication and can be confusing to readers who are following along in their own REPLs. |

### Settings

**tut** also adds the following sbt settings, all of which have reasonable defaults. It is unlikely that you will need to change any of them, but here you go.

| Setting | Explanation | Default Value |
|---------|-------------|---------------|
| `tutSourceDirectory` | Location of **tut** source files. | `(sourceDirectory.value in Compile) / "tut"` |
| `tutNameFilter` | Regex specifying files that should be interpreted. | Names ending in `.md` `.txt` `.htm` `.html` |
| `tutTargetDirectory` | Destination for **tut** output. | `crossTarget.value / "tut"` |
| `scalacOptions in Tut` | Compiler options that will be passed to the **tut** REPL. | Same as `Test` configuration. |
| `tutPluginJars` | List of compiler plugin jarfiles to be passed to the **tut** REPL. | Same as `Test` configuration. |

It's possible to add tut-specific dependencies through the `% "tut"` modifier.
For example:

```scala
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.13.5" % "tut"
```

### <a name="0.5.x"></a>Upgrading from 0.4.x

The 0.5.x series includes a few breaking changes from 0.4.x.

##### tutSettings

Tut is now an autoplugin, and its settings are imported automatically when it's enabled:

* remove `tutSettings`
* add `enablePlugins(TutPlugin)`

##### tutScalacOptions

This setting does not exist anymore, but you can replace it with `(scalacOptions in Tut)` everywhere it was used.

##### Warnings on unused imports

Tut does not filter out `-Ywarn-unused-imports` from its `scalacOptions` anymore. If you need to re-enable that behaviour, simply add:

```scala
scalacOptions in Tut := (scalacOptions in Tut).value.filterNot(Set("-Ywarn-unused-import"))
```

##### Missing dependencies

Tut does not inherit its CLASSPATH from the `Test` configuration anymore. If this breaks your build, you can add missing dependencies manually by using the `% "tut"` modifier. For example:

```scala
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.13.5" % "tut"
```


### Integration with sbt-microsites

The [sbt-microsites plugin](https://47deg.github.io/sbt-microsites/) uses **tut** and **sbt-site** and some other odds and ends to turn your documentation into a really nice little website. It is entirely excellent and I recommend it highly.

### Integration with sbt-site

If you wish to use **tut** with [sbt-site](https://github.com/sbt/sbt-site) add the following to `project/plugins.sbt` in your project to add SBT shell commands:

```scala
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "0.8.1")
```

Then in your build sbt, link the files generated by tut to your site generation:

```scala
project("name").settings(site.addMappingsToSiteDir(tut, "tut"))
```

When the `makeSite` task is run in sbt, the typechecked tutorials from `src/main/tut` will be incorporated with the site generated by sbt-site in `target/site`.

### Running the Tests

There are a set of test markdown files and corresponding expected markdown output from **tut**.
Run these tests from sbt with:

```
publishLocal
tests/scripted
```

### Complaints and other Feedback

Feedback of any kind is always appreciated.

Issues and PR's are welcome, or just find me on Twitter or `#scala` on FreeNode or on [gitter](https://gitter.im/tpolecat/tut).
Please proceed to the [**microsite**](http://tpolecat.github.io/tut/) for more information.
Loading