Subunit Rust
This repo contains a implementation of the subunit v2 protocol in Rust. It provides an interface for both writing and reading subunit streams natively in rust. The subunit v2 protocol is documented in the testing-cabal/subunit repository.
Reading subunit packets
Reading subunit packets first requires an object implementing the Read trait containing the subunit stream. The iter_stream() function is used to parse the contents and return an iterator of ScannedItem enums. For example, parsing a subunit stream from a file:
use File;
use iter_stream;
use ScannedItem;
let f = open?;
for item in iter_stream
# Ok::
In this example, the results.subunit file will be opened and parsed with a
ScannedItem for each packet in the file.
Writing subunit packets
Writing a subunit packet first requires creating an event structure to describe the contents of the packet. The Event API uses a builder pattern for construction. For example:
use ;
use ;
let event_start = new
.test_id
.datetime?
.tag
.tag
.build;
# Ok::
A typical test event normally involves 2 packets though, one to mark the start and the other to mark the finish of a test:
use ;
use ;
let event_end = new
.test_id
.datetime?
.tag
.tag
.mime_type
.file_content
.build;
# Ok::
Then you'll want to write the packet out to something. Anything that implements the std::io::Write trait can be used for the packets, including things like a File and a TCPStream. In this case we'll use Vec to keep it in memory:
use Serializable;
use ;
use ;
let mut subunit_stream: = Vecnew;
let event_start = new
.test_id
.datetime?
.tag
.tag
.build;
let event_end = new
.test_id
.datetime?
.tag
.tag
.mime_type
.file_content
.build;
event_start.serialize?;
event_end.serialize?;
# Ok::
With this the subunit_stream buffer will contain the contents of the subunit stream for that test event.