[enhancement] Add the ability to generate test stubs for procs
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
### What's hard to do? (limit 100 words)
Many tests for procs are repetitive. They involve creating channels that match the ones used by the tested proc, spawning the proc with one end of each channel, and keeping the other ends for use in the test body. Writing this setup by hand is a repetitive task that can lead to mistakes. Automating this process could make working with DSLX code easier.
### Current best alternative workaround (limit 100 words)
You can copy-paste test code from other files, use your text editor macros, or write your own scripts to generate the boilerplate code.
### Your view of the "best case XLS enhancement" (limit 100 words)
Setting up a test for a proc often follows a simple and repeated pattern, so it is a good candidate for automation. Right now, users have to write this code manually. The DSLX LSP could include a custom code action that generates a test stub for any given proc. The stub could include the basic setup, such as creating and wiring channels, spawning the proc, and sending a final signal to a terminate channel. This would save time, reduce boilerplate, and help prevent mistakes:
```rust
proc MyProc {
// ...
config(
req_r: chan in,
resp_s: chan out
) {
(req_r, resp_s)
}
}
#[test_proc]
proc MyTestProc {
terminator: chan out;
req_s: chan out;
resp_r: chan in;
config(terminator: chan out) {
let (req_s, req_r) = chan("req");
let (resp_s, resp_r) = chan("resp");
spawn MyProc(req_r, resp_s);
(terminator, req_s, resp_r)
}
init { }
next(state: ()) {
let tok = join();
// Your test body should go here..
send(tok, terminator, true);
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.