From 5d35f109582e160df7d778698e4a9f65d00501ed Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Thu, 12 Mar 2026 00:36:03 +0545 Subject: [PATCH] feat(tests): add CLI and GPU command tests Add tests for CLI argument parsing and GPU command generation to increase coverage and ensure future changes don't break functionality. New Features - Add unit test `verify_cli` to ensure Clap command is built correctly. - Add unit tests for `xorg_intel`, `xorg_amd`, and `generate_xrandr_script` functions. - Validate that generated Xrandr scripts contain expected provider settings. Enhancements - none Bug Fixes - none --- tests/cli.rs | 7 +++++++ tests/gpu.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/cli.rs create mode 100644 tests/gpu.rs diff --git a/tests/cli.rs b/tests/cli.rs new file mode 100644 index 0000000..ac46dd7 --- /dev/null +++ b/tests/cli.rs @@ -0,0 +1,7 @@ +use clap::CommandFactory; +use lapctl::cli::Cli; + +#[test] +fn verify_cli() { + Cli::command().debug_assert(); +} diff --git a/tests/gpu.rs b/tests/gpu.rs new file mode 100644 index 0000000..ee71c2b --- /dev/null +++ b/tests/gpu.rs @@ -0,0 +1,29 @@ +use lapctl::commands::gpu::{generate_xrandr_script, xorg_amd, xorg_intel}; + +#[test] +fn test_xorg_intel_generation() { + let output = xorg_intel("01:00.0"); + assert!(output.contains(r#"Identifier "intel""#)); + assert!(output.contains(r#"BusID "01:00.0""#)); +} + +#[test] +fn test_xorg_amd_generation() { + let output = xorg_amd("02:00.0"); + assert!(output.contains(r#"Identifier "amdgpu""#)); + assert!(output.contains(r#"BusID "02:00.0""#)); +} + +#[test] +fn test_xrandr_script() { + let intel_str = "intel".to_string(); + let script_with_intel = generate_xrandr_script(Some(&intel_str)); + assert!( + script_with_intel.contains(r#"xrandr --setprovideroutputsource "modesetting" NVIDIA-0"#) + ); + + let script_without_igpu = generate_xrandr_script(None); + assert!( + script_without_igpu.contains(r#"xrandr --setprovideroutputsource "modesetting" NVIDIA-0"#) + ); +}