archunit/common/fluentapi/
check_options.rsuse crate::common::LoggingOptions;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct CheckOptions {
allow_empty_tests: bool,
logging: Option<LoggingOptions>,
clear_cache: bool,
include_test_sources: bool,
}
impl CheckOptions {
#[must_use]
pub const fn new() -> Self {
Self {
allow_empty_tests: false,
logging: None,
clear_cache: false,
include_test_sources: false,
}
}
#[must_use]
pub const fn allows_empty_tests(&self) -> bool {
self.allow_empty_tests
}
#[must_use]
pub const fn with_allow_empty_tests(mut self, allow: bool) -> Self {
self.allow_empty_tests = allow;
self
}
#[must_use]
pub const fn logging(&self) -> Option<&LoggingOptions> {
self.logging.as_ref()
}
#[must_use]
pub fn with_logging(mut self, logging: LoggingOptions) -> Self {
self.logging = Some(logging);
self
}
#[must_use]
pub const fn clears_cache(&self) -> bool {
self.clear_cache
}
#[must_use]
pub const fn with_clear_cache(mut self, clear: bool) -> Self {
self.clear_cache = clear;
self
}
#[must_use]
pub const fn includes_test_sources(&self) -> bool {
self.include_test_sources
}
#[must_use]
pub const fn with_test_sources(mut self, include: bool) -> Self {
self.include_test_sources = include;
self
}
}
impl Default for CheckOptions {
fn default() -> Self {
Self::new()
}
}
#[cfg(test)]
mod tests {
use super::CheckOptions;
use crate::common::LoggingOptions;
#[test]
fn defaults_are_strict_quiet_cached_and_production_only() {
let options = CheckOptions::default();
assert!(!options.allows_empty_tests());
assert!(options.logging().is_none());
assert!(!options.clears_cache());
assert!(!options.includes_test_sources());
}
#[test]
fn consuming_builders_compose_every_current_option() {
let options = CheckOptions::new()
.with_allow_empty_tests(true)
.with_logging(LoggingOptions::new())
.with_clear_cache(true)
.with_test_sources(true);
assert!(options.allows_empty_tests());
assert!(options.logging().is_some());
assert!(options.clears_cache());
assert!(options.includes_test_sources());
}
#[test]
fn configured_bags_can_be_branched_without_mutating_the_base() {
let base = CheckOptions::new().with_clear_cache(true);
let derived = base.clone().with_allow_empty_tests(true);
assert!(!base.allows_empty_tests());
assert!(base.clears_cache());
assert!(derived.allows_empty_tests());
assert!(derived.clears_cache());
}
}