diff --git a/Cargo.lock b/Cargo.lock index 866d3f80..6c2a08ed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,12 +75,6 @@ version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - [[package]] name = "percent-encoding" version = "2.3.1" @@ -185,7 +179,6 @@ dependencies = [ "hoot", "http", "log", - "once_cell", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index d3de5576..b39adc88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,5 +27,4 @@ features = [] hoot = { git = "https://github.com/algesten/hoot", rev = "2e2eac5" } http = "1.1.0" log = "0.4.22" -once_cell = "1.19.0" thiserror = "1.0.61" diff --git a/src/lib.rs b/src/lib.rs index bb33218f..08051bb2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,14 +3,12 @@ // #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] use std::convert::TryFrom; -use std::sync::atomic::{AtomicBool, Ordering}; use body::AsBody; /// Re-exported http-crate. pub use http; use http::{Method, Request, Response, Uri}; -use once_cell::sync::Lazy; use recv::RecvBody; use request::RequestBuilder; @@ -61,18 +59,12 @@ where builder(Method::POST, uri) } -// is_test returns false so long as it has only ever been called with false. -// If it has ever been called with true, it will always return true after that. -// This is a public but hidden function used to allow doctests to use the test_agent. -// Note that we use this approach for doctests rather the #[cfg(test)], because -// doctests are run against a copy of the crate build without cfg(test) set. -// We also can't use #[cfg(doctest)] to do this, because cfg(doctest) is only set -// when collecting doctests, not when building the crate. -#[doc(hidden)] -pub fn is_test(is: bool) -> bool { - static IS_TEST: Lazy = Lazy::new(|| AtomicBool::new(false)); - if is { - IS_TEST.store(true, Ordering::SeqCst); +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn simple_get() { + get("https://httpbin.org/get").call().unwrap(); } - IS_TEST.load(Ordering::SeqCst) } diff --git a/src/request.rs b/src/request.rs index 09a4140d..30ec8cff 100644 --- a/src/request.rs +++ b/src/request.rs @@ -30,14 +30,11 @@ impl RequestBuilder { /// # Examples /// /// ``` - /// # fn main() -> Result<(), ureq::Error> { - /// # ureq::is_test(true); /// let res = ureq::get("https://host.test/my-path") /// .header("Accept", "text/html") /// .header("X-Custom-Foo", "bar") /// .call()?; - /// # Ok(()) - /// # } + /// # Ok::<_, ureq::Error>(()) /// ``` pub fn header(mut self, key: K, value: V) -> RequestBuilder where @@ -56,12 +53,9 @@ impl RequestBuilder { /// Content-Length nor Transfer-Encoding. /// /// ``` - /// # fn main() -> Result<(), ureq::Error> { - /// # ureq::is_test(true); /// let resp = ureq::get("http://httpbin.org/get") /// .call()?; - /// # Ok(()) - /// # } + /// # Ok::<_, ureq::Error>(()) /// ``` pub fn call(self) -> Result, Error> { let request = self.builder.body(()).unwrap(); @@ -73,12 +67,9 @@ impl RequestBuilder { /// The `Content-Length` header is implicitly set to the length of the serialized value. /// /// ``` - /// # fn main() -> Result<(), ureq::Error> { - /// # ureq::is_test(true); /// let resp = ureq::post("http://httpbin.org/put") /// .send_bytes(&[0; 1000])?; - /// # Ok(()) - /// # } + /// # Ok::<_, ureq::Error>(()) /// ``` pub fn send_bytes(self, data: &[u8]) -> Result, Error> { let request = self.builder.body(()).unwrap();