summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2022-06-27 01:36:45 -0400
committerGitHub <noreply@github.com>2022-06-27 01:36:45 -0400
commit4ca68b621d26c61e1c4b4b6b3522ce5ac245b8ba (patch)
tree1894ff9b7223879992d70d0ada32d599373f404f /tests
parent6468f8af58fd32bc86f770a131990d8fde5a385d (diff)
ci: fix missing target in tests (#757)
Fix missing target parameter for primary test targets (e.g. aarch64), and adjust integration tests to work with cross.
Diffstat (limited to 'tests')
-rw-r--r--tests/arg_tests.rs37
-rw-r--r--tests/invalid_config_tests.rs34
-rw-r--r--tests/util.rs73
3 files changed, 105 insertions, 39 deletions
diff --git a/tests/arg_tests.rs b/tests/arg_tests.rs
index 95afb635..372955da 100644
--- a/tests/arg_tests.rs
+++ b/tests/arg_tests.rs
@@ -1,18 +1,13 @@
+//! These tests are mostly here just to ensure that invalid results will be caught when passing arguments.
use assert_cmd::prelude::*;
use predicates::prelude::*;
-use std::process::Command;
-// These tests are mostly here just to ensure that invalid results will be caught when passing arguments...
-
-//======================RATES======================//
-
-fn get_binary_location() -> String {
- env!("CARGO_BIN_EXE_btm").to_string()
-}
+mod util;
+use util::*;
#[test]
fn test_small_rate() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/empty_config.toml")
.arg("-r")
@@ -26,7 +21,7 @@ fn test_small_rate() {
#[test]
fn test_large_default_time() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/empty_config.toml")
.arg("-t")
@@ -38,7 +33,7 @@ fn test_large_default_time() {
#[test]
fn test_small_default_time() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/empty_config.toml")
.arg("-t")
@@ -52,7 +47,7 @@ fn test_small_default_time() {
#[test]
fn test_large_delta_time() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/empty_config.toml")
.arg("-d")
@@ -64,7 +59,7 @@ fn test_large_delta_time() {
#[test]
fn test_small_delta_time() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/empty_config.toml")
.arg("-d")
@@ -78,7 +73,7 @@ fn test_small_delta_time() {
#[test]
fn test_large_rate() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/empty_config.toml")
.arg("-r")
@@ -91,7 +86,7 @@ fn test_large_rate() {
#[test]
fn test_negative_rate() {
// This test should auto fail due to how clap works
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/empty_config.toml")
.arg("-r")
@@ -105,7 +100,7 @@ fn test_negative_rate() {
#[test]
fn test_invalid_rate() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/empty_config.toml")
.arg("-r")
@@ -117,7 +112,7 @@ fn test_invalid_rate() {
#[test]
fn test_conflicting_temps() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/empty_config.toml")
.arg("-c")
@@ -129,7 +124,7 @@ fn test_conflicting_temps() {
#[test]
fn test_invalid_default_widget_1() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/empty_config.toml")
.arg("--default_widget_type")
@@ -141,7 +136,7 @@ fn test_invalid_default_widget_1() {
#[test]
fn test_invalid_default_widget_2() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/empty_config.toml")
.arg("--default_widget_type")
@@ -157,7 +152,7 @@ fn test_invalid_default_widget_2() {
#[test]
fn test_missing_default_widget_type() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/empty_config.toml")
.arg("--default_widget_count")
@@ -172,7 +167,7 @@ fn test_missing_default_widget_type() {
#[test]
fn test_battery_flag() {
if !cfg!(feature = "battery") {
- Command::new(get_binary_location())
+ btm_command()
.arg("--battery")
.assert()
.failure()
diff --git a/tests/invalid_config_tests.rs b/tests/invalid_config_tests.rs
index ca3f7e24..65bdaa1f 100644
--- a/tests/invalid_config_tests.rs
+++ b/tests/invalid_config_tests.rs
@@ -1,16 +1,14 @@
use assert_cmd::prelude::*;
use predicates::prelude::*;
-use std::process::Command;
-// These tests are for testing some config file-specific options.
+mod util;
+use util::*;
-fn get_binary_location() -> String {
- env!("CARGO_BIN_EXE_btm").to_string()
-}
+// These tests are for testing some config file-specific options.
#[test]
fn test_toml_mismatch_type() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/toml_mismatch_type.toml")
.assert()
@@ -20,7 +18,7 @@ fn test_toml_mismatch_type() {
#[test]
fn test_empty_layout() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/empty_layout.toml")
.assert()
@@ -30,7 +28,7 @@ fn test_empty_layout() {
#[test]
fn test_invalid_layout_widget_type() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/invalid_layout_widget_type.toml")
.assert()
@@ -42,7 +40,7 @@ fn test_invalid_layout_widget_type() {
/// However, I feel like it's worth checking anyways - not like it takes long.
#[test]
fn test_duplicate_temp_type() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/duplicate_temp_type.toml")
.assert()
@@ -53,7 +51,7 @@ fn test_duplicate_temp_type() {
/// Checks for if a hex is valid
#[test]
fn test_invalid_colour_hex() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/invalid_colour_hex.toml")
.assert()
@@ -64,7 +62,7 @@ fn test_invalid_colour_hex() {
/// Checks for if a hex is too long
#[test]
fn test_invalid_colour_hex_2() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/invalid_colour_hex_2.toml")
.assert()
@@ -76,7 +74,7 @@ fn test_invalid_colour_hex_2() {
/// boundary errors!
#[test]
fn test_invalid_colour_hex_3() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/invalid_colour_hex_3.toml")
.assert()
@@ -86,7 +84,7 @@ fn test_invalid_colour_hex_3() {
#[test]
fn test_invalid_colour_name() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/invalid_colour_name.toml")
.assert()
@@ -96,7 +94,7 @@ fn test_invalid_colour_name() {
#[test]
fn test_invalid_colour_rgb() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/invalid_colour_rgb.toml")
.assert()
@@ -106,7 +104,7 @@ fn test_invalid_colour_rgb() {
#[test]
fn test_invalid_colour_rgb_2() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/invalid_colour_rgb_2.toml")
.assert()
@@ -116,7 +114,7 @@ fn test_invalid_colour_rgb_2() {
#[test]
fn test_invalid_colour_string() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/invalid_colour_string.toml")
.assert()
@@ -126,7 +124,7 @@ fn test_invalid_colour_string() {
#[test]
fn test_lone_default_widget_count() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/lone_default_widget_count.toml")
.assert()
@@ -136,7 +134,7 @@ fn test_lone_default_widget_count() {
#[test]
fn test_invalid_default_widget_count() {
- Command::new(get_binary_location())
+ btm_command()
.arg("-C")
.arg("./tests/invalid_configs/invalid_default_widget_count.toml")
.assert()
diff --git a/tests/util.rs b/tests/util.rs
new file mode 100644
index 00000000..0e74eafa
--- /dev/null
+++ b/tests/util.rs
@@ -0,0 +1,73 @@
+use std::{collections::HashMap, env, process::Command};
+
+/// Returns a QEMU runner target given an architecture.
+fn get_qemu_target(arch: &str) -> &str {
+ match arch {
+ "armv7" => "arm",
+ "i686" => "i386",
+ "powerpc" => "ppc",
+ "powerpc64le" => "ppc64le",
+ _ => arch,
+ }
+}
+
+/// This is required since running binary tests via cross can cause be tricky! We need to basically "magically" grab
+/// the correct runner in some cases, which can be done by inspecting env variables that should only show up while
+/// using cross.
+///
+/// Originally inspired by [ripgrep's test files](https://cs.github.com/BurntSushi/ripgrep/blob/9f0e88bcb14e02da1b88872435b17d74786640b5/tests/util.rs#L470),
+/// but adapted to work more generally with the architectures supported by bottom after looking through cross'
+/// [linux-runner](https://github.com/cross-rs/cross/blob/main/docker/linux-runner) file.
+fn cross_runner() -> Option<String> {
+ const TARGET_RUNNER: &str = "CARGO_TARGET_RUNNER";
+ const CROSS_RUNNER: &str = "CROSS_RUNNER";
+
+ let env_mapping = std::env::vars_os()
+ .filter_map(|(k, v)| {
+ let (k, v) = (k.to_string_lossy(), v.to_string_lossy());
+
+ if k.starts_with("CARGO_TARGET_") && k.ends_with("_RUNNER") && !v.is_empty() {
+ Some((TARGET_RUNNER.to_string(), v.to_string()))
+ } else if k == CROSS_RUNNER && !v.is_empty() {
+ Some((k.to_string(), v.to_string()))
+ } else {
+ None
+ }
+ })
+ .collect::<HashMap<_, _>>();
+
+ if let Some(cross_runner) = env_mapping.get(CROSS_RUNNER) {
+ if cross_runner == "qemu-user" {
+ env_mapping.get(TARGET_RUNNER).map(|target_runner| {
+ format!(
+ "qemu-{}",
+ get_qemu_target(
+ target_runner
+ .split_ascii_whitespace()
+ .collect::<Vec<_>>()
+ .last()
+ .unwrap()
+ )
+ )
+ })
+ } else {
+ None
+ }
+ } else {
+ env_mapping.get(TARGET_RUNNER).cloned()
+ }
+}
+
+/// Returns the [`Command`] of a binary invocation of bottom.
+///
+pub fn btm_command() -> Command {
+ let btm_exe = env!("CARGO_BIN_EXE_btm");
+ match cross_runner() {
+ None => Command::new(btm_exe),
+ Some(runner) => {
+ let mut cmd = Command::new(runner);
+ cmd.arg(btm_exe);
+ cmd
+ }
+ }
+}