diff --git a/Cargo.toml b/Cargo.toml index e2410e69..2e8548cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ description = "List system USB buses and devices; a modern and compatible `lsusb repository = "https://github.com/tuna-f1sh/cyme" readme = "README.md" license = "GPL-3.0-or-later" -version = "1.2.0" +version = "1.2.1" edition = "2021" keywords = ["usb", "lsusb", "system_profiler", "macos", "libusb"] categories = ["command-line-utilities"] diff --git a/src/config.rs b/src/config.rs index 8cfd43ad..bb3b48e7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -124,3 +124,20 @@ impl Config { dirs::config_dir().map(|x| x.join(CONF_DIR)) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_deserialize_example_file() { + let path = PathBuf::from("./doc").join("cyme_example_config.json"); + Config::from_file(path).unwrap(); + } + + #[test] + fn test_deserialize_config_no_theme() { + let path = PathBuf::from("./tests/data").join("config_no_theme.json"); + Config::from_file(path).unwrap(); + } +} diff --git a/src/display.rs b/src/display.rs index a307790f..58ad3574 100644 --- a/src/display.rs +++ b/src/display.rs @@ -599,9 +599,9 @@ impl Block for DeviceBlocks { format!("{:^pad$}", "TPos", pad = pad.get(self).unwrap_or(&0)) } // will be 000 mA = 6 - DeviceBlocks::BusPower => "BusPwr".into(), - DeviceBlocks::BusPowerUsed => "PwrUsd".into(), - DeviceBlocks::ExtraCurrentUsed => "PwrExr".into(), + DeviceBlocks::BusPower => "PBus".into(), + DeviceBlocks::BusPowerUsed => "PUsd".into(), + DeviceBlocks::ExtraCurrentUsed => "PExr".into(), // 00.00 = 5 DeviceBlocks::BcdDevice => "Dev V".into(), DeviceBlocks::BcdUsb => "USB V".into(), @@ -749,18 +749,18 @@ impl Block for ConfigurationBlocks { if verbose { vec![ ConfigurationBlocks::Number, - ConfigurationBlocks::Name, ConfigurationBlocks::IconAttributes, ConfigurationBlocks::Attributes, ConfigurationBlocks::NumInterfaces, ConfigurationBlocks::MaxPower, + ConfigurationBlocks::Name, ] } else { vec![ ConfigurationBlocks::Number, - ConfigurationBlocks::Name, ConfigurationBlocks::IconAttributes, ConfigurationBlocks::MaxPower, + ConfigurationBlocks::Name, ] } } @@ -841,7 +841,7 @@ impl Block for ConfigurationBlocks { match self { ConfigurationBlocks::Number => " #".into(), ConfigurationBlocks::NumInterfaces => "I#".into(), - ConfigurationBlocks::MaxPower => "MaxPwr".into(), + ConfigurationBlocks::MaxPower => "PMax".into(), ConfigurationBlocks::Name => { format!("{:^pad$}", "Name", pad = pad.get(self).unwrap_or(&0)) } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index bf0b65c3..c58fcc20 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -254,9 +254,16 @@ impl TestEnv { // Compare actual output to expected output. assert_json_diff::assert_json_include!(actual: json!(actual), expected: json!(expected)); - // if json!(actual) != json!(expected) { - // panic!("{}", format_output_error(&args, &expected, &actual)); - // } + } + + /// Parses output back to SPUSBDataType and checks device with `port_path` exists in it + pub fn assert_output_contains_port_path(&self, dump_file: Option<&str>, args: &[&str], port_path: &str) { + // Normalize both expected and actual output. + let output = self.assert_success_and_get_output(dump_file, args); + let actual = String::from_utf8_lossy(&output.stdout).to_string(); + let spdata_out = serde_json::from_str::(&actual).unwrap(); + + assert_eq!(spdata_out.get_node(port_path).is_some(), true); } /// Similar to assert_output, but able to handle non-utf8 output diff --git a/tests/data/config_no_theme.json b/tests/data/config_no_theme.json new file mode 100644 index 00000000..8564970e --- /dev/null +++ b/tests/data/config_no_theme.json @@ -0,0 +1,51 @@ +{ + "blocks": [ + "bus-number", + "device-number", + "icon", + "vendor-id", + "product-id", + "name", + "serial", + "speed" + ], + "bus-blocks": [ + "name", + "host-controller" + ], + "config-blocks": [ + "number", + "name", + "icon-attributes", + "max-power" + ], + "interface-blocks": [ + "port-path", + "icon", + "alt-setting", + "class-code", + "sub-class", + "protocol", + "name" + ], + "endpoint-blocks": [ + "number", + "direction", + "transfer-type", + "sync-type", + "usage-type", + "max-packet-size" + ], + "mask-serials": null, + "lsusb": false, + "tree": false, + "verbose": 0, + "more": false, + "hide-buses": false, + "hide-hubs": false, + "decimal": false, + "no-padding": false, + "ascii": false, + "headings": false, + "force-libusb": false +}