Core library for the cargo-culture project that provides the basic building blocks for running straightforward checks on a Rust project repo.
The primary intended application of these checks is within a command-line tool that contains and enforces best practices across repositories according to the needs of that organization.
The secondary envisioned application of these checks is integrated into Rust tests. This case may appeal to appeal to developers that want a rapid deep-integration path, don't mind writing a bit of code, and prefer to avoid the use of support programs.
cargo-culture-kit
is a Rust project, and manages its dependencies with cargo
,
available as part of the standard Rust toolchain.
For local program development, you can build cargo-culture-kit
with:
bash
git clone https://github.com/PolySync/cargo-culture.git
cd cargo-culture/cargo-culture-kit
bash
cargo build
You can include cargo-culture-kit
in your Rust project
by adding to your Cargo.toml file.
[dependencies]
or `[dev-dependencies]
section:
toml
cargo-culture-kit = "0.1"
check_culture_default
is the easiest way to get started,
as it provides a thin wrapper around the core check_culture
function in combination with the Rule
s provided by the
default_rules()
function. Rule
is the core trait of this crate. A Rule
describes an idiom or best-practice
for projects and provides a means of evaluating whether that rule of thumb
is being upheld.
```rust use cargoculturekit::{checkculturedefault, IsSuccess, OutcomeStats}; use std::path::PathBuf;
let cargo_manifest = PathBuf::from("../cargo-culture/Cargo.toml"); let verbose = false;
let outcomes = checkculturedefault( cargo_manifest, verbose, &mut std::io::stdout() ) .expect("Unexpected trouble checking culture rules:");
let stats = OutcomeStats::from(outcomes); assert!(stats.issuccess()); asserteq!(stats.failcount, 0); asserteq!(stats.undetermined_count, 0); ```
An example of implementing your own Rule
:
```rust
use cargoculturekit::{CargoMetadata, Rule, RuleContext, RuleOutcome}
struct IsProjectAtALuckyTime;
impl Rule for IsProjectAtALuckyTime { fn description(&self) -> &str { "Should be lucky enough to only be tested at specific times." }
fn evaluate(&self, context: RuleContext, ) -> RuleOutcome { use std::time::{SystemTime, UNIXEPOCH}; let sincetheepoch = match SystemTime::now().durationsince(UNIXEPOCH) { Ok(t) => t, Err() => return RuleOutcome::Undetermined, }; if sincetheepoch.assecs() % 2 == 0 { RuleOutcome::Success } else { RuleOutcome::Failure } } } ```
The cargo-culture-kit
tests are managed through the standard
cargo-integrated Rust test framework, with additional enhancement
through the proptest property based testing library.
To build but not run the tests:
bash
cargo build --tests
To both build and run the tests:
bash
cargo test
© 2018, PolySync Technologies, Inc.
Please see the LICENSE file for more details