Krolyxon
Commit 59f791a

Branches

Refs →

budctlcratesbudctl-clitestscli.rs

90 lines · 2.5 KB · Rust

1//! Exit codes that need no Bluetooth (CLAUDE.md, "Exit codes").
2
3// Test-only file: helpers may panic (clippy.toml exempts only #[test] functions themselves).
4#![allow(clippy::unwrap_used, clippy::expect_used, clippy::indexing_slicing)]
5
6use std::process::Command;
7
8fn budctl(args: &[&str]) -> std::process::Output {
9 Command::new(env!("CARGO_BIN_EXE_budctl")).args(args).output().unwrap()
10}
11
12#[test]
13fn help_and_version_exit_0() {
14 for flag in ["--help", "--version"] {
15 let out = budctl(&[flag]);
16 assert_eq!(out.status.code(), Some(0), "{flag}");
17 assert!(!out.stdout.is_empty(), "{flag}");
18 }
19}
20
21#[test]
22fn usage_errors_exit_1() {
23 for args in [&["frobnicate"][..], &[], &["--device", "not-a-mac", "status"]] {
24 let out = budctl(args);
25 assert_eq!(out.status.code(), Some(1), "{args:?}");
26 }
27}
28
29#[test]
30fn find_start_needs_yes_before_connecting() {
31 let out = budctl(&["find", "start"]);
32 assert_eq!(out.status.code(), Some(1));
33 assert!(String::from_utf8_lossy(&out.stderr).contains("--yes"));
34}
35
36#[test]
37fn touch_changes_need_side_gesture_and_action() {
38 for args in [
39 &["touch", "left"][..],
40 &["touch", "left", "hold"],
41 &["touch", "--dry-run"],
42 &["touch", "middle", "hold", "none"],
43 ] {
44 let out = budctl(args);
45 assert_eq!(out.status.code(), Some(1), "{args:?}");
46 }
47}
48
49#[test]
50fn the_hold_cycle_needs_two_or_three_known_modes() {
51 for args in [
52 &["touch", "cycle"][..],
53 &["touch", "cycle", "anc"],
54 &["touch", "cycle", "anc", "deep"],
55 &["touch", "cycle", "off", "transparency", "anc", "off"],
56 &["touch", "cycle", "anc", "off", "--dry-run"],
57 ] {
58 let out = budctl(args);
59 assert_eq!(out.status.code(), Some(1), "{args:?}");
60 }
61}
62
63#[test]
64fn bass_needs_a_level_from_minus_5_to_5() {
65 // Out of range fails while parsing, before anything connects.
66 for args in [
67 &["bass"][..],
68 &["bass", "loud"],
69 &["bass", "300"],
70 &["bass", "6"],
71 &["bass", "-6"],
72 ] {
73 let out = budctl(args);
74 assert_eq!(out.status.code(), Some(1), "{args:?}");
75 }
76}
77
78#[test]
79fn eq_bands_must_be_hz_equals_gain() {
80 for args in [
81 &["eq", "custom-4", "50"][..],
82 &["eq", "custom-4", "fifty=3"],
83 &["eq", "custom-4", "50=loud"],
84 &["eq", "custom-4", "50=+3.5"],
85 &["eq", "custom-4", "50=300"],
86 ] {
87 let out = budctl(args);
88 assert_eq!(out.status.code(), Some(1), "{args:?}");
89 }
90}