This project provides a flexible framework for generating, translating, and managing compiler test cases across multiple programming languages. It is designed to help you maintain a library of test cases in YAML format and automatically generate language-specific code and metadata for each test.
- YAML-based test management: Write your tests in a simple YAML format, including metadata, code, expected output, and language applicability.
- Language translation: Use alias mappings to translate generic code templates into specific programming languages (C, Go, Zig, etc.).
- Randomization: Supports random integer and letter generation for test placeholders.
- Selective test generation: Only generate tests for the selected language or for tests marked as "All".
- Output organization: Generates code files and a summary YAML for each language/version in a structured output directory.
compiler-tests-generator/
├── data/
│ ├── languages/ # Language alias YAML files (C.yaml, go.yaml, zig.yaml, ...)
│ └── tests/ # Test case YAML files (v1.0.yaml, v2.1.yaml, ...)
├── output/ # Generated code and metadata (created by generate.py)
├── generate.py # Main script to generate code and metadata
├── requirements.txt # Python dependencies
└── README.md
- Clone the repository
- Install dependencies
pip install -r requirements.txt
- Write your test cases in
data/tests/vX.Y.yamlusing the following format:- description: Valid Input code: "..." input: "..." output: | ... exception: false languages: [All] # or [C], [Go], etc.
- Define language-specific aliases in
data/languages/{LANG}.yaml:extension: c aliases: - "&LBRA": "{" - "&RBRA": "}" # ...
Run the generator for a specific version and language:
python generate.py v2.3 C- This will create code files and a
tests.yamlinoutput/C/v2.3/. - Only tests with
languages: [All]orlanguages: [C]will be included.
- For each test, a code file (e.g.,
test001.c) is generated with all aliases replaced. - A
tests.yamlfile is generated with metadata for all included tests.
$in code: replaced by a random integer (1-9)#in code: replaced by a random lowercase letter (except 'l')&NLin code: replaced by a newline (or removed in v2.1+ YAMLs)
- Create a new YAML in
data/languages/(e.g.,Rust.yaml) withextensionandaliases. - Add
Rustas a value in thelanguagesfield of relevant tests. - Run the generator as above.
MIT License