serial_test-0.5.1/.cargo_vcs_info.json0000644000000001121375755446500134320ustar { "git": { "sha1": "910aef4106ba891271f0f0d22ac356fc6cc1204f" } } serial_test-0.5.1/Cargo.toml0000644000000017451375755446500114450ustar # 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 believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] edition = "2018" name = "serial_test" version = "0.5.1" authors = ["Tom Parker-Shemilt "] description = "Allows for the creation of serialised Rust tests" readme = "README.md" categories = ["development-tools::testing"] license = "MIT" repository = "https://github.com/palfrey/serial_test/" [dependencies.lazy_static] version = "1.2" [dependencies.parking_lot] version = ">= 0.10, < 0.12" [dependencies.serial_test_derive] version = "~0.5.1" serial_test-0.5.1/Cargo.toml.orig010064400017500001750000000007171375755402500151250ustar 00000000000000[package] name = "serial_test" description = "Allows for the creation of serialised Rust tests" license = "MIT" version = "0.5.1" authors = ["Tom Parker-Shemilt "] edition = "2018" repository = "https://github.com/palfrey/serial_test/" readme = "README.md" categories = ["development-tools::testing"] [dependencies] lazy_static = "1.2" parking_lot = ">= 0.10, < 0.12" serial_test_derive = { version = "~0.5.1", path = "../serial_test_derive" } serial_test-0.5.1/LICENSE010064400017500001750000000020451371232757400132350ustar 00000000000000Copyright (c) 2018 Tom Parker-Shemilt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.serial_test-0.5.1/README.md010064400017500001750000000031131375755365100135120ustar 00000000000000# serial_test [![Version](https://img.shields.io/crates/v/serial_test.svg)](https://crates.io/crates/serial_test) [![Downloads](https://img.shields.io/crates/d/serial_test)](https://crates.io/crates/serial_test) [![Docs](https://docs.rs/serial_test/badge.svg)](https://docs.rs/serial_test/) [![MIT license](https://img.shields.io/crates/l/serial_test.svg)](./LICENSE) [![Build Status](https://travis-ci.com/palfrey/serial_test.svg?branch=main)](https://travis-ci.com/palfrey/serial_test) [![MSRV: 1.39.0](https://flat.badgen.net/badge/MSRV/1.39.0/purple)](https://blog.rust-lang.org/2019/11/07/Rust-1.39.0.html) [![dependency status](https://deps.rs/repo/github/palfrey/serial_test/status.svg)](https://deps.rs/repo/github/palfrey/serial_test) `serial_test` allows for the creation of serialised Rust tests using the `serial` attribute e.g. ```rust #[test] #[serial] fn test_serial_one() { // Do things } #[test] #[serial] fn test_serial_another() { // Do things } #[tokio::test] #[serial] async fn test_serial_another() { // Do things asynchronously } ``` Multiple tests with the `serial` attribute are guaranteed to be executed in serial. Ordering of the tests is not guaranteed however. ## Usage We require at least Rust 1.39 for [async/await](https://blog.rust-lang.org/2019/11/07/Async-await-stable.html) support Add to your Cargo.toml ```toml [dev-dependencies] serial_test = "*" ``` plus `use serial_test::serial;` (for Rust 2018) or ```rust #[macro_use] extern crate serial_test; ``` for earlier versions. You can then either add `#[serial]` or `#[serial(some_text)]` to tests as required. serial_test-0.5.1/src/lib.rs010064400017500001750000000050211372272737600141350ustar 00000000000000//! # serial_test //! `serial_test` allows for the creation of serialised Rust tests using the [serial](attr.serial.html) attribute //! e.g. //! ```` //! #[test] //! #[serial] //! fn test_serial_one() { //! // Do things //! } //! //! #[test] //! #[serial] //! fn test_serial_another() { //! // Do things //! } //! ```` //! Multiple tests with the [serial](attr.serial.html) attribute are guaranteed to be executed in serial. Ordering //! of the tests is not guaranteed however. use lazy_static::lazy_static; use parking_lot::ReentrantMutex; use std::collections::HashMap; use std::ops::{Deref, DerefMut}; use std::sync::{Arc, RwLock}; lazy_static! { static ref LOCKS: Arc>>> = Arc::new(RwLock::new(HashMap::new())); } fn check_new_key(name: &str) { // Check if a new key is needed. Just need a read lock, which can be done in sync with everyone else let new_key = { let unlock = LOCKS.read().unwrap(); !unlock.deref().contains_key(name) }; if new_key { // This is the rare path, which avoids the multi-writer situation mostly LOCKS .write() .unwrap() .deref_mut() .insert(name.to_string(), ReentrantMutex::new(())); } } #[doc(hidden)] pub fn serial_core_with_return(name: &str, function: fn() -> Result<(), E>) -> Result<(), E> { check_new_key(name); let unlock = LOCKS.read().unwrap(); // _guard needs to be named to avoid being instant dropped let _guard = unlock.deref()[name].lock(); function() } #[doc(hidden)] pub fn serial_core(name: &str, function: fn()) { check_new_key(name); let unlock = LOCKS.read().unwrap(); // _guard needs to be named to avoid being instant dropped let _guard = unlock.deref()[name].lock(); function(); } #[doc(hidden)] pub async fn async_serial_core_with_return( name: &str, fut: impl std::future::Future>, ) -> Result<(), E> { check_new_key(name); let unlock = LOCKS.read().unwrap(); // _guard needs to be named to avoid being instant dropped let _guard = unlock.deref()[name].lock(); fut.await } #[doc(hidden)] pub async fn async_serial_core(name: &str, fut: impl std::future::Future) { check_new_key(name); let unlock = LOCKS.read().unwrap(); // _guard needs to be named to avoid being instant dropped let _guard = unlock.deref()[name].lock(); fut.await } // Re-export #[serial]. #[allow(unused_imports)] pub use serial_test_derive::serial; serial_test-0.5.1/tests/tests.rs010064400017500001750000000002051371232757400150760ustar 00000000000000use serial_test::serial_core; #[test] fn test_empty_serial_call() { serial_core("beta", || { println!("Bar"); }); }