From e5809363de3c00cc9234b2ed5ab88287c9f05d4d Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 13 Apr 2022 14:55:26 +0300 Subject: [PATCH] docs: describe the contents of vlib/v/gen/c/testdata/ and how to write tests for the checker, that still do not have good codegen counterpart --- vlib/v/gen/c/testdata/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 vlib/v/gen/c/testdata/README.md diff --git a/vlib/v/gen/c/testdata/README.md b/vlib/v/gen/c/testdata/README.md new file mode 100644 index 0000000000..6cff11b48b --- /dev/null +++ b/vlib/v/gen/c/testdata/README.md @@ -0,0 +1,22 @@ +## Purpose: tests data for the output of V's C code generator + +## TLDR: `v vlib/v/gen/c/coutput_test.v` + +coutput_test.v is a *test runner*, that checks whether the generated C +source code matches *all* expectations, specified in *.c.must_have files, +in the folder vlib/v/gen/c/testdata/ . + +Each `.c.must_have` file, *has* to have a corresponding `.vv` file. + +Each `.c.must_have` file, consists of multiple lines. Each of these +lines, *should* be present *at least once* in the output, when the .vv +file is compiled with `-o -` . + +Note: this test runner can also be used to verify and keep from regressing +*partial fixes* to V's checker, i.e. ones that make a program type check fine, +but that still lead to codegen problems. To do that, put the V code that the +checker can typecheck in a `.vv` file in this folder, then create a +corresponding `.c.must_have` file in this folder too. It should have a single +line in it: `// THE END.` . The V codegen will end every source that it +generates with that line, so its presence, effectively guarantees that cgen +succeeded/ended, even if the produced C code can not be compiled yet.