quick-junit-0.3.3/.cargo_vcs_info.json 0000644 00000000151 00000000001 0013277 0 ustar {
"git": {
"sha1": "3b57b14302fc8158bdcaad2c44a0c7afd0b9ef3c"
},
"path_in_vcs": "quick-junit"
} quick-junit-0.3.3/CHANGELOG.md 0000644 0000000 0000000 00000004404 10461020230 0013705 0 ustar 0000000 0000000 # Changelog
## [0.3.3] - 2023-06-07
### Added
- `TestCase` now has an extra `properties` section and an `add_property` method, similar to `TestSuite`. Thanks [@skycoop](https://github.com/skycoop) for your first contribution!
### Changed
- Internal dependency update: quick-xml updated to 0.29.0.
- MSRV updated to Rust 1.66.
## [0.3.2] - 2022-11-23
### Changed
- Internal dependency update: quick-xml updated to 0.26.0.
- MSRV updated to Rust 1.62.
## [0.3.1] - 2022-11-23
(This version was not published due to a code issue.)
## [0.3.0] - 2022-07-27
### Added
- `Report` contains a new `uuid` field with a unique identifier for a particular run. This is an extension to the JUnit spec.
## [0.2.0] - 2022-06-21
### Changed
- quick-xml updated to 0.23.0.
- The error type is now defined by quick-junit, so that future breaking changes to quick-xml will not necessitate a breaking change to this crate.
- MSRV bumped to Rust 1.59.
## [0.1.5] - 2022-02-14
### Changed
- Lower MSRV to Rust 1.54.
## [0.1.4] - 2022-02-07
### Fixed
- In readme, fix link to cargo-nextest.
### Changed
- Update repository location.
## [0.1.3] - 2022-01-29
- In the readme, replace Markdown checkboxes with Unicode ✅ to make them render properly on
crates.io.
## [0.1.2] - 2022-01-29
- Expand readme.
- Add keywords and categories.
## [0.1.1] - 2022-01-28
- Fix repository field in Cargo.toml.
## [0.1.0] - 2022-01-28
- Initial version.
[0.3.3]: https://github.com/nextest-rs/nextest/releases/tag/quick-junit-0.3.3
[0.3.2]: https://github.com/nextest-rs/nextest/releases/tag/quick-junit-0.3.2
[0.3.1]: https://github.com/nextest-rs/nextest/releases/tag/quick-junit-0.3.1
[0.3.0]: https://github.com/nextest-rs/nextest/releases/tag/quick-junit-0.3.0
[0.2.0]: https://github.com/nextest-rs/nextest/releases/tag/quick-junit-0.2.0
[0.1.5]: https://github.com/nextest-rs/nextest/releases/tag/quick-junit-0.1.5
[0.1.4]: https://github.com/nextest-rs/nextest/releases/tag/quick-junit-0.1.4
[0.1.3]: https://github.com/diem/diem-devtools/releases/tag/quick-junit-0.1.3
[0.1.2]: https://github.com/diem/diem-devtools/releases/tag/quick-junit-0.1.2
[0.1.1]: https://github.com/diem/diem-devtools/releases/tag/quick-junit-0.1.1
[0.1.0]: https://github.com/diem/diem-devtools/releases/tag/quick-junit-0.1.0
quick-junit-0.3.3/Cargo.toml 0000644 00000002401 00000000001 0011275 0 ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
rust-version = "1.66"
name = "quick-junit"
version = "0.3.3"
description = "Data model and serializer for JUnit/XUnit XML"
documentation = "https://docs.rs/quick-junit"
readme = "README.md"
keywords = [
"junit",
"xunit",
"xml",
"serializer",
"flaky-tests",
]
categories = [
"encoding",
"development-tools",
]
license = "Apache-2.0 OR MIT"
repository = "https://github.com/nextest-rs/nextest"
[dependencies.chrono]
version = "0.4.26"
[dependencies.indexmap]
version = "2.0.0"
[dependencies.nextest-workspace-hack]
version = "0.1"
[dependencies.quick-xml]
version = "0.29.0"
[dependencies.thiserror]
version = "1.0.40"
[dependencies.uuid]
version = "1.3.4"
[dev-dependencies.goldenfile]
version = "1.4.5"
[dev-dependencies.owo-colors]
version = "3.5.0"
quick-junit-0.3.3/Cargo.toml.orig 0000644 0000000 0000000 00000001222 10461020230 0014756 0 ustar 0000000 0000000 [package]
name = "quick-junit"
description = "Data model and serializer for JUnit/XUnit XML"
version = "0.3.3"
readme = "README.md"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/nextest-rs/nextest"
documentation = "https://docs.rs/quick-junit"
keywords = ["junit", "xunit", "xml", "serializer", "flaky-tests"]
categories = ["encoding", "development-tools"]
edition = "2021"
rust-version = "1.66"
[dependencies]
chrono = "0.4.26"
indexmap = "2.0.0"
quick-xml = "0.29.0"
thiserror = "1.0.40"
uuid = "1.3.4"
nextest-workspace-hack = { version = "0.1", path = "../workspace-hack" }
[dev-dependencies]
goldenfile = "1.4.5"
owo-colors = "3.5.0"
quick-junit-0.3.3/README.md 0000644 0000000 0000000 00000007055 10461020230 0013360 0 ustar 0000000 0000000 # quick-junit
[](https://crates.io/crates/quick-junit)
[](https://docs.rs/quick-junit/)
[](https://nexte.st/rustdoc/quick_junit/)
[](CHANGELOG.md)
[](LICENSE-APACHE)
[](LICENSE-MIT)
`quick-junit` is a JUnit/XUnit XML data model and serializer for Rust. This crate allows users
to create a JUnit report as an XML file. JUnit XML files are widely supported by test tooling.
This crate is built to serve the needs of [cargo-nextest](https://nexte.st).
## Overview
The root element of a JUnit report is a `Report`. A `Report` consists of one or more
`TestSuite` instances. A `TestSuite` instance consists of one or more `TestCase`s.
The status (success, failure, error, or skipped) of a `TestCase` is represented by `TestCaseStatus`.
## Features
- ✅ Serializing JUnit/XUnit to the [Jenkins format](https://llg.cubic.org/docs/junit/).
- ✅ Including test reruns using `TestRerun`
- ✅ Including flaky tests
- ✅ Including standard output and error
- ✅ Filtering out [invalid XML
characters](https://en.wikipedia.org/wiki/Valid_characters_in_XML) (eg ANSI escape codes)
from the output
- ✅ Automatically keeping track of success, failure and error counts
- ✅ Arbitrary properties and extra attributes
This crate does not currently support deserializing JUnit XML. (PRs are welcome!)
## Examples
```rust
use quick_junit::*;
let mut report = Report::new("my-test-run");
let mut test_suite = TestSuite::new("my-test-suite");
let success_case = TestCase::new("success-case", TestCaseStatus::success());
let failure_case = TestCase::new("failure-case", TestCaseStatus::non_success(NonSuccessKind::Failure));
test_suite.add_test_cases([success_case, failure_case]);
report.add_test_suite(test_suite);
const EXPECTED_XML: &str = r#"
"#;
assert_eq!(report.to_string().unwrap(), EXPECTED_XML);
```
For a more comprehensive example, including reruns and flaky tests, see
[`fixture_tests.rs`](https://github.com/nextest-rs/nextest/blob/main/quick-junit/tests/fixture_tests.rs).
## Minimum supported Rust version (MSRV)
The minimum supported Rust version is **Rust 1.66.**
While this crate is a pre-release (0.x.x) it may have its MSRV bumped in a patch release.
Once a crate has reached 1.x, any MSRV bump will be accompanied with a new minor version.
## Alternatives
* [**junit-report**](https://crates.io/crates/junit-report): Older, more mature project. Doesn't
appear to support flaky tests or arbitrary properties as of version 0.7.0.
## Contributing
See the [CONTRIBUTING](../CONTRIBUTING.md) file for how to help out.
## License
This project is available under the terms of either the [Apache 2.0 license](../LICENSE-APACHE) or
the [MIT license](../LICENSE-MIT).
quick-junit-0.3.3/README.tpl 0000644 0000000 0000000 00000001743 10461020230 0013555 0 ustar 0000000 0000000 # {{crate}}
[](https://crates.io/crates/quick-junit)
[](https://docs.rs/quick-junit/)
[](https://nexte.st/rustdoc/quick_junit/)
[](CHANGELOG.md)
[](LICENSE-APACHE)
[](LICENSE-MIT)
{{readme}}
## Contributing
See the [CONTRIBUTING](../CONTRIBUTING.md) file for how to help out.
## License
This project is available under the terms of either the [Apache 2.0 license](../LICENSE-APACHE) or
the [MIT license](../LICENSE-MIT).
quick-junit-0.3.3/src/errors.rs 0000644 0000000 0000000 00000000677 10461020230 0014555 0 ustar 0000000 0000000 // Copyright (c) The nextest Contributors
// SPDX-License-Identifier: MIT OR Apache-2.0
use thiserror::Error;
/// An error that occurs while serializing a [`Report`](crate::Report).
///
/// Returned by [`Report::serialize`](crate::Report::serialize) and
/// [`Report::to_string`](crate::Report::to_string).
#[derive(Debug, Error)]
#[error("error serializing JUnit report")]
pub struct SerializeError {
#[from]
inner: quick_xml::Error,
}
quick-junit-0.3.3/src/lib.rs 0000644 0000000 0000000 00000006030 10461020230 0013774 0 ustar 0000000 0000000 // Copyright (c) The nextest Contributors
// SPDX-License-Identifier: MIT OR Apache-2.0
#![warn(missing_docs)]
//! `quick-junit` is a JUnit/XUnit XML data model and serializer for Rust. This crate allows users
//! to create a JUnit report as an XML file. JUnit XML files are widely supported by test tooling.
//!
//! This crate is built to serve the needs of [cargo-nextest](https://nexte.st).
//!
//! # Overview
//!
//! The root element of a JUnit report is a [`Report`]. A [`Report`] consists of one or more
//! [`TestSuite`] instances. A [`TestSuite`] instance consists of one or more [`TestCase`]s.
//!
//! The status (success, failure, error, or skipped) of a [`TestCase`] is represented by [`TestCaseStatus`].
//!
//! # Features
//!
//! - ✅ Serializing JUnit/XUnit to the [Jenkins format](https://llg.cubic.org/docs/junit/).
//! - ✅ Including test reruns using [`TestRerun`]
//! - ✅ Including flaky tests
//! - ✅ Including standard output and error
//! - ✅ Filtering out [invalid XML
//! characters](https://en.wikipedia.org/wiki/Valid_characters_in_XML) (eg ANSI escape codes)
//! from the output
//! - ✅ Automatically keeping track of success, failure and error counts
//! - ✅ Arbitrary properties and extra attributes
//!
//! This crate does not currently support deserializing JUnit XML. (PRs are welcome!)
//!
//! # Examples
//!
//! ```rust
//! use quick_junit::*;
//!
//! let mut report = Report::new("my-test-run");
//! let mut test_suite = TestSuite::new("my-test-suite");
//! let success_case = TestCase::new("success-case", TestCaseStatus::success());
//! let failure_case = TestCase::new("failure-case", TestCaseStatus::non_success(NonSuccessKind::Failure));
//! test_suite.add_test_cases([success_case, failure_case]);
//! report.add_test_suite(test_suite);
//!
//! const EXPECTED_XML: &str = r#"
//!
//!
//!
//!
//!
//!
//!
//!
//!
//! "#;
//!
//! assert_eq!(report.to_string().unwrap(), EXPECTED_XML);
//! ```
//!
//! For a more comprehensive example, including reruns and flaky tests, see
//! [`fixture_tests.rs`](https://github.com/nextest-rs/nextest/blob/main/quick-junit/tests/fixture_tests.rs).
//!
//! # Minimum supported Rust version (MSRV)
//!
//! The minimum supported Rust version is **Rust 1.66.**
//!
//! While this crate is a pre-release (0.x.x) it may have its MSRV bumped in a patch release.
//! Once a crate has reached 1.x, any MSRV bump will be accompanied with a new minor version.
//!
//! # Alternatives
//!
//! * [**junit-report**](https://crates.io/crates/junit-report): Older, more mature project. Doesn't
//! appear to support flaky tests or arbitrary properties as of version 0.7.0.
mod errors;
mod report;
mod serialize;
pub use errors::*;
pub use report::*;
quick-junit-0.3.3/src/report.rs 0000644 0000000 0000000 00000054064 10461020230 0014553 0 ustar 0000000 0000000 // Copyright (c) The nextest Contributors
// SPDX-License-Identifier: MIT OR Apache-2.0
use crate::{serialize::serialize_report, SerializeError};
use chrono::{DateTime, FixedOffset};
use indexmap::map::IndexMap;
use std::{io, iter, time::Duration};
use uuid::Uuid;
/// The root element of a JUnit report.
#[derive(Clone, Debug)]
pub struct Report {
/// The name of this report.
pub name: String,
/// A unique identifier associated with this report.
///
/// This is an extension to the spec that's used by nextest.
pub uuid: Option,
/// The time at which the first test in this report began execution.
///
/// This is not part of the JUnit spec, but may be useful for some tools.
pub timestamp: Option>,
/// The overall time taken by the test suite.
///
/// This is serialized as the number of seconds.
pub time: Option,
/// The total number of tests from all TestSuites.
pub tests: usize,
/// The total number of failures from all TestSuites.
pub failures: usize,
/// The total number of errors from all TestSuites.
pub errors: usize,
/// The test suites contained in this report.
pub test_suites: Vec,
}
impl Report {
/// Creates a new `Report` with the given name.
pub fn new(name: impl Into) -> Self {
Self {
name: name.into(),
uuid: None,
timestamp: None,
time: None,
tests: 0,
failures: 0,
errors: 0,
test_suites: vec![],
}
}
/// Sets a unique ID for this `Report`.
///
/// This is an extension that's used by nextest.
pub fn set_uuid(&mut self, uuid: Uuid) -> &mut Self {
self.uuid = Some(uuid);
self
}
/// Sets the start timestamp for the report.
pub fn set_timestamp(&mut self, timestamp: impl Into>) -> &mut Self {
self.timestamp = Some(timestamp.into());
self
}
/// Sets the time taken for overall execution.
pub fn set_time(&mut self, time: Duration) -> &mut Self {
self.time = Some(time);
self
}
/// Adds a new TestSuite and updates the `tests`, `failures` and `errors` counts.
///
/// When generating a new report, use of this method is recommended over adding to
/// `self.TestSuites` directly.
pub fn add_test_suite(&mut self, test_suite: TestSuite) -> &mut Self {
self.tests += test_suite.tests;
self.failures += test_suite.failures;
self.errors += test_suite.errors;
self.test_suites.push(test_suite);
self
}
/// Adds several [`TestSuite`]s and updates the `tests`, `failures` and `errors` counts.
///
/// When generating a new report, use of this method is recommended over adding to
/// `self.TestSuites` directly.
pub fn add_test_suites(
&mut self,
test_suites: impl IntoIterator- ,
) -> &mut Self {
for test_suite in test_suites {
self.add_test_suite(test_suite);
}
self
}
/// Serialize this report to the given writer.
pub fn serialize(&self, writer: impl io::Write) -> Result<(), SerializeError> {
serialize_report(self, writer)
}
/// Serialize this report to a string.
pub fn to_string(&self) -> Result {
let mut buf: Vec = vec![];
self.serialize(&mut buf)?;
String::from_utf8(buf).map_err(|utf8_err| quick_xml::Error::from(utf8_err).into())
}
}
/// Represents a single TestSuite.
///
/// A `TestSuite` groups together several `TestCase` instances.
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct TestSuite {
/// The name of this TestSuite.
pub name: String,
/// The total number of tests in this TestSuite.
pub tests: usize,
/// The total number of disabled tests in this TestSuite.
pub disabled: usize,
/// The total number of tests in this suite that errored.
///
/// An "error" is usually some sort of *unexpected* issue in a test.
pub errors: usize,
/// The total number of tests in this suite that failed.
///
/// A "failure" is usually some sort of *expected* issue in a test.
pub failures: usize,
/// The time at which the TestSuite began execution.
pub timestamp: Option>,
/// The overall time taken by the TestSuite.
pub time: Option,
/// The test cases that form this TestSuite.
pub test_cases: Vec,
/// Custom properties set during test execution, e.g. environment variables.
pub properties: Vec,
/// Data written to standard output while the TestSuite was executed.
pub system_out: Option