- Added documentation for the new Process module tests, including details on test structure, execution, and individual test descriptions. - Created new documentation files for Process module tests. - Updated the main Rhai documentation index to include the new Process module tests.
2.9 KiB
Process Module Tests
This document describes the test scripts for the Process module in the SAL library. These tests verify the functionality of the Process module's command execution and process management features.
Test Structure
The tests are organized into two main scripts:
- Command Execution (
01_command_execution.rhai
): Tests command execution functions likerun()
andwhich()
. - Process Management (
02_process_management.rhai
): Tests process management functions likeprocess_list()
andprocess_get()
.
Additionally, there's a runner script (run_all_tests.rhai
) that executes all tests and reports results. The runner script contains simplified versions of the individual tests to avoid dependency issues.
Running the Tests
To run all tests, execute the following command from the project root:
herodo --path src/rhai_tests/process/run_all_tests.rhai
To run individual test scripts:
herodo --path src/rhai_tests/process/01_command_execution.rhai
Test Details
Command Execution Test
The command execution test (01_command_execution.rhai
) verifies the following functions:
run()
: Running shell commandsrun().do()
: Executing commands and capturing outputrun().silent()
: Running commands without displaying outputrun().ignore_error()
: Running commands that might fail without throwing errorswhich()
: Finding the path of an executable
The test runs various commands and verifies their output and exit status.
Process Management Test
The process management test (02_process_management.rhai
) verifies the following functions:
process_list()
: Listing running processesprocess_get()
: Getting information about a specific process- Process properties: Accessing process information like PID, name, CPU usage, and memory usage
The test lists running processes and verifies that their properties are accessible.
Test Runner
The test runner script (run_all_tests.rhai
) provides a framework for executing all tests and reporting results. It:
- Contains simplified versions of each test
- Runs each test in a try/catch block to handle errors
- Catches and reports any errors
- Provides a summary of passed and failed tests
Adding New Tests
To add a new test:
- Create a new Rhai script in the
src/rhai_tests/process
directory - Add a new test section to the
run_all_tests.rhai
script - Update this documentation to include information about the new test
Best Practices for Writing Tests
When writing tests for the Process module:
- Use assertions to verify expected behavior
- Print clear messages about what's being tested
- Handle errors gracefully
- Make tests independent of each other
- Avoid tests that could disrupt the system (e.g., killing important processes)
- Keep tests focused on specific functionality
- Clean up any resources created during testing