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