Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions for tox crate version information #477

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tox_node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::<u32>().unwrap());
}

#[test]
fn crate_version_minor() {
let v = crate::crate_version_minor();
assert_eq!(v, env!("CARGO_PKG_VERSION_MINOR").parse::<u32>().unwrap());
}

#[test]
fn crate_version_patch() {
let v = crate::crate_version_patch();
assert_eq!(v, env!("CARGO_PKG_VERSION_PATCH").parse::<u32>().unwrap());
}
}