| 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 | |
| 6 | use std::process::Command; |
| 7 | |
| 8 | fn budctl(args: &[&str]) -> std::process::Output { |
| 9 | Command::new(env!("CARGO_BIN_EXE_budctl")).args(args).output().unwrap() |
| 10 | } |
| 11 | |
| 12 | #[test] |
| 13 | fn 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] |
| 22 | fn 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] |
| 30 | fn eq_new_and_rename_check_the_name_before_connecting() { |
| 31 | for args in [ |
| 32 | &["eq", "new"][..], |
| 33 | &["eq", "new", ""], |
| 34 | &["eq", "new", " Gym"], |
| 35 | &["eq", "new", "a\tb"], |
| 36 | &["eq", "rename", "custom-5"], |
| 37 | &["eq", "rename", "custom-5", ""], |
| 38 | ] { |
| 39 | let out = budctl(args); |
| 40 | assert_eq!(out.status.code(), Some(1), "{args:?}"); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | #[test] |
| 45 | fn find_start_needs_yes_before_connecting() { |
| 46 | let out = budctl(&["find", "start"]); |
| 47 | assert_eq!(out.status.code(), Some(1)); |
| 48 | assert!(String::from_utf8_lossy(&out.stderr).contains("--yes")); |
| 49 | } |
| 50 | |
| 51 | #[test] |
| 52 | fn touch_changes_need_side_gesture_and_action() { |
| 53 | for args in [ |
| 54 | &["touch", "left"][..], |
| 55 | &["touch", "left", "hold"], |
| 56 | &["touch", "--dry-run"], |
| 57 | &["touch", "middle", "hold", "none"], |
| 58 | ] { |
| 59 | let out = budctl(args); |
| 60 | assert_eq!(out.status.code(), Some(1), "{args:?}"); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | #[test] |
| 65 | fn the_hold_cycle_needs_two_or_three_known_modes() { |
| 66 | for args in [ |
| 67 | &["touch", "cycle"][..], |
| 68 | &["touch", "cycle", "anc"], |
| 69 | &["touch", "cycle", "anc", "deep"], |
| 70 | &["touch", "cycle", "off", "transparency", "anc", "off"], |
| 71 | &["touch", "cycle", "anc", "off", "--dry-run"], |
| 72 | ] { |
| 73 | let out = budctl(args); |
| 74 | assert_eq!(out.status.code(), Some(1), "{args:?}"); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | #[test] |
| 79 | fn bass_needs_a_level_from_minus_5_to_5() { |
| 80 | // Out of range fails while parsing, before anything connects. |
| 81 | for args in [ |
| 82 | &["bass"][..], |
| 83 | &["bass", "loud"], |
| 84 | &["bass", "300"], |
| 85 | &["bass", "6"], |
| 86 | &["bass", "-6"], |
| 87 | ] { |
| 88 | let out = budctl(args); |
| 89 | assert_eq!(out.status.code(), Some(1), "{args:?}"); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | #[test] |
| 94 | fn eq_bands_must_be_hz_equals_gain() { |
| 95 | for args in [ |
| 96 | &["eq", "custom-4", "50"][..], |
| 97 | &["eq", "custom-4", "fifty=3"], |
| 98 | &["eq", "custom-4", "50=loud"], |
| 99 | &["eq", "custom-4", "50=+3.5"], |
| 100 | &["eq", "custom-4", "50=300"], |
| 101 | ] { |
| 102 | let out = budctl(args); |
| 103 | assert_eq!(out.status.code(), Some(1), "{args:?}"); |
| 104 | } |
| 105 | } |