mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust: Run rustfmt with some experimental options
+ Sort and group the imports + Normalize and format comments (100 characters width) Command used: $ cargo +nightly fmt -- Acked-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Marc Hartmayer <marc@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
3d5f75d6c3
commit
f8fb9ce32a
@@ -4,11 +4,12 @@
|
||||
|
||||
//! Handlers for processing CLI flags and subcommands
|
||||
|
||||
use std::io::{self, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::constants::*;
|
||||
use crate::io_utils::{collect_bit_messages, collect_version_flags, read_hex_from_file};
|
||||
use crate::strings::*;
|
||||
use std::io::{self, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
// Represents metadata for a supported content file.
|
||||
struct Content {
|
||||
@@ -18,7 +19,7 @@ struct Content {
|
||||
}
|
||||
|
||||
impl Content {
|
||||
//Reads a hex file, then prints either:
|
||||
// Reads a hex file, then prints either:
|
||||
// bit messages or version flags
|
||||
fn handle_flag(&self, writer: &mut dyn Write, query_dir: &Path) -> io::Result<String> {
|
||||
let hex = match read_hex_from_file(query_dir.join(self.file), self.label) {
|
||||
@@ -132,10 +133,12 @@ pub fn handle_supported_flags(
|
||||
// Unit Tests for handlers
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use std::fs;
|
||||
|
||||
use tempfile::tempdir;
|
||||
|
||||
use super::*;
|
||||
|
||||
// Verifies that handle_supported_flags correctly processes all
|
||||
#[test]
|
||||
fn test_handle_supported_flags_with_buffer() {
|
||||
|
||||
@@ -4,14 +4,15 @@
|
||||
|
||||
//! I/O utilities for the PV Info Tool
|
||||
|
||||
use crate::constants::*;
|
||||
use anyhow::{Context, Result};
|
||||
use pv_core::misc::{read_file, read_file_string, try_parse_u64};
|
||||
use pv_core::misc::{Flags, Msb0Flags64};
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::str;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use pv_core::misc::{read_file, read_file_string, try_parse_u64, Flags, Msb0Flags64};
|
||||
|
||||
use crate::constants::*;
|
||||
|
||||
// Verify that the Ultravisor directory exists
|
||||
pub fn check_uv_exists() -> Result<()> {
|
||||
let uv_path = Path::new(BASE_DIR);
|
||||
@@ -143,11 +144,13 @@ pub fn collect_limits(query_dir: &Path) -> HashMap<String, u64> {
|
||||
mod test {
|
||||
//! Unit Tests for io_utils
|
||||
|
||||
use super::*;
|
||||
use std::io::{self, Write};
|
||||
use std::path::Path;
|
||||
|
||||
use tempfile::{tempdir, NamedTempFile};
|
||||
|
||||
use super::*;
|
||||
|
||||
// Tests check_uv_exists() by observing the real BASE_DIR at test runtime
|
||||
// if BASE_DIR exists on the machine running the tests, check_uv_exists() must return Ok
|
||||
// otherwise, it must return Err(anyhow::Error) whose cause is an io::ErrorKind::NotFound,
|
||||
@@ -280,7 +283,8 @@ mod test {
|
||||
let hex = (1u64 << 63) | (1u64 << 61);
|
||||
let messages = collect_bit_messages(hex, desc);
|
||||
|
||||
// Expect "First Feature" and "Third Feature" (and the reserved line should get the " Bit-<index>" if matched)
|
||||
// Expect "First Feature" and "Third Feature" (and the reserved line should get the "
|
||||
// Bit-<index>" if matched)
|
||||
assert!(messages.iter().any(|m| m == "First Feature"));
|
||||
assert!(messages.iter().any(|m| m == "Third Feature"));
|
||||
// reserved wasn't set here; now test reserved specifically below
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
|
||||
//! Main function for the PV Info Tool
|
||||
|
||||
use std::io::{self, Write};
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use std::io::{self, Write};
|
||||
|
||||
mod cli;
|
||||
mod constants;
|
||||
@@ -16,13 +17,14 @@ mod pvinfo;
|
||||
mod se_status;
|
||||
mod strings;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::cli::{CliOptions, Commands, OutputFormat};
|
||||
use crate::constants::*;
|
||||
use crate::handlers::handle_supported_flags;
|
||||
use crate::io_utils::check_uv_exists;
|
||||
use crate::pvinfo::PvInfo;
|
||||
use crate::se_status::SeStatus;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// Parse CLI arguments and apply post-processing
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
|
||||
//! PV Info method implementation for the PV Info Tool
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::path::Path;
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::cli::CliOptions;
|
||||
use crate::constants::*;
|
||||
use crate::io_utils::{
|
||||
@@ -12,10 +18,6 @@ use crate::io_utils::{
|
||||
};
|
||||
use crate::se_status::*;
|
||||
use crate::strings::*;
|
||||
use serde::Serialize;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct PvInfo {
|
||||
@@ -262,9 +264,10 @@ impl fmt::Display for PvInfo {
|
||||
mod test {
|
||||
//! Unit Tests for pvinfo_method
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::*;
|
||||
use crate::se_status::SeStatus;
|
||||
use std::collections::HashMap;
|
||||
|
||||
// Test that Display for PvInfo produces a truly empty string
|
||||
// when all optional fields are None/
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
|
||||
//! se-status definitions for the PV Info Tool
|
||||
|
||||
use serde::Serialize; // Trait for serializing data structures (e.g., YAML)
|
||||
use std::fmt; // Provides the `Display` trait for pretty-printing
|
||||
use std::fmt;
|
||||
|
||||
use serde::Serialize; // Trait for serializing data structures (e.g., YAML) // Provides the `Display` trait for pretty-printing
|
||||
|
||||
/// Enum representing Secure Execution status
|
||||
|
||||
@@ -67,8 +68,8 @@ mod test {
|
||||
use super::SeStatus;
|
||||
|
||||
// Display implementation tests
|
||||
// Verifies that each enum variant of SeStatus is converted into the expected human-readable string
|
||||
// via the Display trait implementation
|
||||
// Verifies that each enum variant of SeStatus is converted into the expected human-readable
|
||||
// string via the Display trait implementation
|
||||
|
||||
#[test]
|
||||
fn test_display_strings() {
|
||||
|
||||
Reference in New Issue
Block a user