PLC-lang / rusty

Structured Text Parser and LLVM Frontend
GNU Lesser General Public License v3.0
191 stars 52 forks source link

Snapshot testing for resolver tests #1002

Open volsa opened 8 months ago

volsa commented 8 months ago

Is your refactor request related to a problem? Please describe. I think our resolver unit tests could benefit from snapshot testing, as writing them currently is a bit tedious imo. This is somewhat related to https://github.com/PLC-lang/rusty/issues/1001.

Describe the solution you'd like Introduce a function similar to parse_and_validate_buffered but for annotations.

riederm commented 8 months ago

What would be a nice way of writing these tests? For me the hard part is, to get a hold of the AST-Elements that you want to check :/

so like unpacking ´b´ in the example below is tidious

foo(a := b); 
volsa commented 8 months ago

I was thinking of integrating this closely with https://github.com/PLC-lang/rusty/issues/1001, so some function that generates the following output?

`foo(a := b)` => Function { ... }                   @ ReferenceExpr { kind: Member(...), parameters: ..., ... }
`foo(a := b)` => Value { "DINT" }                   @ CallStatement
`foo`         => Function { ... }                   @ Identifier
`a`           => Variable { "DINT", "foo.a",  ... } @ ReferenceExpr { ... }
`b`           => Variable { "DINT", "main.b", ... } @ ReferenceExpr ( ... }

I'm not sure if this is the best way to go, since this will basically yield all elements in the type_map and type_map_hint within the snapshot but it would make writing these tests easier in the future at the cost of maybe bloated up snapshots? Maybe because in theory most resolver tests should not have a lot of elements in these type_map(_hint) members since they're kept small? This probably needs more discussion in the team if we really want and/or need this.