neo-go
neo-go copied to clipboard
Support coverage in neotest
It would be nice to check that contract tests cover all possible branches.
So basically there are 2 parts:
- Execute VM, while tracking executed opcodes and mapping them to the source code lines using
DebugInfo
. It has a lot of runtime overhead, but we can have a separate package which contains all the logic and use it only with certain test flags. - Create custom coverage file.
As a nice consequence, we can use this to check for the presence of dead-code which can be used to optimize the compiler itself.
The most difficult part of this is to figure out clean interface without a lot of overhead.
Another difficulty (optional feature) is to have nice green lines displayed by GoLand, so far this was my biggest issue.
Yeah, that'd be really cool, but I think it can only be done properly at the VM level and it won't be trivial.
The thing I had in mind is to leave VM as it is: make custom Execute
which executes code step-by-step and updates seen opcodes/lines. The vm.Run
is rather simple so it can be copied with minimum changes.
We have POC written by @fyrchik in https://github.com/nspcc-dev/neo-go/tree/neotest-coverage, so let's keep this branch linked for now.