...
This commit is contained in:
		
							
								
								
									
										70
									
								
								packages/system/git/tests/rhai/01_git_basic.rhai
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								packages/system/git/tests/rhai/01_git_basic.rhai
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,70 @@
 | 
			
		||||
// 01_git_basic.rhai
 | 
			
		||||
// Tests for basic Git functionality like creating a GitTree, listing repositories, finding repositories, and cloning repositories
 | 
			
		||||
 | 
			
		||||
// Custom assert function
 | 
			
		||||
fn assert_true(condition, message) {
 | 
			
		||||
    if !condition {
 | 
			
		||||
        print(`ASSERTION FAILED: ${message}`);
 | 
			
		||||
        throw message;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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)`);
 | 
			
		||||
 | 
			
		||||
// Test GitTree.get() with a URL to clone a repository
 | 
			
		||||
// We'll use a small, public repository for testing
 | 
			
		||||
print("Testing GitTree.get() with URL...");
 | 
			
		||||
let repo_url = "https://github.com/rhaiscript/playground.git";
 | 
			
		||||
let repo = git_tree.get(repo_url);
 | 
			
		||||
print(`✓ GitTree.get(): Repository cloned successfully to ${repo.path()}`);
 | 
			
		||||
 | 
			
		||||
// Test GitRepo.path()
 | 
			
		||||
print("Testing GitRepo.path()...");
 | 
			
		||||
let repo_path = repo.path();
 | 
			
		||||
assert_true(repo_path.contains(test_dir), "Repository path should contain test directory");
 | 
			
		||||
print(`✓ GitRepo.path(): ${repo_path}`);
 | 
			
		||||
 | 
			
		||||
// Test GitRepo.has_changes()
 | 
			
		||||
print("Testing GitRepo.has_changes()...");
 | 
			
		||||
let has_changes = repo.has_changes();
 | 
			
		||||
print(`✓ GitRepo.has_changes(): ${has_changes}`);
 | 
			
		||||
 | 
			
		||||
// Test GitTree.list() after cloning
 | 
			
		||||
print("Testing GitTree.list() after cloning...");
 | 
			
		||||
let repos_after_clone = git_tree.list();
 | 
			
		||||
assert_true(repos_after_clone.len() > 0, "Expected non-empty list of repositories");
 | 
			
		||||
print(`✓ GitTree.list(): Found ${repos_after_clone.len()} repositories`);
 | 
			
		||||
 | 
			
		||||
// Test GitTree.find() after cloning
 | 
			
		||||
print("Testing GitTree.find() after cloning...");
 | 
			
		||||
let found_repos_after_clone = git_tree.find("*");
 | 
			
		||||
assert_true(found_repos_after_clone.len() > 0, "Expected non-empty list of repositories");
 | 
			
		||||
print(`✓ GitTree.find(): Found ${found_repos_after_clone.len()} repositories`);
 | 
			
		||||
 | 
			
		||||
// Clean up
 | 
			
		||||
print("Cleaning up...");
 | 
			
		||||
delete(test_dir);
 | 
			
		||||
assert_true(!exist(test_dir), "Directory deletion failed");
 | 
			
		||||
print(`✓ Cleanup: Directory ${test_dir} removed`);
 | 
			
		||||
 | 
			
		||||
print("All basic Git tests completed successfully!");
 | 
			
		||||
		Reference in New Issue
	
	Block a user