GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — csharp/docs/GENERATORS.md at main · exercism/csharp

Expand file tree

/

GENERATORS.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
52 lines (31 loc) · 2.51 KB
/

GENERATORS.md

Copy path

File metadata and controls

52 lines (31 loc) · 2.51 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

Test generators

The C# track uses a test generator to auto-generate practice exercise tests. It uses the fact that most exercises defined in the problem-specifications repo also have a canonical-data.json file, which contains standardized test inputs and outputs that can be used to implement the exercise.

Steps

To generate a practice exercise's tests, the test generator:

  1. Reads the exercise's test cases from its canonical-data.json file
  2. Uses tests.toml file to omit and excluded test cases
  3. Renders the test cases using the exercise's generator template
  4. Format the rendered template using Roslyn
  5. Writes the formatted template to the exercise's test file

Step 1: read canonical-data.json file

The test generator parses the test cases from the exercise's canonical-data.json using the System.Text.Json namespace.

Since some canonical data uses nesting, the parsed test case includes an additional path field that contains the description properties of any parent elements, as well as the test case's own description property.

Step 2: omit excluded tests from tests.toml file

Each exercise has a tests.toml file, in which individual tests can be excluded/disabled. The test generator will remove any test cases that are marked as excluded (include = false).

Step 3: render the test cases

The (potentially transformed) test cases are then passed to the .meta/Generator.tpl file, which defines how the tests should be rendered based on those test cases.

Step 4: format the rendered template using Roslyn

The rendered template is then formatted using Roslyn. This has the following benefits:

  • Exercises are formatted consistently
  • You're not required to worry much about whitespace and alignment when writing templates

Step 5: write the rendered template to the exercise's test file

Finally, the output of the rendered template is written to the exercise's test file.

Templates

The templates are rendered using the Scriban library.

Command-line interface

There are two ways in which the test generator can be run:

  1. bin/update-tests.ps1: update the tests for all exercises that have a generator template
  2. bin/update-tests.ps1 -e <slug>: update the tests for the specified exercise, if it has a generator template
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.