From 7991cef904977cd1351ef06f4441717249807438 Mon Sep 17 00:00:00 2001 From: xmppftw Date: Wed, 18 Dec 2024 17:59:06 +0100 Subject: [PATCH] Add tests for crate exports ; add structure to imports/exports --- jid/src/lib.rs | 4 ++-- parsers/src/lib.rs | 19 ++++++++++++++++ tokio-xmpp/Cargo.toml | 1 - tokio-xmpp/examples/echo_server.rs | 9 +++++--- tokio-xmpp/src/error.rs | 20 ++++++++--------- tokio-xmpp/src/lib.rs | 36 ++++++++++++++++++------------ xmpp/src/lib.rs | 20 +++++++++++++++-- 7 files changed, 77 insertions(+), 32 deletions(-) diff --git a/jid/src/lib.rs b/jid/src/lib.rs index 6128196d11636c82ec736812d2d69d40483c09a9..be6657f7199e0236cf4d46f5cfb01ccbfdb163e2 100644 --- a/jid/src/lib.rs +++ b/jid/src/lib.rs @@ -65,9 +65,9 @@ use quote::{quote, ToTokens}; use minidom::{IntoAttributeValue, Node}; mod error; -pub use crate::error::Error; - mod parts; + +pub use crate::error::Error; pub use parts::{DomainPart, DomainRef, NodePart, NodeRef, ResourcePart, ResourceRef}; fn length_check(len: usize, error_empty: Error, error_too_long: Error) -> Result<(), Error> { diff --git a/parsers/src/lib.rs b/parsers/src/lib.rs index 56864d9e757acfca833dc9d76836d65759f25eac..f319cdcd63dd0a693ce2c814fcca699af920a058 100644 --- a/parsers/src/lib.rs +++ b/parsers/src/lib.rs @@ -293,3 +293,22 @@ pub mod fast; /// XEP-0490: Message Displayed Synchronization pub mod message_displayed; + +#[cfg(test)] +mod tests { + #[test] + fn reexports() { + #[allow(unused_imports)] + use crate::blake2; + #[allow(unused_imports)] + use crate::jid; + #[allow(unused_imports)] + use crate::minidom; + #[allow(unused_imports)] + use crate::sha1; + #[allow(unused_imports)] + use crate::sha2; + #[allow(unused_imports)] + use crate::sha3; + } +} diff --git a/tokio-xmpp/Cargo.toml b/tokio-xmpp/Cargo.toml index 31cf17bcbff865a719785731a54ef6c15d54e6e2..cc1c8e1d768033f414fe85ef59e75eb4649c894f 100644 --- a/tokio-xmpp/Cargo.toml +++ b/tokio-xmpp/Cargo.toml @@ -26,7 +26,6 @@ pin-project-lite = { version = "0.2" } # same repository dependencies sasl = { version = "0.5", path = "../sasl" } xmpp-parsers = { version = "0.21", path = "../parsers" } -minidom = { version = "0.16", path = "../minidom" } xso = { version = "0.1", path = "../xso" } # these are only needed for starttls ServerConnector support diff --git a/tokio-xmpp/examples/echo_server.rs b/tokio-xmpp/examples/echo_server.rs index 6cbb75cd43ac678d58640f3b81b3a8e9850bfd2f..e779ab203dfaa31fd7665eec1df52b85c5c8f9d3 100644 --- a/tokio-xmpp/examples/echo_server.rs +++ b/tokio-xmpp/examples/echo_server.rs @@ -1,8 +1,11 @@ use futures::{SinkExt, StreamExt}; use tokio::{self, io, net::TcpSocket}; -use tokio_xmpp::parsers::stream_features::StreamFeatures; -use tokio_xmpp::xmlstream::{accept_stream, StreamHeader, Timeouts}; +use tokio_xmpp::{ + minidom::Element, + parsers::stream_features::StreamFeatures, + xmlstream::{accept_stream, StreamHeader, Timeouts}, +}; #[tokio::main] async fn main() -> Result<(), io::Error> { @@ -24,7 +27,7 @@ async fn main() -> Result<(), io::Error> { .await?; let stream = stream.send_header(StreamHeader::default()).await?; let mut stream = stream - .send_features::(&StreamFeatures::default()) + .send_features::(&StreamFeatures::default()) .await?; tokio::spawn(async move { diff --git a/tokio-xmpp/src/error.rs b/tokio-xmpp/src/error.rs index 8963ad763afc0503f7b02b3009d36a28ea1b40dd..79d7b4cbd0d775bbf7426385baeb6dc27005f36a 100644 --- a/tokio-xmpp/src/error.rs +++ b/tokio-xmpp/src/error.rs @@ -9,10 +9,10 @@ use std::io::Error as IoError; use std::net::AddrParseError; use std::str::Utf8Error; -use xmpp_parsers::sasl::DefinedCondition as SaslDefinedCondition; -use xmpp_parsers::{jid::Error as JidParseError, Error as ParsersError}; - -use crate::connect::ServerConnectorError; +use crate::{ + connect::ServerConnectorError, jid, minidom, + parsers::sasl::DefinedCondition as SaslDefinedCondition, +}; /// Top-level error type #[derive(Debug)] @@ -20,7 +20,7 @@ pub enum Error { /// I/O error Io(IoError), /// Error parsing Jabber-Id - JidParse(JidParseError), + JidParse(jid::Error), /// Protocol-level error Protocol(ProtocolError), /// Authentication error @@ -86,8 +86,8 @@ impl From for Error { } } -impl From for Error { - fn from(e: JidParseError) -> Self { +impl From for Error { + fn from(e: jid::Error) -> Self { Error::JidParse(e) } } @@ -149,7 +149,7 @@ pub enum ProtocolError { /// XML parser error Parser(minidom::Error), /// Error with expected stanza schema - Parsers(ParsersError), + Parsers(xso::error::Error), /// No TLS available NoTls, /// Invalid response to resource binding @@ -197,8 +197,8 @@ impl From for Error { } } -impl From for ProtocolError { - fn from(e: ParsersError) -> Self { +impl From for ProtocolError { + fn from(e: xso::error::Error) -> Self { ProtocolError::Parsers(e) } } diff --git a/tokio-xmpp/src/lib.rs b/tokio-xmpp/src/lib.rs index beabf88eeb78fe6e03e8ee52305ff83d3af658d3..59d903dd8f214f114bede17ceca4c3f28a8a7f8e 100644 --- a/tokio-xmpp/src/lib.rs +++ b/tokio-xmpp/src/lib.rs @@ -46,28 +46,36 @@ compile_error!( "when starttls feature enabled one of tls-native and tls-rust features must be enabled." ); -mod event; -pub use event::{Event, Stanza}; -pub mod connect; -pub mod stanzastream; -pub mod xmlstream; +pub use parsers::{jid, minidom}; +pub use xmpp_parsers as parsers; mod client; -pub use client::Client; - #[cfg(feature = "insecure-tcp")] mod component; -#[cfg(feature = "insecure-tcp")] -pub use crate::component::Component; - +pub mod connect; /// Detailed error types pub mod error; +mod event; +pub mod stanzastream; +pub mod xmlstream; #[doc(inline)] /// Generic tokio_xmpp Error pub use crate::error::Error; +pub use client::Client; +#[cfg(feature = "insecure-tcp")] +pub use component::Component; +pub use event::{Event, Stanza}; -// Re-exports -pub use minidom; -pub use xmpp_parsers as parsers; -pub use xmpp_parsers::jid; +#[cfg(test)] +mod tests { + #[test] + fn reexports() { + #[allow(unused_imports)] + use crate::jid; + #[allow(unused_imports)] + use crate::minidom; + #[allow(unused_imports)] + use crate::parsers; + } +} diff --git a/xmpp/src/lib.rs b/xmpp/src/lib.rs index 3cd0253c9b17b5c578e713a8ea56e2b5e7946d6a..6ed7ce833d23ba4f20eef769411cc0b8b26eaacc 100644 --- a/xmpp/src/lib.rs +++ b/xmpp/src/lib.rs @@ -8,13 +8,15 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg))] pub use tokio_xmpp; -pub use tokio_xmpp::jid::{ResourcePart, ResourceRef}; +pub use tokio_xmpp::jid; pub use tokio_xmpp::minidom; pub use tokio_xmpp::parsers; + #[macro_use] extern crate log; use core::fmt; +use jid::{ResourcePart, ResourceRef}; pub mod agent; pub mod builder; @@ -30,7 +32,6 @@ pub mod presence; pub mod pubsub; pub mod upload; -// Module re-exports pub use agent::Agent; pub use builder::{ClientBuilder, ClientType}; pub use event::Event; @@ -76,6 +77,21 @@ impl fmt::Display for RoomNick { } } +#[cfg(test)] +mod tests { + #[test] + fn reexports() { + #[allow(unused_imports)] + use crate::jid; + #[allow(unused_imports)] + use crate::minidom; + #[allow(unused_imports)] + use crate::parsers; + #[allow(unused_imports)] + use crate::tokio_xmpp; + } +} + // The test below is dysfunctional since we have moved to StanzaStream. The // StanzaStream will attempt to connect to foo@bar indefinitely. // Keeping it here as inspiration for future integration tests.