#!/bin/bash # Test: samios CLI tool # Validates the CLI script's syntax, help, version, status, and error handling. # We test the script at packaging/archiso/airootfs/usr/local/bin/samios # (the installed script), not the one embedded in samios-desktop-setup.sh. source "$(dirname "$0")/test_helper.sh" suite "samios CLI tests" SAMIOS_CLI="$PROFILE_DIR/airootfs/usr/local/bin/samios" assert_file_exists "samios CLI exists" "$SAMIOS_CLI" assert "samios CLI has valid bash syntax" \ bash -n "$SAMIOS_CLI" assert "samios CLI is executable" \ bash -c "[ -x '$SAMIOS_CLI' ]" assert "samios CLI starts with bash shebang" \ bash -c 'head -1 "'"$SAMIOS_CLI"'" | grep -q "#!/bin/bash"' # --------------------------------------------------------------------------- # --help / help / -h # --------------------------------------------------------------------------- assert_cmd_output_contains "samios --help shows usage" "Usage" \ bash "$SAMIOS_CLI" --help assert_cmd_output_contains "samios help shows Usage" "Usage" \ bash "$SAMIOS_CLI" help assert_cmd_output_contains "samios -h shows Usage" "Usage" \ bash "$SAMIOS_CLI" -h assert_cmd_output_contains "samios help lists 'version' command" "version" \ bash "$SAMIOS_CLI" help assert_cmd_output_contains "samios help lists 'status' command" "status" \ bash "$SAMIOS_CLI" help # --------------------------------------------------------------------------- # version # --------------------------------------------------------------------------- assert_cmd_output_contains "samios version outputs 'SamiOS v'" "SamiOS v" \ bash "$SAMIOS_CLI" version assert_cmd_output_contains "samios version outputs Kernel info" "Kernel:" \ bash "$SAMIOS_CLI" version assert_cmd_output_contains "samios version outputs Architecture info" "Architecture:" \ bash "$SAMIOS_CLI" version # --------------------------------------------------------------------------- # status (may fail in CI if commands like 'ip' aren't installed, so we use || true) # --------------------------------------------------------------------------- assert_cmd_output_contains "samios status shows system status header" "System Status" \ bash "$SAMIOS_CLI" status assert_cmd_output_contains "samios status shows Disk Usage" "Disk" \ bash "$SAMIOS_CLI" status assert_cmd_output_contains "samios status shows Memory section" "Memory" \ bash "$SAMIOS_CLI" status # --------------------------------------------------------------------------- # fonts # --------------------------------------------------------------------------- assert_cmd_output_contains "samios fonts shows font count" "fonts installed" \ bash "$SAMIOS_CLI" fonts assert_cmd_output_contains "samios fonts mentions font policy" "Font Policy" \ bash "$SAMIOS_CLI" fonts assert "samios fonts mentions 7777 exclusion" \ bash -c ' output="$(bash "'"$SAMIOS_CLI"'" fonts 2>&1)" || true echo "$output" | grep -q "7777" ' # --------------------------------------------------------------------------- # unknown command # --------------------------------------------------------------------------- assert_exit_code "samios with unknown command exits non-zero" 1 \ bash "$SAMIOS_CLI" nonexistentcommand assert_cmd_output_contains "samios unknown cmd shows error" "Unknown command" \ bash "$SAMIOS_CLI" nonexistentcommand # --------------------------------------------------------------------------- # No-arg invocation defaults to help # --------------------------------------------------------------------------- assert_cmd_output_contains "samios with no args shows Usage" "Usage" \ bash "$SAMIOS_CLI" print_summary