Skip to content
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
4 changes: 2 additions & 2 deletions standard/basic-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ The behavior of the garbage collector can be controlled, to some degree, via sta

> *Example*: Since the garbage collector is allowed wide latitude in deciding when to collect objects and run finalizers, a conforming implementation might produce output that differs from that shown by the following code. The program
>
> <!-- ImplementationDefined$Example: {template:"standalone-console",name:"MemoryManagement1", expectedOutput:["xx"]} -->
> <!-- Example: {template:"standalone-console",name:"MemoryManagement1", ignoreOutput:true} -->
> <!-- Maintenance Note: The behavior of this example is implementation-defined. As such, the metadata does *not* compare test output with any ```console block. -->
> ```csharp
> class A
Expand Down Expand Up @@ -1023,7 +1023,7 @@ The behavior of the garbage collector can be controlled, to some degree, via sta
>
> In subtle cases, the distinction between “eligible for finalization” and “eligible for collection” can be important. For example,
>
> <!-- ImplementationDefined$Example: {template:"standalone-console",name:"MemoryManagement2", expectedOutput:["xx"]} -->
> <!-- Example: {template:"standalone-console",name:"MemoryManagement2", ignoreOutput:true} -->
> <!-- Maintenance Note: The behavior of this example is implementation-defined. As such, the metadata does *not* compare test output with any ```console block. -->
> ```csharp
> class A
Expand Down
10 changes: 9 additions & 1 deletion tools/ExampleExtractor/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,19 @@ private static IEnumerable<Example> LoadExamplesFromFile(string markdownFile)
metadata.EndLine = closingLine;
metadata.MarkdownFile = Path.GetFileName(markdownFile);

if (metadata.IgnoreOutput)
{
if (metadata.InferOutput || metadata.ExpectedOutput is not null)
{
throw new InvalidOperationException($"Example {metadata.Name} has both {nameof(metadata.IgnoreOutput)} and either {nameof(metadata.InferOutput)} or {nameof(metadata.ExpectedOutput)}");
}
}

if (metadata.InferOutput)
{
if (metadata.ExpectedOutput is not null)
{
throw new InvalidOperationException($"Example {metadata.Name} has both ${nameof(metadata.InferOutput)} and {nameof(metadata.ExpectedOutput)}");
throw new InvalidOperationException($"Example {metadata.Name} has both {nameof(metadata.InferOutput)} and {nameof(metadata.ExpectedOutput)}");
}
int openingConsoleLine = FindLineEnding(closingLine + 1, "```console");
// We expect the output to appear very shortly after the example.
Expand Down
8 changes: 8 additions & 0 deletions tools/ExampleExtractor/ExampleMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public class ExampleMetadata
[JsonProperty("inferOutput")]
public bool InferOutput { get; set; }

/// <summary>
/// If this is set, ExpectedOutput must be null and InferOutput must be false.
/// The actual output is then ignored by the test runner.
/// This option should be used when output is nondeterministic.
/// </summary>
[JsonProperty("ignoreOutput")]
public bool IgnoreOutput { get; set; }

[JsonProperty("expectedException")]
public string ExpectedException { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion tools/ExampleTester/GeneratedExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ bool ValidateOutput()
}
var expectedLines = Metadata.ExpectedOutput ?? new List<string>();
return ValidateException(actualException, Metadata.ExpectedException) &&
ValidateExpectedAgainstActual("output", expectedLines, actualLines);
(Metadata.IgnoreOutput || ValidateExpectedAgainstActual("output", expectedLines, actualLines));
}

bool ValidateException(Exception? actualException, string? expectedExceptionName)
Expand Down