Skip to content

Commit

Permalink
Add top-level heading to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Christer van der Meeren committed Sep 12, 2023
1 parent 0cbcf15 commit 3735d39
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Table of contents
# Faqt documentation

## Table of contents

<img src="https://raw.githubusercontent.com/cmeeren/Faqt/main/logo/faqt-logo-docs.png" width="300" align="right" />

Expand All @@ -22,7 +24,7 @@

<!-- TOC -->

# Installation and requirements
## Installation and requirements

1. Install Faqt [from NuGet](https://www.nuget.org/packages/Faqt). Faqt supports .NET 5.0 and higher.
2. If you use path mapping (e.g., CI builds with `DeterministicSourcePaths` enabled) or want to execute assertions where
Expand All @@ -43,7 +45,7 @@
Note that `DebugType=embedded` is automatically set
by [DotNet.ReproducibleBuilds](https://github.com/dotnet/reproducible-builds) if you use that.

# Multiple assertion chains without `|> ignore`
## Multiple assertion chains without `|> ignore`

Since assertions return `And` or `AndDerived`, F# will warn you if an assertion chain is not the last line of an
expression. You have to `|> ignore` all lines (except the last) in order to remove this warning.
Expand All @@ -65,7 +67,7 @@ If you want to use another operator, you can define your own just as easily.
See [this StackOverflow answer](https://stackoverflow.com/a/34188952/2978652) for valid prefix operators. However, your
custom operator will then be shown in the subject name (whereas `%` is automatically removed).

# Writing your own assertions
## Writing your own assertions

Writing your own assertions is easy! Custom assertions are implemented exactly like Faqt’s built-in assertions, so you
can always look at those for inspiration (see all files ending with `Assertions`
Expand Down Expand Up @@ -243,7 +245,7 @@ If you want all the details, here they are:
But was: false
```

# Customizing the format
## Customizing the format

Faqt's formatter is implemented as a simple function with signature `FailureData -> string`.

Expand Down Expand Up @@ -279,7 +281,7 @@ Formatter.Set(myFormatter)
use _ = Formatter.With(myConfig)
```

# Configuring options
## Configuring options

Faqt contains some configurable options, such as the maximum length to display when rendering `HttpContent`. Options are
configured similarly to the formatter:
Expand All @@ -306,22 +308,22 @@ use _ = Config.With(myConfig)
myFormatter Config.Current
```

# Security considerations
## Security considerations

**Treat assertion exception messages (and therefore test failure messages) as securely as you treat your source code.**

Faqt derives subject names from your source code. Known existing limitations (see below) as well as bugs can cause Faqt
to use a lot more of your code in the subject name than intended (up to entire source files). Therefore, do not give
anyone access to Faqt assertion failure messages that should not have access to your source code.

# FAQ
## FAQ

## Which testing frameworks does Faqt work with?
### Which testing frameworks does Faqt work with?

All of them. XUnit, NUnit, MSTest, NSpec, MSpec, Expecto, you name it. Faqt is agnostic to the test framework (and can
also be used in non-test production code); it simply throws a custom exception when an assertion fails.

## Why is the subject name not correct in my specific example?
### Why is the subject name not correct in my specific example?

The automatic subject name (the first part of the assertion message) is correct in most situations, but there are edge
cases where it may produce unexpected results:
Expand Down Expand Up @@ -350,7 +352,7 @@ simple regex-based processing/replacement of the call chain based on which asser
If you would like to help make the automatic subject name functionality more robust, please raise an issue. You can find
the relevant code in [SubjectName.fs](https://github.com/cmeeren/Faqt/blob/main/src/Faqt/SubjectName.fs).

## Why do I have to use `Should(())` inside an assertion chain?
### Why do I have to use `Should(())` inside an assertion chain?

This is due to how subject names are implemented, and the solution was chosen as the lesser of several evils. The
details are probably boring, but in short, when an assertion fails, Faqt needs to know the chain of assertions
Expand All @@ -364,7 +366,7 @@ entirely), or make the subject name incorrect in many more cases (e.g. by removi
assertion history altogether, thereby only giving correct subject names up to the first assertion of any given name in a
chain).

## Why does this assertion pass/fail for null?
### Why does this assertion pass/fail for null?

Note: I recognize that the below is not the only way to look at the issue. If you fundamentally disagree with this
policy, I am open to discussing it. Please raise an issue.
Expand Down Expand Up @@ -397,7 +399,7 @@ The only exceptions are for assertions that check equality, such as `Be` or `BeS
to `null` (which is consistent with the default F# implementations of structural and reference equality). This also
extends to `SequenceEqual` and `HaveSameItemsAs`, which will pass if both sequences are `null`.

## Why not FluentAssertions?
### Why not FluentAssertions?

FluentAssertions is a fantastic library, and very much the inspiration for Faqt. Unfortunately, its API design causes
trouble for F#. Here are the reasons I decided to make Faqt instead of just using FluentAssertions:
Expand All @@ -420,13 +422,13 @@ Note that Faqt does not aim for feature parity with FluentAssertions. For exampl
multiple assertions simultaneously; like almost all assertion libraries, it stops at the first failure ("monadic"
instead of "applicative" behavior).

## Why not Shouldly?
### Why not Shouldly?

I will admit I have not used Shouldly myself, but its feature set (ignoring the actual assertions) seem to be a subset
of that of FluentAssertions. For example, it does not support chaining assertions. However, I like its easy-to-read
assertion failure messages, and have used those as inspiration for Faqt's assertion messages.

## Why not Unquote?
### Why not Unquote?

[Unquote](https://github.com/SwensenSoftware/unquote) is a great library built on a great idea: Use code quotations with
arbitrary `bool`-returning F# expressions as your assertions, and Unquote will display step-by-step evaluations if the
Expand All @@ -444,7 +446,7 @@ Unfortunately, I stopped using it because of several issues:
* I need assertions that can work in production code, too. I assume that evaluating quotations has a significant
performance impact. (I have admittedly not measured this, since I stopped using it for the reasons above anyway.)

## Can I use Faqt from C#?
### Can I use Faqt from C#?

Faqt is designed only for F#. The subject names only work correctly for F#, and the API design and assertion choices are
based on F# idioms and expected usage. Any support for C# is incidental, and improving or even preserving C# support is
Expand Down

0 comments on commit 3735d39

Please sign in to comment.