// 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 and Real Functionality print("\n--- Running Git Error Handling and Real Functionality Tests ---"); try { print("Testing git_clone with invalid URL..."); try { git_clone("invalid-url-format"); 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 git_clone with real repository..."); try { let repo = git_clone("https://github.com/octocat/Hello-World.git"); let path = repo.path(); assert_true(path.len() > 0, "Repository path should not be empty"); print(`✓ git_clone successfully cloned repository to: ${path}`); // Test repository operations print("Testing repository operations..."); let has_changes = repo.has_changes(); print(`✓ Repository has_changes check: ${has_changes}`); } catch(err) { // Network issues or git not available are acceptable failures if err.contains("Git error") || err.contains("command") || err.contains("Failed to clone") { print(`Note: git_clone test skipped due to environment: ${err}`); } else { print(`!!! Unexpected error in git_clone: ${err}`); failed += 1; } } 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 ===");