Skip to content

Commit 9241e89

Browse files
committed
2 parents ba6d0b1 + cdb240c commit 9241e89

15 files changed

Lines changed: 306 additions & 0 deletions

docs/converter.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,43 @@ return new(
206206
<!-- endSnippet -->
207207

208208

209+
## Excluding targets
210+
211+
Some converters emit the source document (for example a `pdf`, `docx`, or `xlsx`) alongside the info file and the derived targets. That source document is then committed as a `.verified.{extension}` file. Where the document is large, or where its bytes cannot be made deterministic, it can be excluded from the snapshot. The info file and the derived targets continue to verify.
212+
213+
`ExcludeTargets` takes one or more extensions, and drops every matching target:
214+
215+
<!-- snippet: ExcludeTargets -->
216+
<a id='snippet-ExcludeTargets'></a>
217+
```cs
218+
[Fact]
219+
public Task ExcludeConverterSourceTarget() =>
220+
Verify(new MemoryStream("source-document"u8.ToArray()), "excludesource")
221+
.ExcludeTargets("excludesource");
222+
```
223+
<sup><a href='/src/Verify.Tests/Converters/ExcludeTargetsTests.cs#L67-L74' title='Snippet source file'>snippet source</a> | <a href='#snippet-ExcludeTargets' title='Start of snippet'>anchor</a></sup>
224+
<!-- endSnippet -->
225+
226+
Any existing verified file for an excluded extension is then reported as pending deletion.
227+
228+
To exclude an extension for every test, call `ExcludeTargets` on `VerifierSettings` at initialization:
229+
230+
<!-- snippet: StaticExcludeTargets -->
231+
<a id='snippet-StaticExcludeTargets'></a>
232+
```cs
233+
public static class ModuleInitializer
234+
{
235+
[ModuleInitializer]
236+
public static void Init() =>
237+
VerifierSettings.ExcludeTargets("pdf");
238+
}
239+
```
240+
<sup><a href='/src/ModuleInitDocs/ExcludeTargets.cs#L3-L12' title='Snippet source file'>snippet source</a> | <a href='#snippet-StaticExcludeTargets' title='Start of snippet'>anchor</a></sup>
241+
<!-- endSnippet -->
242+
243+
Excluding every target of a verification is an error, since a verification requires at least one target.
244+
245+
209246
## Shipping
210247

211248
Converters can be shipped as NuGet packages:

docs/mdsource/converter.source.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ If cleanup needs to occur after verification a callback can be passes to `Conver
7070
snippet: ConversionResultWithCleanup
7171

7272

73+
## Excluding targets
74+
75+
Some converters emit the source document (for example a `pdf`, `docx`, or `xlsx`) alongside the info file and the derived targets. That source document is then committed as a `.verified.{extension}` file. Where the document is large, or where its bytes cannot be made deterministic, it can be excluded from the snapshot. The info file and the derived targets continue to verify.
76+
77+
`ExcludeTargets` takes one or more extensions, and drops every matching target:
78+
79+
snippet: ExcludeTargets
80+
81+
Any existing verified file for an excluded extension is then reported as pending deletion.
82+
83+
To exclude an extension for every test, call `ExcludeTargets` on `VerifierSettings` at initialization:
84+
85+
snippet: StaticExcludeTargets
86+
87+
Excluding every target of a verification is an error, since a verification requires at least one target.
88+
89+
7390
## Shipping
7491

7592
Converters can be shipped as NuGet packages:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
public class ExcludeTargets
2+
{
3+
#region StaticExcludeTargets
4+
5+
public static class ModuleInitializer
6+
{
7+
[ModuleInitializer]
8+
public static void Init() =>
9+
VerifierSettings.ExcludeTargets("pdf");
10+
}
11+
12+
#endregion
13+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
null
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class ExcludeTargetsTests :
2+
BaseTest
3+
{
4+
[Fact]
5+
public async Task GlobalExclusionAppliesToAllVerifications()
6+
{
7+
VerifierSettings.ExcludeTargets("excludedbin");
8+
Target[] targets = [new("excludedbin", new MemoryStream("binary-content"u8.ToArray()))];
9+
var result = await Verify(null, targets)
10+
.DisableDiff();
11+
Assert.Single(result.Files);
12+
}
13+
14+
[Fact]
15+
public void AfterVerifyHasBeenRunThrows()
16+
{
17+
InnerVerifier.verifyHasBeenRun = true;
18+
Assert.Throws<Exception>(() => VerifierSettings.ExcludeTargets("excludedbin"));
19+
}
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
derived from source
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
the info
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
null
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
null
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
null

0 commit comments

Comments
 (0)