|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +use std::process::Command; |
| 3 | + |
| 4 | +fn version_output(executable: &str, flag: &str) -> String { |
| 5 | + let output = Command::new(executable) |
| 6 | + .arg(flag) |
| 7 | + .output() |
| 8 | + .unwrap_or_else(|err| panic!("{executable} {flag} runs: {err}")); |
| 9 | + assert!( |
| 10 | + output.status.success(), |
| 11 | + "{executable} {flag} failed: {}", |
| 12 | + String::from_utf8_lossy(&output.stderr) |
| 13 | + ); |
| 14 | + String::from_utf8_lossy(&output.stdout).into_owned() |
| 15 | +} |
| 16 | + |
| 17 | +/// Both Coordinator executables report the version text the shared build |
| 18 | +/// identity decides, so a nightly build names its dated source identity and |
| 19 | +/// an unmarked build names a development version. The release scripts compare |
| 20 | +/// `--version` against that text before they stage a binary. |
| 21 | +#[test] |
| 22 | +fn both_executables_report_the_shared_build_identity() { |
| 23 | + for (name, executable) in [ |
| 24 | + ("coordinator", env!("CARGO_BIN_EXE_coordinator")), |
| 25 | + ("coordinatorctl", env!("CARGO_BIN_EXE_coordinatorctl")), |
| 26 | + ] { |
| 27 | + for flag in ["--version", "-V"] { |
| 28 | + assert_eq!( |
| 29 | + version_output(executable, flag), |
| 30 | + format!("{name} {}\n", registry_platform_buildinfo::DISPLAY_VERSION) |
| 31 | + ); |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +#[test] |
| 37 | +fn version_output_distinguishes_the_build_identity() { |
| 38 | + let expected = if registry_platform_buildinfo::IS_RELEASE_BUILD { |
| 39 | + env!("CARGO_PKG_VERSION").to_owned() |
| 40 | + } else if registry_platform_buildinfo::IS_NIGHTLY_BUILD { |
| 41 | + registry_platform_buildinfo::DISPLAY_VERSION.to_owned() |
| 42 | + } else { |
| 43 | + format!("{}-dev", env!("CARGO_PKG_VERSION")) |
| 44 | + }; |
| 45 | + assert_eq!( |
| 46 | + version_output(env!("CARGO_BIN_EXE_coordinator"), "--version"), |
| 47 | + format!("coordinator {expected}\n") |
| 48 | + ); |
| 49 | +} |
0 commit comments