diff --git a/rust/pact_verifier_cli/Cargo.toml b/rust/pact_verifier_cli/Cargo.toml index 3fb05cc0f..f9ad9af01 100644 --- a/rust/pact_verifier_cli/Cargo.toml +++ b/rust/pact_verifier_cli/Cargo.toml @@ -13,16 +13,24 @@ exclude = [ "*.iml" ] +[features] +default = ["datetime", "xml", "plugins", "multipart", "junit"] +datetime = ["pact_models/datetime", "pact_verifier/datetime"] # Support for date/time matchers and expressions +xml = ["pact_models/xml", "pact_verifier/xml"] # support for matching XML documents +plugins = ["pact_verifier/plugins"] +multipart = ["pact_verifier/multipart"] # suport for MIME multipart bodies +junit = ["dep:junit-report"] # suport for MIME multipart bodies + [dependencies] ansi_term = "0.12.1" anyhow = "1.0.70" clap = { version = "4.2.1", features = ["cargo", "env"] } env_logger = "0.10.0" -junit-report = "0.8.2" +junit-report = { version = "0.8.2", optional = true } log = "0.4.17" maplit = "1.0.2" -pact_models = "~1.1.8" -pact_verifier = { version = "~1.0.1", path = "../pact_verifier" } +pact_models = { version = "~1.1.8", default-features = false } +pact_verifier = { version = "~1.0.1", path = "../pact_verifier", default-features = false } regex = "1.7.3" reqwest = { version = "0.11.16", default-features = false, features = ["rustls-tls-native-roots", "blocking", "json"] } serde_json = "1.0.95" diff --git a/rust/pact_verifier_cli/src/args.rs b/rust/pact_verifier_cli/src/args.rs index a17bc160f..5961f85cb 100644 --- a/rust/pact_verifier_cli/src/args.rs +++ b/rust/pact_verifier_cli/src/args.rs @@ -77,7 +77,7 @@ pub(crate) fn setup_app() -> Command { .long("junit") .action(ArgAction::Set) .value_parser(NonEmptyStringValueParser::new()) - .help("Generate a JUnit XML report of the verification")) + .help("Generate a JUnit XML report of the verification (requires the junit feature)")) .arg(Arg::new("no-colour") .long("no-colour") .action(ArgAction::SetTrue) diff --git a/rust/pact_verifier_cli/src/main.rs b/rust/pact_verifier_cli/src/main.rs index accad4266..5be9ca889 100644 --- a/rust/pact_verifier_cli/src/main.rs +++ b/rust/pact_verifier_cli/src/main.rs @@ -400,11 +400,15 @@ async fn handle_matches(matches: &ArgMatches) -> Result<(), i32> { } } - if let Some(junit_file) = matches.get_one::("junit-file") { - if let Err(err) = reports::write_junit_report(&result, junit_file.as_str(), &provider_name) { - error!("Failed to write JUnit report to '{junit_file}' - {err}"); + if let Some(_junit_file) = matches.get_one::("junit-file") { + #[cfg(feature = "junit")] + if let Err(err) = reports::write_junit_report(&result, _junit_file.as_str(), &provider_name) { + error!("Failed to write JUnit report to '{_junit_file}' - {err}"); return Err(2) } + + #[cfg(not(feature = "junit"))] + warn!("junit feature is not enabled, ignoring junit-file option"); } if result.result { Ok(()) } else { Err(1) } diff --git a/rust/pact_verifier_cli/src/reports.rs b/rust/pact_verifier_cli/src/reports.rs index d0c2e797b..a66ab99d4 100644 --- a/rust/pact_verifier_cli/src/reports.rs +++ b/rust/pact_verifier_cli/src/reports.rs @@ -1,11 +1,11 @@ use std::fs::File; use std::io::Write; -use junit_report::{ReportBuilder, TestCaseBuilder, TestSuiteBuilder}; +#[cfg(feature = "junit")] use junit_report::{ReportBuilder, TestCaseBuilder, TestSuiteBuilder}; use serde_json::Value; use tracing::debug; -use pact_verifier::{interaction_mismatch_output, MismatchResult}; +#[cfg(feature = "junit")] use pact_verifier::{interaction_mismatch_output, MismatchResult}; use pact_verifier::verification_result::VerificationExecutionResult; pub(crate) fn write_json_report(result: &VerificationExecutionResult, file_name: &str) -> anyhow::Result<()> { @@ -16,6 +16,7 @@ pub(crate) fn write_json_report(result: &VerificationExecutionResult, file_name: Ok(()) } +#[cfg(feature = "junit")] pub(crate) fn write_junit_report(result: &VerificationExecutionResult, file_name: &str, provider: &String) -> anyhow::Result<()> { debug!("Writing JUnit result of the verification to '{file_name}'"); let mut f = File::create(file_name)?; diff --git a/rust/pact_verifier_cli/tests/cmd/main.stderr b/rust/pact_verifier_cli/tests/cmd/main.stderr index ec903100c..0003daf69 100644 --- a/rust/pact_verifier_cli/tests/cmd/main.stderr +++ b/rust/pact_verifier_cli/tests/cmd/main.stderr @@ -12,7 +12,7 @@ Logging options: --full-log This emits human-readable, single-line logs for each event that occurs, with the current span context displayed before the formatted representation of the event. --compact-log Emit logs optimized for short line lengths. -j, --json Generate a JSON report of the verification - -x, --junit Generate a JUnit XML report of the verification + -x, --junit Generate a JUnit XML report of the verification (requires the junit feature) --no-colour Disables ANSI escape codes in the output [aliases: no-color] Loading pacts options: