January 2018
Beginner to intermediate
454 pages
10h 8m
English
In the Rust test framework, there's no setup() and teardown() functions like there are in the test frameworks of many other languages. And here, we need to run some code when the test is done: we need to kill our FTP server. So, we need some kind of teardown function. We cannot simply say child.kill() at the end of the function because, if the test panics before that, the FTP server will continue running after the test ends. To make sure the cleanup code is always called, no matter how the function ended, we'll have to use the RAII pattern that we discovered in Chapter 6, Implementing the Engine of the Music Player.
Let's write a simple teardown structure:
struct ProcessController {
child: Child,
}
The structure contains the child ...
Read now
Unlock full access