2 releases

0.1.1 Apr 8, 2023
0.1.0 Apr 8, 2023

#19 in #anything

Download history 18/week @ 2024-02-19 17/week @ 2024-02-26 3/week @ 2024-03-04 1/week @ 2024-03-11 7/week @ 2024-03-18 27/week @ 2024-04-01 31/week @ 2024-04-08

60 downloads per month
Used in tap_runner

MIT license

70KB
1.5K SLoC

TAP Parser

This library implements a parser for the Test Anything Protocol.

It implements only the TAP version 14. It should implement all features, including subtests. Pragmas are ignored.

There are two examples in the examples, json outputs the TAP document as json, and parse outputs a debug representation.


lib.rs:

This crate is a parser for the Test Anything Protocol.

It handles all the TAP 14 features, including subtests. The main entrypoint is the [TapParser] structure.

The parser will ignore trailing lines when it is sure it could not be in the TAP document anymore.

Example

use tap_parser::{TapParser, TapStatement, TapPlan, TapTest};

let document = "TAP version 14\n1..1\nok 1 - success\nnot ok 2 - fail";
let mut parser = TapParser::new();
assert_eq!(
    parser.parse(document).unwrap(),
    vec![
        TapStatement::Plan(TapPlan {
            count: 1,
            reason: None
        }),
        TapStatement::TestPoint(TapTest {
            result: true,
            number: Some(1),
            desc: Some("success"),
            directive: None,
            yaml: Vec::new(),
        }),
        TapStatement::TestPoint(TapTest {
            result: false,
            number: Some(2),
            desc: Some("fail"),
            directive: None,
            yaml: Vec::new(),
        }),
    ]
);

Dependencies

~0.3–0.9MB
~21K SLoC