sal/git/tests/rhai/run_all_tests.rhai
Mahmoud-Emad e031b03e04
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
feat: Convert SAL to a Rust monorepo
- Migrate SAL project from single-crate to monorepo structure
- Create independent packages for individual modules
- Improve build efficiency and testing capabilities
- Update documentation to reflect new structure
- Successfully convert the git module to an independent package.
2025-06-18 14:12:36 +03:00

130 lines
3.9 KiB
Plaintext

// run_all_tests.rhai
// Test runner for all Git module tests
// Custom assert function
fn assert_true(condition, message) {
if !condition {
print(`ASSERTION FAILED: ${message}`);
throw message;
}
}
// Test counters
let passed = 0;
let failed = 0;
print("=== Git Module Test Suite ===");
print("Running comprehensive tests for Git module functionality...");
// Test 1: Basic Git Operations
print("\n--- Running Basic Git Operations Tests ---");
try {
// Create a temporary directory for Git operations
let test_dir = "rhai_test_git";
mkdir(test_dir);
print(`Created test directory: ${test_dir}`);
// Test GitTree constructor
print("Testing GitTree constructor...");
let git_tree = git_tree_new(test_dir);
print("✓ GitTree created successfully");
// Test GitTree.list() with empty directory
print("Testing GitTree.list() with empty directory...");
let repos = git_tree.list();
assert_true(repos.len() == 0, "Expected empty list of repositories");
print(`✓ GitTree.list(): Found ${repos.len()} repositories (expected 0)`);
// Test GitTree.find() with empty directory
print("Testing GitTree.find() with empty directory...");
let found_repos = git_tree.find("*");
assert_true(found_repos.len() == 0, "Expected empty list of repositories");
print(`✓ GitTree.find(): Found ${found_repos.len()} repositories (expected 0)`);
// Clean up
print("Cleaning up...");
delete(test_dir);
assert_true(!exist(test_dir), "Directory deletion failed");
print(`✓ Cleanup: Directory ${test_dir} removed`);
print("--- Basic Git Operations Tests completed successfully ---");
passed += 1;
} catch(err) {
print(`!!! Error in Basic Git Operations Tests: ${err}`);
failed += 1;
}
// Test 2: Git Repository Operations
print("\n--- Running Git Repository Operations Tests ---");
try {
// Create a temporary directory for Git operations
let test_dir = "rhai_test_git_ops";
mkdir(test_dir);
print(`Created test directory: ${test_dir}`);
// Create a GitTree
print("Creating GitTree...");
let git_tree = git_tree_new(test_dir);
print("✓ GitTree created successfully");
// Clean up
print("Cleaning up...");
delete(test_dir);
assert_true(!exist(test_dir), "Directory deletion failed");
print(`✓ Cleanup: Directory ${test_dir} removed`);
print("--- Git Repository Operations Tests completed successfully ---");
passed += 1;
} catch(err) {
print(`!!! Error in Git Repository Operations Tests: ${err}`);
failed += 1;
}
// Test 3: Git Error Handling
print("\n--- Running Git Error Handling Tests ---");
try {
print("Testing git_clone with invalid URL...");
try {
git_clone("invalid-url");
print("!!! Expected error but got success");
failed += 1;
} catch(err) {
assert_true(err.contains("Git error"), "Expected Git error message");
print("✓ git_clone properly handles invalid URLs");
}
print("Testing GitTree with invalid path...");
try {
let git_tree = git_tree_new("/invalid/nonexistent/path");
print("Note: GitTree creation succeeded (directory was created)");
// Clean up if it was created
try {
delete("/invalid");
} catch(cleanup_err) {
// Ignore cleanup errors
}
} catch(err) {
print(`✓ GitTree properly handles invalid paths: ${err}`);
}
print("--- Git Error Handling Tests completed successfully ---");
passed += 1;
} catch(err) {
print(`!!! Error in Git Error Handling Tests: ${err}`);
failed += 1;
}
// Summary
print("\n=== Test Results ===");
print(`Passed: ${passed}`);
print(`Failed: ${failed}`);
print(`Total: ${passed + failed}`);
if failed == 0 {
print("🎉 All tests passed!");
} else {
print("❌ Some tests failed!");
}
print("=== Git Module Test Suite Complete ===");