From c697b554d8d874418bee7e560fdc33edee969aa5 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 21 Nov 2023 13:05:02 +0100 Subject: [PATCH 1/4] Add functions for tox crate version information --- tox/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tox/src/lib.rs b/tox/src/lib.rs index 13912f1b..b39b0253 100644 --- a/tox/src/lib.rs +++ b/tox/src/lib.rs @@ -4,3 +4,16 @@ pub use tox_core as core; pub use tox_crypto as crypto; pub use tox_encryptsave as encryptsave; pub use tox_packet as packet; + +pub fn crate_version() -> String { + env!("CARGO_PKG_VERSION").to_string() +} +pub fn crate_version_major() -> u32 { + env!("CARGO_PKG_VERSION_MAJOR").parse().expect("Invalid major version") +} +pub fn crate_version_minor() -> u32 { + env!("CARGO_PKG_VERSION_MINOR").parse().expect("Invalid minor version") +} +pub fn crate_version_patch() -> u32 { + env!("CARGO_PKG_VERSION_PATCH").parse().expect("Invalid patch version") +} From 4d4ecdd603241d1f36ae640697c1e0bae4e81160 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Thu, 23 Nov 2023 10:36:04 +0100 Subject: [PATCH 2/4] Add crate version tests --- tox/src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tox/src/lib.rs b/tox/src/lib.rs index b39b0253..c508111e 100644 --- a/tox/src/lib.rs +++ b/tox/src/lib.rs @@ -17,3 +17,26 @@ pub fn crate_version_minor() -> u32 { pub fn crate_version_patch() -> u32 { env!("CARGO_PKG_VERSION_PATCH").parse().expect("Invalid patch version") } + +#[cfg(test)] +mod tests { + #[test] + fn crate_version_is_not_empty() { + assert_ne!(crate::crate_version(), ""); + } + + #[test] + fn crate_version_major() { + crate::crate_version_major(); + } + + #[test] + fn crate_version_minor() { + crate::crate_version_minor(); + } + + #[test] + fn crate_version_patch() { + crate::crate_version_patch(); + } +} From 6a5a935ccdd3b4af19e4dd5054f692c24fb94602 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 18 Dec 2023 12:45:07 +0100 Subject: [PATCH 3/4] Update tests and documentation for crate version features --- tox/src/lib.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tox/src/lib.rs b/tox/src/lib.rs index c508111e..c1469443 100644 --- a/tox/src/lib.rs +++ b/tox/src/lib.rs @@ -5,15 +5,19 @@ pub use tox_crypto as crypto; pub use tox_encryptsave as encryptsave; pub use tox_packet as packet; +/// The tox crate version string in the form "major.minor.patch" (e.g. "1.2.3") pub fn crate_version() -> String { env!("CARGO_PKG_VERSION").to_string() } +/// The tox crate major version represented as unsigned integer pub fn crate_version_major() -> u32 { env!("CARGO_PKG_VERSION_MAJOR").parse().expect("Invalid major version") } +/// The tox crate minor version represented as unsigned integer pub fn crate_version_minor() -> u32 { env!("CARGO_PKG_VERSION_MINOR").parse().expect("Invalid minor version") } +/// The tox crate patch version represented as unsigned integer pub fn crate_version_patch() -> u32 { env!("CARGO_PKG_VERSION_PATCH").parse().expect("Invalid patch version") } @@ -27,16 +31,19 @@ mod tests { #[test] fn crate_version_major() { - crate::crate_version_major(); + let v = crate::crate_version_major(); + assert_eq!(v, env!("CARGO_PKG_VERSION_MAJOR").parse::().unwrap()); } #[test] fn crate_version_minor() { - crate::crate_version_minor(); + let v = crate::crate_version_minor(); + assert_eq!(v, env!("CARGO_PKG_VERSION_MINOR").parse::().unwrap()); } #[test] fn crate_version_patch() { - crate::crate_version_patch(); + let v = crate::crate_version_patch(); + assert_eq!(v, env!("CARGO_PKG_VERSION_PATCH").parse::().unwrap()); } } From 04d5183cb444e70dd7eac8a75e6851327f9f8658 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Tue, 16 Jan 2024 20:20:58 +0100 Subject: [PATCH 4/4] Moved crate version info into tox_node context --- tox/src/lib.rs | 43 ------------------------------------------- tox_node/src/main.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/tox/src/lib.rs b/tox/src/lib.rs index c1469443..13912f1b 100644 --- a/tox/src/lib.rs +++ b/tox/src/lib.rs @@ -4,46 +4,3 @@ pub use tox_core as core; pub use tox_crypto as crypto; pub use tox_encryptsave as encryptsave; pub use tox_packet as packet; - -/// The tox crate version string in the form "major.minor.patch" (e.g. "1.2.3") -pub fn crate_version() -> String { - env!("CARGO_PKG_VERSION").to_string() -} -/// The tox crate major version represented as unsigned integer -pub fn crate_version_major() -> u32 { - env!("CARGO_PKG_VERSION_MAJOR").parse().expect("Invalid major version") -} -/// The tox crate minor version represented as unsigned integer -pub fn crate_version_minor() -> u32 { - env!("CARGO_PKG_VERSION_MINOR").parse().expect("Invalid minor version") -} -/// The tox crate patch version represented as unsigned integer -pub fn crate_version_patch() -> u32 { - env!("CARGO_PKG_VERSION_PATCH").parse().expect("Invalid patch version") -} - -#[cfg(test)] -mod tests { - #[test] - fn crate_version_is_not_empty() { - assert_ne!(crate::crate_version(), ""); - } - - #[test] - fn crate_version_major() { - let v = crate::crate_version_major(); - assert_eq!(v, env!("CARGO_PKG_VERSION_MAJOR").parse::().unwrap()); - } - - #[test] - fn crate_version_minor() { - let v = crate::crate_version_minor(); - assert_eq!(v, env!("CARGO_PKG_VERSION_MINOR").parse::().unwrap()); - } - - #[test] - fn crate_version_patch() { - let v = crate::crate_version_patch(); - assert_eq!(v, env!("CARGO_PKG_VERSION_PATCH").parse::().unwrap()); - } -} diff --git a/tox_node/src/main.rs b/tox_node/src/main.rs index 32dfa0a8..7c7c0e82 100644 --- a/tox_node/src/main.rs +++ b/tox_node/src/main.rs @@ -40,6 +40,23 @@ const ONION_CHANNEL_SIZE: usize = 32; /// Channel size for DHT packets. const DHT_CHANNEL_SIZE: usize = 32; +/// The tox crate version string in the form "major.minor.patch" (e.g. "1.2.3") +pub fn crate_version() -> String { + env!("CARGO_PKG_VERSION").to_string() +} +/// The tox crate major version represented as unsigned integer +pub fn crate_version_major() -> u32 { + env!("CARGO_PKG_VERSION_MAJOR").parse().expect("Invalid major version") +} +/// The tox crate minor version represented as unsigned integer +pub fn crate_version_minor() -> u32 { + env!("CARGO_PKG_VERSION_MINOR").parse().expect("Invalid minor version") +} +/// The tox crate patch version represented as unsigned integer +pub fn crate_version_patch() -> u32 { + env!("CARGO_PKG_VERSION_PATCH").parse().expect("Invalid patch version") +} + /// Get version in format 3AAABBBCCC, where A B and C are major, minor and patch /// versions of node. `tox-bootstrapd` uses similar scheme but with leading 1. /// Before it used format YYYYMMDDVV so the leading numeral was 2. To make a @@ -383,3 +400,29 @@ fn main() { run(future, config.threads); } + +#[cfg(test)] +mod tests { + #[test] + fn crate_version_is_not_empty() { + assert_ne!(crate::crate_version(), ""); + } + + #[test] + fn crate_version_major() { + let v = crate::crate_version_major(); + assert_eq!(v, env!("CARGO_PKG_VERSION_MAJOR").parse::().unwrap()); + } + + #[test] + fn crate_version_minor() { + let v = crate::crate_version_minor(); + assert_eq!(v, env!("CARGO_PKG_VERSION_MINOR").parse::().unwrap()); + } + + #[test] + fn crate_version_patch() { + let v = crate::crate_version_patch(); + assert_eq!(v, env!("CARGO_PKG_VERSION_PATCH").parse::().unwrap()); + } +}