Skip to content

Commit 82671a4

Browse files
authored
Revise Example Metadata User Guide (#720)
* Revise user guide * mention limits on looking for console block
1 parent ac1be4d commit 82671a4

File tree

1 file changed

+58
-9
lines changed

1 file changed

+58
-9
lines changed

tools/ExampleExtractor/ExtractorAndTesterUsersGuide.md

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,19 @@ template
8787
: 'template' ':' template_name
8888
;
8989
template_name
90-
: '"standalone-console"' // actually, a JSON_string_value with this content
91-
| '"standalone-lib"' // actually, a JSON_string_value with this content
90+
: '"code-in-class-lib"' // actually, a JSON_string_value with this content
91+
| '"code-in-class-lib-without-using"' // actually, a JSON_string_value with this content
9292
| '"code-in-main"' // actually, a JSON_string_value with this content
93+
| '"code-in-main-without-using"' // actually, a JSON_string_value with this content
94+
| '"standalone-console"' // actually, a JSON_string_value with this content
95+
| '"standalone-console-without-using"' // actually, a JSON_string_value with this content
96+
| '"standalone-lib"' // actually, a JSON_string_value with this content
97+
| '"standalone-lib-without-using"' // actually, a JSON_string_value with this content
9398
;
9499
```
95100

101+
The unsuffixed and suffixed versions are identical, *except* that the unsuffixed ones have using directioves for all namespaces used by examples, while the suffixed ones do not. The unsuffixed versions are used by those few examples that begin with `#undef` or `#define`, which *must* precede using directives, and which might then have explicit using directives.
102+
96103
The template `standalone-console` indicates that the example is an application. For example:
97104

98105
````
@@ -156,6 +163,42 @@ class Program
156163
}
157164
````
158165

166+
The template `code-in-class-lib` indicates that the example needs to be wrapped inside an entry-point method inside a class. For example, the example:
167+
168+
````
169+
> <!-- Example: {template:"code-in-class-lib", ..."} -->
170+
> ```csharp
171+
> public void Log(
172+
> [CallerLineNumber] int line = -1,
173+
> [CallerFilePath] string path = null,
174+
> [CallerMemberName] string name = null
175+
> )
176+
> {
177+
> Console.WriteLine((line < 0) ? "No line" : "Line "+ line);
178+
> Console.WriteLine((path == null) ? "No file path" : path);
179+
> Console.WriteLine((name == null) ? "No member name" : name);
180+
> }
181+
> ```
182+
````
183+
184+
gets transformed into the following library:
185+
186+
````
187+
class Class1
188+
{
189+
public void Log(
190+
[CallerLineNumber] int line = -1,
191+
[CallerFilePath] string path = null,
192+
[CallerMemberName] string name = null
193+
)
194+
{
195+
Console.WriteLine((line < 0) ? "No line" : "Line "+ line);
196+
Console.WriteLine((path == null) ? "No file path" : path);
197+
Console.WriteLine((name == null) ? "No member name" : name);
198+
}
199+
}
200+
````
201+
159202
### Example Names
160203

161204
An annotation’s *name* is the name of the resulting test file directory, **which must be unique across the whole C# spec**. This *annotation_directive* is required. *name* should be a valid C# idenifier.
@@ -426,6 +469,12 @@ Consider the following example:
426469
> ```
427470
````
428471

472+
If no console block begins within the 8 lines following the end of such an example, the following error message results:
473+
474+
````
475+
Example xx has InferOutput set but no ```console block shortly after it.
476+
````
477+
429478
**Scenario #2:**
430479

431480
In those cases in which an example is *not* followed by a console block containing the expected output, the list of expected output-line strings is provided by the *expected_output* annotation directive, so the two sets of text can be compared, verbatim, for equality. This *annotation_directive* is optional. (This directive makes no provision for output written to a file.)
@@ -551,7 +600,7 @@ All templates support compilation of examples containing unsafe code.
551600

552601
### Examples Containing Pseudo-Code
553602

554-
Some examples contain C# grammar-rule names, which show a general format rather than source code that will compile. Such names are fenced using the following notation: `«rule_name»`. These examples do *not* have *example_annotation*s.
603+
Some examples contain C# grammar-rule names, which show a general format rather than source code that will compile. Such names are fenced using the following notation: `«rule_name»`. These examples do not have *example_annotation*s.
555604

556605
Here’s an example:
557606

@@ -608,31 +657,31 @@ Clearly, this code won’t compile, as is. As such, the ExampleExtractor tool re
608657
609658
Here are some things to consider:
610659
611-
Always add an *example_annotation* to a new example that is intended to be tested. If the annotations details are not completely known, use something like the following:
660+
Always add an *example_annotation* to a new example that is intended to be tested. If the annotations details are *not* completely known, use something like the following:
612661
613662
````
614-
<!-- UntestedExample: {template:"x", name:"x", replaceEllipsis:true, expectedOutput:["x", "x"], expectedErrors:["x","x"], expectedWarnings:["x","x"], ignoredWarnings:["x","x"], expectedException:"x"} -->
663+
<!-- Untested$Example: {template:"x", name:"x", replaceEllipsis:true, expectedOutput:["x", "x"], expectedErrors:["x","x"], expectedWarnings:["x","x"], ignoredWarnings:["x","x"], expectedException:"x"} -->
615664
````
616665
617666
That way, a person or tool can easily find untested examples, resolve them, and fill-in the missing information, using something like
618667
619668
````
620-
grep -E '<!-- [A-Za-z]+Example' standard/*.md
669+
grep -E '<!-- [A-Za-z]+$Example' standard/*.md
621670
````
622671
623672
If the runtime behavior is implementation-defined, and the annotation is incomplete, use
624673
625674
````
626-
<!-- ImplementationDefinedExample: { … } -->
675+
<!-- ImplementationDefined$Example: { … } -->
627676
````
628677
629678
If the runtime behavior is undefined, and the annotation is incomplete, use
630679
631680
````
632-
<!-- UndefinedExample: { … } -->
681+
<!-- Undefined$Example: { … } -->
633682
````
634683
635684
If the example involves multiple source files, use
636685
````
637-
<!-- RequiresSeparateFilesExample: { … } -->
686+
<!-- RequiresSeparateFiles$Example: { … } -->
638687
````

0 commit comments

Comments
 (0)