Skip to content

Commit

Permalink
improvement(clean): Cleanup and better docs. Bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
yonkeltron committed Aug 30, 2023
1 parent 63f90fd commit 35d8a53
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "testanything"
version = "0.4.0"
version = "0.4.1"
authors = ["Jonathan E. Magen <[email protected]>"]
edition = "2021"
description = "Generate results in the Test Anything Protocol (TAP)"
Expand Down
2 changes: 1 addition & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ dependencies = ["build", "test", "check", "clippy"]
[tasks.publish]
command = "cargo"
args = ["publish"]
dependencies = ["quality"]
dependencies = ["quality"]
9 changes: 3 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))]
Expand All @@ -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;
10 changes: 3 additions & 7 deletions src/tap_suite.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
33 changes: 26 additions & 7 deletions src/tap_test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
//! `TapTest` -- The core, representing an individual TAP test.

#[cfg(feature = "alloc")]
use alloc::{
string::{String, ToString},
vec,
vec::Vec,
};
use core::fmt::Write;
use std::fmt;

use crate::{NOT_OK_SYMBOL, OK_SYMBOL};

Expand All @@ -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.
Expand Down Expand Up @@ -78,11 +80,28 @@ impl From<TapTest> 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() {
Expand Down
2 changes: 2 additions & 0 deletions src/tap_test_builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! `TapTestBuilder` -- Helper for creating a `TapTestSuite` using the builder pattern

#[cfg(feature = "alloc")]
use alloc::{
string::{String, ToString},
Expand Down
2 changes: 2 additions & 0 deletions src/tap_writer.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 35d8a53

Please sign in to comment.