diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aacdb49c..668239c0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,14 @@ -on: [push, pull_request] +on: + # Trigger the workflow on push to master or any pull request + # Ignore all tags + push: + branches: + - master + tags-ignore: '*' + pull_request: + branches: + - '*' + tags-ignore: '*' name: CI diff --git a/src/feature/build.rs b/src/feature/build.rs index 26cccf07..94b5164d 100644 --- a/src/feature/build.rs +++ b/src/feature/build.rs @@ -64,6 +64,8 @@ vergen(config)?; #[derive(Clone, Copy, Debug, Getters, MutGetters)] #[getset(get = "pub(crate)", get_mut = "pub")] pub struct Build { + /// Enable/Disable the build output + enabled: bool, /// Enable/Disable the `VERGEN_BUILD_DATE`, `VERGEN_BUILD_TIME`, and `VERGEN_BUILD_TIMESTAMP` instructions. timestamp: bool, /// The timezone to use for the date/time instructions. @@ -78,6 +80,7 @@ pub struct Build { impl Default for Build { fn default() -> Self { Self { + enabled: true, timestamp: true, timezone: TimeZone::Utc, kind: TimestampKind::Timestamp, @@ -89,7 +92,7 @@ impl Default for Build { #[cfg(feature = "build")] impl Build { pub(crate) fn has_enabled(self) -> bool { - self.timestamp || self.semver + self.enabled && (self.timestamp || self.semver) } } @@ -195,6 +198,28 @@ mod test { *config.build_mut().kind_mut() = TimestampKind::All; assert_eq!(config.build().kind(), &TimestampKind::All); } + + #[test] + fn not_enabled() { + let mut config = Instructions::default(); + *config.build_mut().enabled_mut() = false; + assert!(!config.build().has_enabled()); + } + + #[test] + fn no_timestamp() { + let mut config = Instructions::default(); + *config.build_mut().timestamp_mut() = false; + assert!(config.build().has_enabled()); + } + + #[test] + fn nothing() { + let mut config = Instructions::default(); + *config.build_mut().timestamp_mut() = false; + *config.build_mut().semver_mut() = false; + assert!(!config.build().has_enabled()); + } } #[cfg(all(test, not(feature = "build")))] diff --git a/src/feature/cargo.rs b/src/feature/cargo.rs index ba936cb6..f8e44d58 100644 --- a/src/feature/cargo.rs +++ b/src/feature/cargo.rs @@ -56,6 +56,8 @@ vergen(config)?; #[derive(Clone, Copy, Debug, Getters, MutGetters)] #[getset(get = "pub(crate)", get_mut = "pub")] pub struct Cargo { + /// Enable/Disable the cargo output + enabled: bool, /// Enable/Disable the `VERGEN_CARGO_FEATURES` instruction features: bool, /// Enable/Disable the `VERGEN_CARGO_PROFILE` instruction @@ -68,6 +70,7 @@ pub struct Cargo { impl Default for Cargo { fn default() -> Self { Self { + enabled: true, features: true, profile: true, target_triple: true, @@ -78,7 +81,7 @@ impl Default for Cargo { #[cfg(feature = "cargo")] impl Cargo { pub(crate) fn has_enabled(self) -> bool { - self.features || self.profile || self.target_triple + self.enabled && (self.features || self.profile || self.target_triple) } } @@ -164,6 +167,37 @@ mod test { assert!(!config.cargo().features); teardown(); } + + #[test] + fn not_enabled() { + let mut config = Instructions::default(); + *config.cargo_mut().enabled_mut() = false; + assert!(!config.cargo().has_enabled()); + } + + #[test] + fn no_features() { + let mut config = Instructions::default(); + *config.cargo_mut().features_mut() = false; + assert!(config.cargo().has_enabled()); + } + + #[test] + fn no_profile() { + let mut config = Instructions::default(); + *config.cargo_mut().features_mut() = false; + *config.cargo_mut().profile_mut() = false; + assert!(config.cargo().has_enabled()); + } + + #[test] + fn nothing() { + let mut config = Instructions::default(); + *config.cargo_mut().features_mut() = false; + *config.cargo_mut().profile_mut() = false; + *config.cargo_mut().target_triple_mut() = false; + assert!(!config.cargo().has_enabled()); + } } #[cfg(all(test, not(feature = "cargo")))] diff --git a/src/feature/git.rs b/src/feature/git.rs index 5d7e38c5..870f1813 100644 --- a/src/feature/git.rs +++ b/src/feature/git.rs @@ -104,6 +104,8 @@ vergen(config)?; #[derive(Clone, Copy, Debug, Getters, MutGetters)] #[getset(get = "pub(crate)", get_mut = "pub")] pub struct Git { + /// Enable/Disable the git output + enabled: bool, /// Enable/Disable the `VERGEN_GIT_BRANCH` instruction branch: bool, /// Enable/Disable the `VERGEN_GIT_COMMIT_DATE`, `VERGEN_GIT_COMMIT_TIME`, and `VERGEN_GIT_COMMIT_TIMESTAMP` instructions @@ -128,6 +130,7 @@ pub struct Git { impl Default for Git { fn default() -> Self { Self { + enabled: true, branch: true, commit_timestamp: true, commit_timestamp_timezone: feature::TimeZone::Utc, @@ -144,7 +147,12 @@ impl Default for Git { #[cfg(feature = "git")] impl Git { pub(crate) fn has_enabled(&self) -> bool { - self.branch || self.commit_timestamp || self.rerun_on_head_change || self.semver || self.sha + self.enabled + && (self.branch + || self.commit_timestamp + || self.rerun_on_head_change + || self.semver + || self.sha) } } @@ -374,6 +382,58 @@ mod test { config.git_mut().commit_timestamp_kind = TimestampKind::All; assert_eq!(config.git().commit_timestamp_kind, TimestampKind::All); } + + #[test] + fn not_enabled() { + let mut config = Instructions::default(); + *config.git_mut().enabled_mut() = false; + assert!(!config.git().has_enabled()); + } + + #[test] + fn no_branch() { + let mut config = Instructions::default(); + *config.git_mut().branch_mut() = false; + assert!(config.git().has_enabled()); + } + + #[test] + fn no_timestamp() { + let mut config = Instructions::default(); + *config.git_mut().branch_mut() = false; + *config.git_mut().commit_timestamp_mut() = false; + assert!(config.git().has_enabled()); + } + + #[test] + fn no_rerun_on_head_change() { + let mut config = Instructions::default(); + *config.git_mut().branch_mut() = false; + *config.git_mut().commit_timestamp_mut() = false; + *config.git_mut().rerun_on_head_change_mut() = false; + assert!(config.git().has_enabled()); + } + + #[test] + fn no_semver() { + let mut config = Instructions::default(); + *config.git_mut().branch_mut() = false; + *config.git_mut().commit_timestamp_mut() = false; + *config.git_mut().rerun_on_head_change_mut() = false; + *config.git_mut().semver_mut() = false; + assert!(config.git().has_enabled()); + } + + #[test] + fn nothing() { + let mut config = Instructions::default(); + *config.git_mut().branch_mut() = false; + *config.git_mut().commit_timestamp_mut() = false; + *config.git_mut().rerun_on_head_change_mut() = false; + *config.git_mut().semver_mut() = false; + *config.git_mut().sha_mut() = false; + assert!(!config.git().has_enabled()); + } } #[cfg(all(test, not(feature = "git")))] diff --git a/src/feature/rustc.rs b/src/feature/rustc.rs index f92c1b7f..91d614fb 100644 --- a/src/feature/rustc.rs +++ b/src/feature/rustc.rs @@ -63,7 +63,10 @@ vergen(config)?; #[cfg(feature = "rustc")] #[derive(Clone, Copy, Debug, Getters, MutGetters)] #[getset(get = "pub(crate)", get_mut = "pub")] +#[allow(clippy::struct_excessive_bools)] pub struct Rustc { + /// Enable/Disable the rustc output + enabled: bool, /// Enable/Disable the `VERGEN_RUSTC_CHANNEL` instruction channel: bool, /// Enable/Disable the `VERGEN_RUSTC_COMMIT_DATE` instruction @@ -82,6 +85,7 @@ pub struct Rustc { impl Default for Rustc { fn default() -> Self { Self { + enabled: true, channel: true, commit_date: true, host_triple: true, @@ -95,7 +99,12 @@ impl Default for Rustc { #[cfg(feature = "rustc")] impl Rustc { pub(crate) fn has_enabled(self) -> bool { - self.channel || self.commit_date || self.host_triple || self.llvm_version || self.sha + self.enabled + && (self.channel + || self.commit_date + || self.host_triple + || self.llvm_version + || self.sha) } } @@ -186,6 +195,58 @@ mod test { config.rustc_mut().host_triple = false; assert!(!config.rustc().host_triple); } + + #[test] + fn not_enabled() { + let mut config = Instructions::default(); + *config.rustc_mut().enabled_mut() = false; + assert!(!config.rustc().has_enabled()); + } + + #[test] + fn no_channel() { + let mut config = Instructions::default(); + *config.rustc_mut().channel_mut() = false; + assert!(config.rustc().has_enabled()); + } + + #[test] + fn no_commit_date() { + let mut config = Instructions::default(); + *config.rustc_mut().channel_mut() = false; + *config.rustc_mut().commit_date_mut() = false; + assert!(config.rustc().has_enabled()); + } + + #[test] + fn no_host_triple() { + let mut config = Instructions::default(); + *config.rustc_mut().channel_mut() = false; + *config.rustc_mut().commit_date_mut() = false; + *config.rustc_mut().host_triple_mut() = false; + assert!(config.rustc().has_enabled()); + } + + #[test] + fn no_llvm_version() { + let mut config = Instructions::default(); + *config.rustc_mut().channel_mut() = false; + *config.rustc_mut().commit_date_mut() = false; + *config.rustc_mut().host_triple_mut() = false; + *config.rustc_mut().llvm_version_mut() = false; + assert!(config.rustc().has_enabled()); + } + + #[test] + fn nothing() { + let mut config = Instructions::default(); + *config.rustc_mut().channel_mut() = false; + *config.rustc_mut().commit_date_mut() = false; + *config.rustc_mut().host_triple_mut() = false; + *config.rustc_mut().llvm_version_mut() = false; + *config.rustc_mut().sha_mut() = false; + assert!(!config.rustc().has_enabled()); + } } #[cfg(all(test, not(feature = "rustc")))] diff --git a/src/feature/si.rs b/src/feature/si.rs index 7a4ea6b2..4449719a 100644 --- a/src/feature/si.rs +++ b/src/feature/si.rs @@ -68,6 +68,8 @@ vergen(config)?; #[getset(get = "pub(crate)", get_mut = "pub")] #[allow(clippy::struct_excessive_bools)] pub struct Sysinfo { + /// Enable/Disable the sysinfo output + enabled: bool, /// Enable/Disable the `VERGEN_SYSINFO_NAME` instruction name: bool, /// Enable/Disable the `VERGEN_SYSINFO_OS_VERSION` instruction @@ -92,6 +94,7 @@ pub struct Sysinfo { impl Default for Sysinfo { fn default() -> Self { Self { + enabled: true, name: true, os_version: true, user: true, @@ -108,15 +111,16 @@ impl Default for Sysinfo { #[cfg(feature = "si")] impl Sysinfo { pub(crate) fn has_enabled(self) -> bool { - self.name - || self.os_version - || self.user - || self.memory - || self.cpu_vendor - || self.cpu_core_count - || self.cpu_name - || self.cpu_brand - || self.cpu_frequency + self.enabled + && (self.name + || self.os_version + || self.user + || self.memory + || self.cpu_vendor + || self.cpu_core_count + || self.cpu_name + || self.cpu_brand + || self.cpu_frequency) } } @@ -331,6 +335,111 @@ mod test { assert_eq!("GB", suffix(2)); assert_eq!("xB", suffix(3)); } + + #[test] + fn not_enabled() { + let mut config = Instructions::default(); + *config.sysinfo_mut().enabled_mut() = false; + assert!(!config.sysinfo().has_enabled()); + } + + #[test] + fn no_name() { + let mut config = Instructions::default(); + *config.sysinfo_mut().name_mut() = false; + assert!(config.sysinfo().has_enabled()); + } + + #[test] + fn no_os_version() { + let mut config = Instructions::default(); + *config.sysinfo_mut().name_mut() = false; + *config.sysinfo_mut().os_version_mut() = false; + assert!(config.sysinfo().has_enabled()); + } + + #[test] + fn no_user() { + let mut config = Instructions::default(); + *config.sysinfo_mut().name_mut() = false; + *config.sysinfo_mut().os_version_mut() = false; + *config.sysinfo_mut().user_mut() = false; + assert!(config.sysinfo().has_enabled()); + } + + #[test] + fn no_memory() { + let mut config = Instructions::default(); + *config.sysinfo_mut().name_mut() = false; + *config.sysinfo_mut().os_version_mut() = false; + *config.sysinfo_mut().user_mut() = false; + *config.sysinfo_mut().memory_mut() = false; + assert!(config.sysinfo().has_enabled()); + } + #[test] + fn no_cpu_vendor() { + let mut config = Instructions::default(); + *config.sysinfo_mut().name_mut() = false; + *config.sysinfo_mut().os_version_mut() = false; + *config.sysinfo_mut().user_mut() = false; + *config.sysinfo_mut().memory_mut() = false; + *config.sysinfo_mut().cpu_vendor_mut() = false; + assert!(config.sysinfo().has_enabled()); + } + + #[test] + fn no_cpu_core_count() { + let mut config = Instructions::default(); + *config.sysinfo_mut().name_mut() = false; + *config.sysinfo_mut().os_version_mut() = false; + *config.sysinfo_mut().user_mut() = false; + *config.sysinfo_mut().memory_mut() = false; + *config.sysinfo_mut().cpu_vendor_mut() = false; + *config.sysinfo_mut().cpu_core_count_mut() = false; + assert!(config.sysinfo().has_enabled()); + } + + #[test] + fn no_cpu_name() { + let mut config = Instructions::default(); + *config.sysinfo_mut().name_mut() = false; + *config.sysinfo_mut().os_version_mut() = false; + *config.sysinfo_mut().user_mut() = false; + *config.sysinfo_mut().memory_mut() = false; + *config.sysinfo_mut().cpu_vendor_mut() = false; + *config.sysinfo_mut().cpu_core_count_mut() = false; + *config.sysinfo_mut().cpu_name_mut() = false; + assert!(config.sysinfo().has_enabled()); + } + + #[test] + fn no_cpu_brand() { + let mut config = Instructions::default(); + *config.sysinfo_mut().name_mut() = false; + *config.sysinfo_mut().os_version_mut() = false; + *config.sysinfo_mut().user_mut() = false; + *config.sysinfo_mut().memory_mut() = false; + *config.sysinfo_mut().cpu_vendor_mut() = false; + *config.sysinfo_mut().cpu_core_count_mut() = false; + *config.sysinfo_mut().cpu_name_mut() = false; + *config.sysinfo_mut().cpu_brand_mut() = false; + assert!(config.sysinfo().has_enabled()); + } + + #[test] + fn nothing() { + let mut config = Instructions::default(); + *config.sysinfo_mut().name_mut() = false; + *config.sysinfo_mut().os_version_mut() = false; + *config.sysinfo_mut().user_mut() = false; + *config.sysinfo_mut().memory_mut() = false; + *config.sysinfo_mut().cpu_vendor_mut() = false; + *config.sysinfo_mut().cpu_core_count_mut() = false; + *config.sysinfo_mut().cpu_name_mut() = false; + *config.sysinfo_mut().cpu_brand_mut() = false; + *config.sysinfo_mut().cpu_frequency_mut() = false; + assert!(!config.sysinfo().has_enabled()); + } } #[cfg(all(test, not(feature = "si")))] diff --git a/src/gen.rs b/src/gen.rs index bda76dff..951dbe95 100644 --- a/src/gen.rs +++ b/src/gen.rs @@ -396,6 +396,17 @@ mod test { assert!(BUILD_REGEX_INST.is_match(&String::from_utf8_lossy(&stdout_buf))); } + #[cfg(feature = "build")] + #[test] + fn contains_no_build_output() { + let repo_path = PathBuf::from("."); + let mut stdout_buf = vec![]; + let mut instructions = Instructions::default(); + *instructions.build_mut().enabled_mut() = false; + assert!(config_from_instructions(instructions, Some(repo_path), &mut stdout_buf,).is_ok()); + assert!(!BUILD_REGEX_INST.is_match(&String::from_utf8_lossy(&stdout_buf))); + } + #[cfg(feature = "cargo")] #[test] #[serial_test::serial] @@ -413,6 +424,20 @@ mod test { teardown(); } + #[cfg(feature = "cargo")] + #[test] + #[serial_test::serial] + fn contains_no_cargo_output() { + setup(); + let repo_path = PathBuf::from("."); + let mut stdout_buf = vec![]; + let mut instructions = Instructions::default(); + *instructions.cargo_mut().enabled_mut() = false; + assert!(config_from_instructions(instructions, Some(repo_path), &mut stdout_buf,).is_ok()); + assert!(!CARGO_REGEX.is_match(&String::from_utf8_lossy(&stdout_buf))); + teardown(); + } + #[cfg(feature = "git")] #[test] fn contains_git_output() { @@ -428,6 +453,18 @@ mod test { assert!(GIT_RIC_REGEX.is_match(&String::from_utf8_lossy(&stdout_buf))); } + #[cfg(feature = "git")] + #[test] + fn contains_no_git_output() { + let repo_path = PathBuf::from("."); + let mut stdout_buf = vec![]; + let mut instructions = Instructions::default(); + *instructions.git_mut().enabled_mut() = false; + assert!(config_from_instructions(instructions, Some(repo_path), &mut stdout_buf,).is_ok()); + assert!(!GIT_REGEX_INST.is_match(&String::from_utf8_lossy(&stdout_buf))); + assert!(!GIT_RIC_REGEX.is_match(&String::from_utf8_lossy(&stdout_buf))); + } + #[cfg(feature = "rustc")] #[test] fn contains_rustc_output() { @@ -442,6 +479,17 @@ mod test { check_rustc_output(&stdout_buf); } + #[cfg(feature = "rustc")] + #[test] + fn contains_no_rustc_output() { + let repo_path = PathBuf::from("."); + let mut stdout_buf = vec![]; + let mut instructions = Instructions::default(); + *instructions.rustc_mut().enabled_mut() = false; + assert!(config_from_instructions(instructions, Some(repo_path), &mut stdout_buf,).is_ok()); + check_no_rustc_output(&stdout_buf); + } + #[cfg(feature = "si")] #[test] fn contains_sysinfo_output() { @@ -456,11 +504,27 @@ mod test { assert!(SYSINFO_REGEX_INST.is_match(&String::from_utf8_lossy(&stdout_buf))); } + #[cfg(feature = "si")] + #[test] + fn contains_no_sysinfo_output() { + let repo_path = PathBuf::from("."); + let mut stdout_buf = vec![]; + let mut instructions = Instructions::default(); + *instructions.sysinfo_mut().enabled_mut() = false; + assert!(config_from_instructions(instructions, Some(repo_path), &mut stdout_buf,).is_ok()); + assert!(!SYSINFO_REGEX_INST.is_match(&String::from_utf8_lossy(&stdout_buf))); + } + #[cfg(feature = "rustc")] fn check_rustc_output(stdout: &[u8]) { assert!(RUSTC_REGEX.is_match(&String::from_utf8_lossy(&stdout))); } + #[cfg(feature = "rustc")] + fn check_no_rustc_output(stdout: &[u8]) { + assert!(!RUSTC_REGEX.is_match(&String::from_utf8_lossy(&stdout))); + } + #[cfg(feature = "build")] #[test] fn build_local_timezone() {