Skip to content

Commit dace2ea

Browse files
committed
fix: update documentation and minor code adjustments
1 parent 7fb53c6 commit dace2ea

File tree

2 files changed

+61
-29
lines changed

2 files changed

+61
-29
lines changed

Readme.md

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,35 @@
22
<img src="logo.png" height="128" width="128" />
33
</p>
44

5-
# Sprout: BDD Testing for F#
5+
# 🌱 Sprout: BDD Testing for F#
66

7-
> *Write your tests like your thoughts. Sprout is a lightweight F# test DSL with a clean, composable structure built on computation expressions.*
7+
> *Sprout is a lightweight F# test DSL with a clean, composable structure built on computation expressions. This allows your test suites to grow almost organically - i.e. sprout.*
88
99
[![Build](https://github.com/dlidstrom/Sprout/actions/workflows/build.yml/badge.svg)](https://github.com/dlidstrom/Sprout/actions/workflows/build.yml)
1010

1111
## ✅ Features
1212

1313
* Minimalist & expressive BDD-style syntax
14-
* Nestable `describe` blocks
14+
* Nestable `describe` blocks for organizing tests to any depth or complexity
1515
* Computation expressions for `it`, `beforeEach`, `afterEach`
16-
* Pending tests supported by omission
17-
* Logging for improved tracing
16+
* Pending tests support
17+
* Logging for improved traceability
18+
* Built-in assertions: `shouldEqual`, `shouldBeTrue`, `shouldBeFalse`
19+
* These go along way to making your tests readable and expressive due to the
20+
descriptive text that goes along with each `describe` block and `it` test
21+
case. Note that you may use any exception-based constraints library if
22+
desired ([FsUnit.Light](https://github.com/Lanayx/FsUnit.Light) works
23+
beautifully).
24+
* Support for parameterized tests using normal F# loops within `describe` blocks
1825
* Pluggable reporters (console, silent, TAP, JSON)
19-
* Built for F# — no extra syntax or matchers
26+
* Built for F# — simple and idiomatic
27+
* No need for `<|` or functions wrapped in parentheses!
28+
* No need for complex combination of attributes - it's just all F# code!
29+
30+
Sprout provides a clean API for structuring tests. There are a minimum of
31+
abstractions. `describe` blocks may be nested to any suitable depth. It is all
32+
just a matter of *composing* the building blocks. Just like you would expect
33+
coming from a functional programming background.
2034

2135
---
2236

@@ -26,6 +40,8 @@
2640
dotnet add package Sprout
2741
```
2842

43+
> Sprout is currently only available from [GitHub Packages](https://github.com/dlidstrom/Sprout/pkgs/nuget/Sprout).
44+
2945
---
3046

3147
### 🧪 Example Test
@@ -100,6 +116,31 @@ Output:
100116

101117
---
102118

119+
### 📦 Blocks
120+
121+
| Name | Usage | Supported Expressions |
122+
|-|-|-|
123+
| `describe` | Declarative | `it`, `beforeEach`, `afterEach`, `it`, `Info`, `Debug` |
124+
| `it` | Imperative | Any F# expressions, but typically exception-based assertions |
125+
| `beforeEach`, `afterEach` | Imperative | Hook functions that run before and after test cases, respectively |
126+
127+
* **`describe`** - used to define a test suite, or a group of tests. Use the
128+
descriptive text to create descriptive sentences of expected behaviour.
129+
* **`it`** - used to define test assertions, along with a descriptive text to
130+
define the expected behaviour
131+
* **`beforeEach`/`afterEach`** - hook functions that run before and after test
132+
cases, respectively
133+
* **`pending`** - used to denote a pending test case
134+
* **`info`/`debug`** - tracing functions that may be used inside hook functions
135+
and `it` blocks
136+
* **`Info`/`Debug`** - constructor functions that provide tracing inside
137+
`describe` blocks
138+
139+
> Tracing works slightly different in `describe` blocks due to limitations of me
140+
> (most likely) and/or F# computation expressions.
141+
142+
---
143+
103144
### 🧩 Extending Sprout
104145

105146
You can plug in your own reporter:
@@ -115,29 +156,20 @@ type MyCustomReporter() =
115156
member _.End(testResults) = ...
116157
```
117158

118-
---
159+
Use it like this:
119160

120-
### 🎯 Philosophy
121-
122-
Sprout is built on:
123-
124-
* **F# idioms** — computation expressions
125-
* **Extensibility** — pluggable reporters and hooks
126-
127-
### Blocks
128-
129-
| Name | Usage | Supported Expressions |
130-
|-|-|-|
131-
`describe` | Declarative | `it`, `beforeEach`, `afterEach`, `it`, `Info`, `Debug` |
132-
| `it` | Imperative | Any F# expressions, but typically exception-based assertions |
161+
```fsharp
162+
let reporter = MyCustomReporter()
163+
let results = runTestSuiteWithContext reporter suite
164+
```
133165

134166
---
135167

136168
### 📦 Package Info
137169

138170
| | |
139171
| ------- | --------------------------- |
140-
| NuGet | `Sprout` |
172+
| NuGet | [`Sprout`](https://github.com/dlidstrom/Sprout/pkgs/nuget/Sprout) |
141173
| Target | .NET Standard 2.0. |
142174
| License | MIT |
143175
| Author | Daniel Lidström |

Sprout.fs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ module Reporters =
116116
let white = "\u001b[37m"
117117
let reset = "\u001b[0m"
118118

119-
type ConsoleReporter(passedChar, failedChar, pendingChar) =
119+
type ConsoleReporter(passedChar, failedChar, pendingChar, indentString) =
120120
let sw = Stopwatch.StartNew()
121-
let indent (path: Path) = String.replicate ((path.Length - 1) * 2) " "
121+
let indent (path: Path) = String.replicate (path.Length - 1) indentString
122122

123123
new() =
124-
ConsoleReporter("", "", "")
124+
ConsoleReporter("", "", "", " ")
125125

126126
interface ITestReporter with
127127
member _.BeginSuite(name, path) =
@@ -223,10 +223,10 @@ let rec private doRunTestSuite (suite: Describe) (context: TestContext): TestRes
223223
match testCase with
224224
| It itCase ->
225225
runTestCase context.Path itCase beforeHooks afterHooks
226-
| LogStatement logStatement ->
227-
match logStatement with
228-
| Info message -> context.Reporter.Info(message, context.Path)
229-
| Debug message -> context.Reporter.Debug(message, context.Path)
226+
| LogStatement (Info message) ->
227+
context.Reporter.Info(message, context.Path)
228+
| LogStatement (Debug message) ->
229+
context.Reporter.Debug(message, context.Path)
230230
]
231231

232232
for result, logs in testResults do
@@ -255,7 +255,7 @@ let runTestSuiteWithContext (sb: Describe) (context: TestContext) =
255255
context.Reporter.EndSuite(sb.Name, context.Path)
256256
context.Reporter.End testResults
257257

258-
let runTestSuite (sb: Describe) = runTestSuiteWithContext sb TestContext.Empty
258+
let runTestSuite (describe: Describe) = runTestSuiteWithContext describe TestContext.Empty
259259

260260
[<AutoOpen>]
261261
module Constraints =

0 commit comments

Comments
 (0)