Krolyxon
Branch master

Branches

Refs →

budctlcratesbudctl-clitestscli.rs

113 lines · 3.2 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 // Never the real ~/.config: budctl writes a default config there.
10 Command::new(env!("CARGO_BIN_EXE_budctl"))
11 .env("XDG_CONFIG_HOME", env!("CARGO_TARGET_TMPDIR"))
12 .args(args)
13 .output()
14 .unwrap()
15}
16
17#[test]
18fn help_and_version_exit_0() {
19 for flag in ["--help", "--version"] {
20 let out = budctl(&[flag]);
21 assert_eq!(out.status.code(), Some(0), "{flag}");
22 assert!(!out.stdout.is_empty(), "{flag}");
23 }
24}
25
26#[test]
27fn usage_errors_exit_1() {
28 for args in [&["frobnicate"][..], &[], &["--device", "not-a-mac", "status"]] {
29 let out = budctl(args);
30 assert_eq!(out.status.code(), Some(1), "{args:?}");
31 }
32}
33
34#[test]
35fn eq_new_and_rename_check_the_name_before_connecting() {
36 for args in [
37 &["eq", "new"][..],
38 &["eq", "new", ""],
39 &["eq", "new", " Gym"],
40 &["eq", "new", "a\tb"],
41 &["eq", "rename", "custom-5"],
42 &["eq", "rename", "custom-5", ""],
43 &["eq", "delete"],
44 ] {
45 let out = budctl(args);
46 assert_eq!(out.status.code(), Some(1), "{args:?}");
47 }
48}
49
50#[test]
51fn find_start_needs_yes_before_connecting() {
52 let out = budctl(&["find", "start"]);
53 assert_eq!(out.status.code(), Some(1));
54 assert!(String::from_utf8_lossy(&out.stderr).contains("--yes"));
55}
56
57#[test]
58fn touch_changes_need_side_gesture_and_action() {
59 for args in [
60 &["touch", "left"][..],
61 &["touch", "left", "hold"],
62 &["touch", "--dry-run"],
63 &["touch", "middle", "hold", "none"],
64 ] {
65 let out = budctl(args);
66 assert_eq!(out.status.code(), Some(1), "{args:?}");
67 }
68}
69
70#[test]
71fn the_hold_cycle_needs_two_or_three_known_modes() {
72 for args in [
73 &["touch", "cycle"][..],
74 &["touch", "cycle", "anc"],
75 &["touch", "cycle", "anc", "deep"],
76 &["touch", "cycle", "off", "transparency", "anc", "off"],
77 &["touch", "cycle", "anc", "off", "--dry-run"],
78 ] {
79 let out = budctl(args);
80 assert_eq!(out.status.code(), Some(1), "{args:?}");
81 }
82}
83
84#[test]
85fn bass_needs_a_band_and_a_level_from_minus_5_to_5() {
86 // A missing band, or a level out of range, fails while parsing, before anything connects.
87 for args in [
88 &["bass"][..],
89 &["bass", "3"],
90 &["bass", "loud", "3"],
91 &["bass", "low"],
92 &["bass", "low", "300"],
93 &["bass", "low", "6"],
94 &["bass", "high", "-6"],
95 ] {
96 let out = budctl(args);
97 assert_eq!(out.status.code(), Some(1), "{args:?}");
98 }
99}
100
101#[test]
102fn eq_bands_must_be_hz_equals_gain() {
103 for args in [
104 &["eq", "custom-4", "50"][..],
105 &["eq", "custom-4", "fifty=3"],
106 &["eq", "custom-4", "50=loud"],
107 &["eq", "custom-4", "50=+3.5"],
108 &["eq", "custom-4", "50=300"],
109 ] {
110 let out = budctl(args);
111 assert_eq!(out.status.code(), Some(1), "{args:?}");
112 }
113}