From 7d142f1f06bd5311fcafe06c2a7bafe9b22d0db7 Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Fri, 14 Feb 2020 14:41:03 +0600 Subject: [PATCH] Fix the tests --- Cargo.toml | 7 ++++++- src/lib.rs | 50 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7df89eca..9058d79a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,4 +25,9 @@ pin-project = "0.4.6" serde_with_macros = "1.0.1" either = "1.5.3" -teloxide-macros = { path = "teloxide-macros" } \ No newline at end of file +teloxide-macros = { path = "teloxide-macros" } + +[dev-dependencies] +smart-default = "0.6.0" +rand = "0.7.3" +pretty_env_logger = "0.4.0" diff --git a/src/lib.rs b/src/lib.rs index 3783fa01..e78c9abf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,24 +24,24 @@ //! message: //! //! ([Full](https://github.com/teloxide/teloxide/blob/dev/examples/ping_pong_bot/src/main.rs)) -//! ```rust +//! ```rust,no_run //! use teloxide::prelude::*; //! -//! #[tokio::main] -//! async fn main() { -//! teloxide::enable_logging!(); -//! log::info!("Starting the ping-pong bot!"); +//! # #[tokio::main] +//! # async fn main() { +//! teloxide::enable_logging!(); +//! log::info!("Starting the ping-pong bot!"); //! -//! let bot = Bot::from_env(); +//! let bot = Bot::from_env(); //! -//! Dispatcher::::new(bot) -//! .message_handler(&|ctx: DispatcherHandlerCtx| async move { -//! ctx.answer("pong").send().await?; -//! Ok(()) -//! }) -//! .dispatch() -//! .await; -//! } +//! Dispatcher::::new(bot) +//! .message_handler(&|ctx: DispatcherHandlerCtx| async move { +//! ctx.answer("pong").send().await?; +//! Ok(()) +//! }) +//! .dispatch() +//! .await; +//! # } //! ``` //! //! ## Commands @@ -50,7 +50,9 @@ //! [0; 1) on `/generate`, and shows the usage guide on `/help`: //! //! ([Full](https://github.com/teloxide/teloxide/blob/dev/examples/simple_commands_bot/src/main.rs)) -//! ```rust +//! ```rust,no_run +//! # use teloxide::{prelude::*, utils::command::BotCommand}; +//! # use rand::{thread_rng, Rng}; //! // Imports are omitted... //! //! #[derive(BotCommand)] @@ -103,6 +105,15 @@ //! #[tokio::main] //! async fn main() { //! // Setup is omitted... +//! # teloxide::enable_logging!(); +//! # log::info!("Starting simple_commands_bot!"); +//! # +//! # let bot = Bot::from_env(); +//! # +//! # Dispatcher::::new(bot) +//! # .message_handler(&handle_command) +//! # .dispatch() +//! # .await; //! } //! ``` //! @@ -111,7 +122,11 @@ //! You must guess a number from 1 to 10 (inclusively): //! //! ([Full](https://github.com/teloxide/teloxide/blob/dev/examples/guess_a_number_bot/src/main.rs)) -//! ```rust +//! ```rust,no_run +//! # #[macro_use] +//! # extern crate smart_default; +//! # use teloxide::prelude::*; +//! # use rand::{thread_rng, Rng}; //! // Imports are omitted... //! //! #[derive(SmartDefault)] @@ -178,6 +193,9 @@ //! //! #[tokio::main] //! async fn main() { +//! # teloxide::enable_logging!(); +//! # log::info!("Starting guess_a_number_bot!"); +//! # let bot = Bot::from_env(); //! // Setup is omitted... //! //! Dispatcher::new(bot)