#1117·warp

Example tests do not pass

Author: guspowerCreated Apr 6, 2025Updated Apr 6, 2025
Labelsbug

Version └── warp v0.3.7

Platform Linux dev01 6.12.16-gentoo #3 SMP PREEMPT_DYNAMIC Wed Mar 26 17:04:45 GMT 2025 x86_64 AMD Ryzen 3 5300U with Radeon Graphics AuthenticAMD GNU/Linu

Description The tests shown for the test module (test_sum and test_math) in the crate docs do not succeed.

I tried this code:

#[test]
fn test_math() {
    let filter = math();

    let res = warp::test::request()
        .path("/1/2")
        .reply(&filter);
    assert_eq!(res.status(), 405, "GET is not allowed");

    let res = warp::test::request()
        .method("POST")
        .path("/1/2")
        .reply(&filter);
    assert_eq!(res.status(), 200);
    assert_eq!(res.body(), "Sum is 3");
}

I expected to see this happen: a test pass

Instead, this happened: a test failure

I updated the test like so:

    #[tokio::test] // made test async
    async fn test_math() {
        let filter = math();

        let res = warp::test::request().path("/1/2").reply(&filter).await; // added await
        assert_eq!(res.status(), 405, "GET is not allowed");

        let res = warp::test::request()
            .method("POST")
            .path("/1/2")
            .reply(&filter)
            .await;
        assert_eq!(res.status(), 200);
        assert_eq!(res.body(), "Sum is 3"); // changed assertion from "Sum = 3"
    }

Similarly test_sum fails on this assertion: assert!(warp::test::request().path("/1/-5").matches(&filter).await);

It seems that it does not succeed with the negative number (-5).