[][src]Crate tcp_test

Programmatically test TCP programs using real TCP streams.

Example

Everything can be done using the channel() function:

use tcp_test::{channel, read_assert};
use std::io::{Read, Write};

#[test]
fn first_test() {
    let sent = b"Hello, reader";

    let (mut reader, mut writer) = channel();

    writer.write_all(sent).unwrap();

    let mut read = Vec::new();
    reader.read_to_end(&mut read).unwrap();

    assert_eq!(read, sent);
}

#[test]
fn second_test() {
    let sent = b"Interesting story";

    let (mut reader, mut writer) = channel();

    writer.write_all(sent).unwrap();

    read_assert!(reader, sent.len(), sent);
}

#[test]
fn third_test() {
    let sent = b"...";

    let (mut reader, mut writer) = channel();

    writer.write_all(sent).unwrap();

    read_assert!(reader, sent.len(), sent);
}

Features

By default, a panic in one of the internal threads causes all tests to exit, because in most cases the tests will just block indefinitely. The only_panic feature prevents this behaviour if enabled.

Macros

read_assert

Convenience macro for reading and comparing a specific amount of bytes.

Functions

channel

Returns two TCP streams pointing at each other.

channel_on

Returns two TCP streams pointing at each other.