Incorpora y revisa código para pruebas unitarias

This commit is contained in:
Manuel Cillero 2024-12-05 14:32:10 +01:00
parent 7bf89ca90d
commit c5b0c529ef
9 changed files with 31 additions and 14 deletions

View file

@ -17,7 +17,7 @@ use syn::{parse_macro_input, parse_str, DeriveInput, ItemFn};
/// ///
/// # Ejemplos /// # Ejemplos
/// ///
/// ``` /// ```rust#ignore
/// #[fn_builder] /// #[fn_builder]
/// pub fn set_example(&mut self) -> &mut Self { /// pub fn set_example(&mut self) -> &mut Self {
/// // implementación /// // implementación
@ -26,7 +26,7 @@ use syn::{parse_macro_input, parse_str, DeriveInput, ItemFn};
/// ///
/// Añadirá al código el siguiente método: /// Añadirá al código el siguiente método:
/// ///
/// ``` /// ```rust#ignore
/// #[inline] /// #[inline]
/// pub fn with_example(mut self) -> Self { /// pub fn with_example(mut self) -> Self {
/// self.set_example(); /// self.set_example();
@ -159,7 +159,7 @@ pub fn derive_component_classes(input: TokenStream) -> TokenStream {
/// ///
/// # Ejemplos /// # Ejemplos
/// ///
/// ``` /// ```rust#ignore
/// #[pagetop::main] /// #[pagetop::main]
/// async fn main() { /// async fn main() {
/// async { println!("Hello world!"); }.await /// async { println!("Hello world!"); }.await
@ -180,7 +180,7 @@ pub fn main(_: TokenStream, item: TokenStream) -> TokenStream {
/// ///
/// # Ejemplos /// # Ejemplos
/// ///
/// ``` /// ```rust#ignore
/// #[pagetop::test] /// #[pagetop::test]
/// async fn test() { /// async fn test() {
/// assert_eq!(async { "Hello world" }.await, "Hello world"); /// assert_eq!(async { "Hello world" }.await, "Hello world");

View file

@ -57,7 +57,7 @@
//! Then, use the [`include_config!`](crate::include_config) macro to initialize your settings with //! Then, use the [`include_config!`](crate::include_config) macro to initialize your settings with
//! type-safe structures and predefined values: //! type-safe structures and predefined values:
//! //!
//! ``` //! ```rust#ignore
//! use pagetop::prelude::*; //! use pagetop::prelude::*;
//! use serde::Deserialize; //! use serde::Deserialize;
//! //!
@ -101,7 +101,7 @@
//! //!
//! Access the settings directly in your code: //! Access the settings directly in your code:
//! //!
//! ``` //! ```rust#ignore
//! use pagetop::prelude::*; //! use pagetop::prelude::*;
//! use crate::config; //! use crate::config;
//! //!

View file

@ -34,7 +34,7 @@ mod escape;
/// ///
/// # Example /// # Example
/// ///
/// ```rust /// ```rust#ignore
/// use maud::Escaper; /// use maud::Escaper;
/// use std::fmt::Write; /// use std::fmt::Write;
/// let mut s = String::new(); /// let mut s = String::new();
@ -72,7 +72,7 @@ impl<'a> fmt::Write for Escaper<'a> {
/// ///
/// # Example /// # Example
/// ///
/// ```rust /// ```rust#ignore
/// use maud::{html, Markup, Render}; /// use maud::{html, Markup, Render};
/// ///
/// /// Provides a shorthand for linking to a CSS stylesheet. /// /// Provides a shorthand for linking to a CSS stylesheet.
@ -188,7 +188,7 @@ impl_render_with_itoa! {
/// ///
/// # Example /// # Example
/// ///
/// ```rust /// ```rust#ignore
/// use maud::html; /// use maud::html;
/// use std::net::Ipv4Addr; /// use std::net::Ipv4Addr;
/// ///
@ -259,7 +259,7 @@ impl<T: AsRef<str> + Default> Default for PreEscaped<T> {
/// ///
/// A minimal web page: /// A minimal web page:
/// ///
/// ```rust /// ```rust#ignore
/// use maud::{DOCTYPE, html}; /// use maud::{DOCTYPE, html};
/// ///
/// let markup = html! { /// let markup = html! {

View file

@ -29,7 +29,7 @@
//! //!
//! # ⚡️ Quick start //! # ⚡️ Quick start
//! //!
//! ```rust //! ```rust#ignore
//! use pagetop::prelude::*; //! use pagetop::prelude::*;
//! //!
//! struct HelloWorld; //! struct HelloWorld;

View file

@ -70,7 +70,7 @@
//! [`include_locales!`](crate::include_locales) macro to integrate them into your module or //! [`include_locales!`](crate::include_locales) macro to integrate them into your module or
//! application. If your resources are located in the `"src/locale"` directory, simply declare: //! application. If your resources are located in the `"src/locale"` directory, simply declare:
//! //!
//! ``` //! ```rust#ignore
//! use pagetop::prelude::*; //! use pagetop::prelude::*;
//! //!
//! include_locales!(LOCALES_SAMPLE); //! include_locales!(LOCALES_SAMPLE);
@ -78,7 +78,7 @@
//! //!
//! But if they are in another directory, then you can use: //! But if they are in another directory, then you can use:
//! //!
//! ``` //! ```rust#ignore
//! use pagetop::prelude::*; //! use pagetop::prelude::*;
//! //!
//! include_locales!(LOCALES_SAMPLE from "path/to/locale"); //! include_locales!(LOCALES_SAMPLE from "path/to/locale");

View file

@ -103,7 +103,7 @@ impl TypeInfo {
/// ///
/// # Examples /// # Examples
/// ///
/// ``` /// ```rust#ignore
/// let root = "/home/user"; /// let root = "/home/user";
/// let relative = "documents"; /// let relative = "documents";
/// let abs_dir = absolute_dir(root, relative).unwrap(); /// let abs_dir = absolute_dir(root, relative).unwrap();

2
tests/main.rs Normal file
View file

@ -0,0 +1,2 @@
#[cfg(test)]
mod server;

View file

@ -0,0 +1,14 @@
use pagetop::prelude::*;
struct HealthCheck;
impl PackageTrait for HealthCheck {}
#[pagetop::test]
async fn health_check_works() {
let app = service::test::init_service(Application::prepare(&HealthCheck).test()).await;
let req = service::test::TestRequest::get().uri("/").to_request();
let _resp = service::test::call_service(&app, req).await;
// assert_eq!("OK", "OK");
}

1
tests/server/mod.rs Normal file
View file

@ -0,0 +1 @@
mod health_check;