From 35d8a53486feba68499f6eb4bdb453f495fc9a9f Mon Sep 17 00:00:00 2001 From: "Jonathan E. Magen" <59451+yonkeltron@users.noreply.github.com> Date: Wed, 30 Aug 2023 16:16:15 -0400 Subject: [PATCH] improvement(clean): Cleanup and better docs. Bump version. --- Cargo.lock | 2 +- Cargo.toml | 2 +- Makefile.toml | 2 +- src/lib.rs | 9 +++------ src/tap_suite.rs | 10 +++------- src/tap_test.rs | 33 ++++++++++++++++++++++++++------- src/tap_test_builder.rs | 2 ++ src/tap_writer.rs | 2 ++ 8 files changed, 39 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 17b7c82..47ab2ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,4 +4,4 @@ version = 3 [[package]] name = "testanything" -version = "0.4.0" +version = "0.4.1" diff --git a/Cargo.toml b/Cargo.toml index c64bd0c..fc0bcac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "testanything" -version = "0.4.0" +version = "0.4.1" authors = ["Jonathan E. Magen "] edition = "2021" description = "Generate results in the Test Anything Protocol (TAP)" diff --git a/Makefile.toml b/Makefile.toml index 00aea1b..52763b8 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -25,4 +25,4 @@ dependencies = ["build", "test", "check", "clippy"] [tasks.publish] command = "cargo" args = ["publish"] -dependencies = ["quality"] \ No newline at end of file +dependencies = ["quality"] diff --git a/src/lib.rs b/src/lib.rs index 347ab2a..4044cc2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,13 +60,15 @@ //! writer.diagnostic("The above test failed because of XYZ reason"); //! writer.ok(5, "Tree"); //! -//! // uh oh! something went horribly wrong and we need to stop before +//! // Uh oh! something went horribly wrong and we need to stop before //! // we print out the results from test 6! //! writer.bail_out_with_message("Destabilized warp core! Can't continue!"); //! ``` //! //! +#![forbid(unsafe_code)] +#![deny(clippy::all)] // Support using TAP without the standard library #![cfg_attr(not(feature = "std"), no_std)] #[cfg(all(feature = "alloc", not(feature = "std")))] @@ -77,14 +79,9 @@ const OK_SYMBOL: &str = "ok"; /// Global constant for the "not ok" const NOT_OK_SYMBOL: &str = "not ok"; -/// `TapSuite` -- A collection of `TapTest` objects renderable into a TAP text stream pub mod tap_suite; -/// `TapTestBuilder` -- Helper for creating a `TapTestSuite` using the builder pattern pub mod tap_suite_builder; -/// `TapTest` -- The core, representing an individual TAP test. pub mod tap_test; -/// `TapTestBuilder` -- Helper for creating a `TapTest` using the builder pattern. pub mod tap_test_builder; #[cfg(feature = "std")] -/// `TapWriter` -- For writing TAP streams incrementally pub mod tap_writer; diff --git a/src/tap_suite.rs b/src/tap_suite.rs index 0e62d34..9a4261e 100644 --- a/src/tap_suite.rs +++ b/src/tap_suite.rs @@ -1,3 +1,5 @@ +//! `TapSuite` -- A collection of `TapTest` objects renderable into a TAP text stream + #[cfg(feature = "alloc")] use alloc::{format, string::String, vec, vec::Vec}; #[cfg(feature = "std")] @@ -6,7 +8,7 @@ use std::io::Write; use crate::tap_test::TapTest; /// Represents a collection of TAP tests (`TapTest`) which can be rendered into a (text) TAP stream. This orchestrates that rendering. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct TapSuite { /// The name of the suite. If this is a blank string, that's fine but it's considered a party foul. pub name: String, @@ -43,12 +45,6 @@ impl TapSuite { } } -impl PartialEq for TapSuite { - fn eq(&self, other: &TapSuite) -> bool { - self.name == other.name && self.tests == other.tests - } -} - #[cfg(test)] mod tests { use super::TapSuite; diff --git a/src/tap_test.rs b/src/tap_test.rs index ec96592..ef9e534 100644 --- a/src/tap_test.rs +++ b/src/tap_test.rs @@ -1,3 +1,5 @@ +//! `TapTest` -- The core, representing an individual TAP test. + #[cfg(feature = "alloc")] use alloc::{ string::{String, ToString}, @@ -5,6 +7,7 @@ use alloc::{ vec::Vec, }; use core::fmt::Write; +use std::fmt; use crate::{NOT_OK_SYMBOL, OK_SYMBOL}; @@ -22,13 +25,12 @@ pub struct TapTest { impl TapTest { /// Based on the test passing status, yield either "ok" or "not ok". pub fn ok_string(&self) -> String { - let result = if self.passed { + if self.passed { OK_SYMBOL } else { NOT_OK_SYMBOL - }; - - result.to_string() + } + .to_string() } /// Produce a properly-formatted TAP line. This excludes diagnostics. @@ -78,11 +80,28 @@ impl From for String { } } +impl From<&TapTest> for String { + fn from(tap_test: &TapTest) -> Self { + let mut buf = String::new(); + write!( + &mut buf, + "TapTest(name: {}, passed: {}, diagnostics: {:?})", + tap_test.name, tap_test.passed, tap_test.diagnostics + ) + .unwrap(); + buf + } +} + +impl fmt::Display for TapTest { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", String::from(self)) + } +} + #[cfg(test)] mod tests { - use super::TapTest; - use crate::NOT_OK_SYMBOL; - use crate::OK_SYMBOL; + use super::*; #[test] fn test_tap_test_status_string() { diff --git a/src/tap_test_builder.rs b/src/tap_test_builder.rs index cc8f8a7..c76199f 100644 --- a/src/tap_test_builder.rs +++ b/src/tap_test_builder.rs @@ -1,3 +1,5 @@ +//! `TapTestBuilder` -- Helper for creating a `TapTestSuite` using the builder pattern + #[cfg(feature = "alloc")] use alloc::{ string::{String, ToString}, diff --git a/src/tap_writer.rs b/src/tap_writer.rs index f13c560..d0fbbf7 100644 --- a/src/tap_writer.rs +++ b/src/tap_writer.rs @@ -1,3 +1,5 @@ +//! `TapWriter` -- For writing TAP streams incrementally + use super::{NOT_OK_SYMBOL, OK_SYMBOL}; /// A named TAP stream writer. This will print directly to STDOUT as you call methods. No waiting.