- Added documentation for the Git module's test scripts, including test structure, running instructions, and details of each test. - Added links to Git module tests in the main Rhai documentation. - Improved overall structure and clarity of the Rhai documentation.
2.9 KiB
Git Module Tests
This document describes the test scripts for the Git module in the SAL library. These tests verify the functionality of the Git module's repository management and Git operations.
Test Structure
The tests are organized into two main scripts:
- Basic Git Operations (
01_git_basic.rhai
): Tests basic Git functionality like creating a GitTree, listing repositories, finding repositories, and cloning repositories. - Git Repository Operations (
02_git_operations.rhai
): Tests Git operations like pull, reset, commit, and push.
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/git/run_all_tests.rhai
To run individual test scripts:
herodo --path src/rhai_tests/git/01_git_basic.rhai
Test Details
Basic Git Operations Test
The basic Git operations test (01_git_basic.rhai
) verifies the following functions:
git_tree_new
: Creating a GitTreelist
: Listing repositories in a GitTreefind
: Finding repositories matching a patternget
: Getting or cloning a repositorypath
: Getting the path of a repositoryhas_changes
: Checking if a repository has changes
The test creates a temporary directory, performs operations on it, and then cleans up after itself.
Git Repository Operations Test
The Git repository operations test (02_git_operations.rhai
) verifies the following functions:
pull
: Pulling changes from a remote repositoryreset
: Resetting local changescommit
: Committing changes (method existence only)push
: Pushing changes to a remote repository (method existence only)
Note: The test does not actually commit or push changes to avoid modifying remote repositories. It only verifies that the methods exist and can be called.
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/git
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 Git module:
- Always clean up temporary files and directories
- 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 modify remote repositories
- Keep tests focused on specific functionality