Rust: generate test code from schema docstrings

This generates test source files from code blocks in class docstrings.

By default the test code is generated as is, but it can optionally:
* be wrapped in a function providing an adequate context using
  `@rust.doc_test_function(name, *, lifetimes=(), return_type="()", **kwargs)`,
  with `kwargs` providing both generic and normal params depending on
  capitalization
* be skipped altogether using `@rust.skip_doc_test`

So for example an annotation like
```python
@rust.doc_test_function("foo",
                        lifetimes=("a",),
                        T="Eq",
                        x="&'a T",
                        y="&'a T",
                        return_type="&'a T")
```
will result in the following wrapper:
```rust
fn foo<'a, T: Eq>(x: &'a T, y: &'a T) -> &'a T {
    // example code here
}
```
This commit is contained in:
Paolo Tranquilli
2024-09-06 13:58:49 +02:00
parent 122e5a7598
commit 8c5cc2efdc
19 changed files with 199 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
# configuration file for Swift code generation default options
--generate=dbscheme,ql,rust
--generate=dbscheme,rusttest,ql,rust
--dbscheme=ql/lib/rust.dbscheme
--ql-output=ql/lib/codeql/rust/generated
--ql-stub-output=ql/lib/codeql/rust/elements