mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 17:52:12 +01:00
Properly gate tests, so that cargo test
works with any features
This commit is contained in:
parent
a84a90e038
commit
7ea428a21c
5 changed files with 50 additions and 25 deletions
|
@ -90,8 +90,8 @@ use crate::{
|
|||
///
|
||||
/// Because of this it's oftentimes more convinient to have a type alias:
|
||||
///
|
||||
/// ```rust
|
||||
/// # async {
|
||||
/// ```rust,no_run
|
||||
/// # #[cfg(feature = "throttle")] {
|
||||
/// # use teloxide_core::{adaptors::{DefaultParseMode, Throttle}, requests::RequesterExt, types::ParseMode};
|
||||
/// type Bot = DefaultParseMode<Throttle<teloxide_core::Bot>>;
|
||||
///
|
||||
|
|
|
@ -137,41 +137,49 @@ required-features = ["sqlite-storage", "cbor-serializer", "bincode-serializer"]
|
|||
|
||||
|
||||
[[example]]
|
||||
name = "dialogue"
|
||||
required-features = ["macros"]
|
||||
name = "admin"
|
||||
required-features = ["macros", "ctrlc_handler"]
|
||||
|
||||
[[example]]
|
||||
name = "buttons"
|
||||
required-features = ["macros", "ctrlc_handler"]
|
||||
|
||||
[[example]]
|
||||
name = "command"
|
||||
required-features = ["macros"]
|
||||
required-features = ["macros", "ctrlc_handler"]
|
||||
|
||||
[[example]]
|
||||
name = "db_remember"
|
||||
required-features = ["sqlite-storage", "redis-storage", "bincode-serializer", "macros"]
|
||||
|
||||
[[example]]
|
||||
name = "inline"
|
||||
required-features = ["macros"]
|
||||
|
||||
[[example]]
|
||||
name = "buttons"
|
||||
required-features = ["macros"]
|
||||
|
||||
[[example]]
|
||||
name = "admin"
|
||||
required-features = ["macros"]
|
||||
name = "dialogue"
|
||||
required-features = ["macros", "ctrlc_handler"]
|
||||
|
||||
[[example]]
|
||||
name = "dispatching_features"
|
||||
required-features = ["macros"]
|
||||
|
||||
[[example]]
|
||||
name = "ngrok_ping_pong"
|
||||
required-features = ["webhooks-axum"]
|
||||
required-features = ["macros", "ctrlc_handler"]
|
||||
|
||||
[[example]]
|
||||
name = "heroku_ping_pong"
|
||||
required-features = ["webhooks-axum"]
|
||||
required-features = ["webhooks-axum", "ctrlc_handler"]
|
||||
|
||||
[[example]]
|
||||
name = "inline"
|
||||
required-features = ["macros", "ctrlc_handler"]
|
||||
|
||||
[[example]]
|
||||
name = "ngrok_ping_pong"
|
||||
required-features = ["webhooks-axum", "ctrlc_handler"]
|
||||
|
||||
[[example]]
|
||||
name = "purchase"
|
||||
required-features = ["macros"]
|
||||
required-features = ["macros", "ctrlc_handler"]
|
||||
|
||||
[[example]]
|
||||
name = "shared_state"
|
||||
required-features = ["ctrlc_handler"]
|
||||
|
||||
[[example]]
|
||||
name = "throw_dice"
|
||||
required-features = ["ctrlc_handler"]
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
//! `/start` or `/help`:
|
||||
//!
|
||||
//! ```no_run
|
||||
//! # #[cfg(feature = "macros")] {
|
||||
//! # use teloxide::utils::command::BotCommands;
|
||||
//! #[derive(BotCommands, Clone)]
|
||||
//! #[command(rename_rule = "lowercase", description = "These commands are supported:")]
|
||||
|
@ -34,6 +35,7 @@
|
|||
//! #[command(description = "cancel the purchase procedure.")]
|
||||
//! Cancel,
|
||||
//! }
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! Now the key question: how to elegantly dispatch on different combinations of
|
||||
|
@ -43,6 +45,7 @@
|
|||
//! solution is to use [`dptree`]:
|
||||
//!
|
||||
//! ```no_run
|
||||
//! # #[cfg(feature = "macros")] {
|
||||
//! # // That's a lot of context needed to compile this, oof
|
||||
//! # use teloxide::dispatching::{UpdateHandler, UpdateFilterExt, dialogue, dialogue::InMemStorage};
|
||||
//! # use teloxide::utils::command::BotCommands;
|
||||
|
@ -81,6 +84,7 @@
|
|||
//! .branch(message_handler)
|
||||
//! .branch(callback_query_handler)
|
||||
//! }
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! The overall logic should be clear. Throughout the above example, we use
|
||||
|
@ -149,6 +153,7 @@
|
|||
//! Inside `main`, we plug the schema into [`Dispatcher`] like this:
|
||||
//!
|
||||
//! ```no_run
|
||||
//! # #[cfg(feature = "ctrlc_handler")] {
|
||||
//! # use teloxide::Bot;
|
||||
//! # use teloxide::requests::RequesterExt;
|
||||
//! # use teloxide::dispatching::{Dispatcher, dialogue::InMemStorage};
|
||||
|
@ -165,6 +170,7 @@
|
|||
//! .dispatch()
|
||||
//! .await;
|
||||
//! }
|
||||
//! # }
|
||||
//! ```
|
||||
//!
|
||||
//! In a call to [`DispatcherBuilder::dependencies`], we specify a list of
|
||||
|
|
|
@ -77,14 +77,15 @@ impl EventKind for Kind {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[cfg(feature = "macros")]
|
||||
use crate::{
|
||||
self as teloxide, // fixup for the `BotCommands` macro
|
||||
dispatching::{HandlerExt, UpdateFilterExt},
|
||||
types::{AllowedUpdate::*, Update},
|
||||
utils::command::BotCommands,
|
||||
};
|
||||
|
||||
use crate as teloxide; // fixup for the `BotCommands` macro
|
||||
|
||||
#[cfg(feature = "macros")]
|
||||
#[derive(BotCommands, Clone)]
|
||||
#[command(rename_rule = "lowercase")]
|
||||
enum Cmd {
|
||||
|
@ -93,6 +94,7 @@ mod tests {
|
|||
|
||||
// <https://github.com/teloxide/teloxide/discussions/648>
|
||||
#[test]
|
||||
#[cfg(feature = "macros")]
|
||||
fn discussion_648() {
|
||||
let h =
|
||||
dptree::entry().branch(Update::filter_my_chat_member().endpoint(|| async {})).branch(
|
||||
|
@ -108,4 +110,11 @@ mod tests {
|
|||
|
||||
assert_eq!(v, [Message, MyChatMember])
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "this test requires `macros` feature"]
|
||||
#[cfg(not(feature = "macros"))]
|
||||
fn discussion_648() {
|
||||
panic!("this test requires `macros` feature")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,10 @@
|
|||
//!
|
||||
//! [[`examples/throw_dice.rs`](https://github.com/teloxide/teloxide/blob/master/examples/throw_dice.rs)]
|
||||
//! ```no_run
|
||||
//! # #[cfg(feature = "ctrlc_handler")]
|
||||
//! use teloxide::prelude::*;
|
||||
//!
|
||||
//! # #[cfg(feature = "ctrlc_handler")]
|
||||
//! # #[tokio::main]
|
||||
//! # async fn main() {
|
||||
//! pretty_env_logger::init();
|
||||
|
@ -20,7 +22,7 @@
|
|||
//! Ok(())
|
||||
//! })
|
||||
//! .await;
|
||||
//! # }
|
||||
//! # } #[cfg(not(feature = "ctrlc_handler"))] fn main(){}
|
||||
//! ```
|
||||
//!
|
||||
//! <div align="center">
|
||||
|
|
Loading…
Reference in a new issue