Subunit Rust
This repo contains a implementation of the subunit protocol in Rust. It provides an interface for both writing and reading subunit streams natively in rust. The rust 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 parse_subunit() function is used to first buffer the entire stream in memory, and then parse the contents and return a vector of Event structs. For example, parsing a subunit stream from a file:
let mut f = open?;
let events = parse_subunit.unwrap;
In this example, the results.subunit
file will be opened and parsed with an
Event struct in the events vector for each subunit packet in the file.
Writing subunit packets
Writing a subunit packet first requires creating an event structure to describe the contents of the packet. For example:
let mut event_start = Event ;
A typical test event normally involves 2 packets though, one to mark the start and the other to mark the finish of a test:
let mut event_end = Event ;
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:
let mut subunit_stream: = Vec new;
subunit_stream = event_start.write?;
subunit_stream = event_end.write?;
With this the subunit_stream buffer will contain the contents of the subunit stream for that test event.