Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
- Add new `sal-rhai` crate for Rhai scripting integration - Integrate Rhai with existing SAL modules - Improve error handling for Rhai scripts and SAL functions - Add comprehensive unit and integration tests for `sal-rhai`
137 lines
3.7 KiB
Plaintext
137 lines
3.7 KiB
Plaintext
// Simple SAL Rhai Integration Test
|
|
// Tests that all major SAL modules are working
|
|
|
|
print("🧪 SAL Rhai Integration - Simple Test");
|
|
print("=====================================");
|
|
|
|
let tests_passed = 0;
|
|
let total_tests = 0;
|
|
|
|
// Test 1: OS Module
|
|
total_tests += 1;
|
|
print("Test 1: OS Module - File existence check");
|
|
try {
|
|
let result = exist("Cargo.toml");
|
|
if result {
|
|
print(" ✓ PASSED - Cargo.toml exists");
|
|
tests_passed += 1;
|
|
} else {
|
|
print(" ✗ FAILED - Cargo.toml should exist");
|
|
}
|
|
} catch (error) {
|
|
print(` ✗ FAILED - Error: ${error}`);
|
|
}
|
|
|
|
// Test 2: Process Module
|
|
total_tests += 1;
|
|
print("Test 2: Process Module - Command detection");
|
|
try {
|
|
let result = which("echo");
|
|
if result != () {
|
|
print(" ✓ PASSED - echo command found");
|
|
tests_passed += 1;
|
|
} else {
|
|
print(" ✗ FAILED - echo command not found");
|
|
}
|
|
} catch (error) {
|
|
print(` ✗ FAILED - Error: ${error}`);
|
|
}
|
|
|
|
// Test 3: Text Module
|
|
total_tests += 1;
|
|
print("Test 3: Text Module - Text processing");
|
|
try {
|
|
let result = dedent(" Hello World");
|
|
if result == "Hello World" {
|
|
print(" ✓ PASSED - Text dedenting works");
|
|
tests_passed += 1;
|
|
} else {
|
|
print(` ✗ FAILED - Expected 'Hello World', got '${result}'`);
|
|
}
|
|
} catch (error) {
|
|
print(` ✗ FAILED - Error: ${error}`);
|
|
}
|
|
|
|
// Test 4: Net Module
|
|
total_tests += 1;
|
|
print("Test 4: Net Module - TCP check");
|
|
try {
|
|
let result = tcp_check("127.0.0.1", 65534);
|
|
if type_of(result) == "bool" {
|
|
print(" ✓ PASSED - TCP check returns boolean");
|
|
tests_passed += 1;
|
|
} else {
|
|
print(` ✗ FAILED - Expected boolean, got ${type_of(result)}`);
|
|
}
|
|
} catch (error) {
|
|
print(` ✗ FAILED - Error: ${error}`);
|
|
}
|
|
|
|
// Test 5: Core Module
|
|
total_tests += 1;
|
|
print("Test 5: Core Module - Exec function");
|
|
try {
|
|
let result = exec("21 * 2");
|
|
if result == 42 {
|
|
print(" ✓ PASSED - Exec function works");
|
|
tests_passed += 1;
|
|
} else {
|
|
print(` ✗ FAILED - Expected 42, got ${result}`);
|
|
}
|
|
} catch (error) {
|
|
print(` ✗ FAILED - Error: ${error}`);
|
|
}
|
|
|
|
// Test 6: Process execution
|
|
total_tests += 1;
|
|
print("Test 6: Process Module - Command execution");
|
|
try {
|
|
let result = run_command("echo 'Integration Test'");
|
|
if result.success && result.stdout.contains("Integration Test") {
|
|
print(" ✓ PASSED - Command execution works");
|
|
tests_passed += 1;
|
|
} else {
|
|
print(" ✗ FAILED - Command execution failed");
|
|
}
|
|
} catch (error) {
|
|
print(` ✗ FAILED - Error: ${error}`);
|
|
}
|
|
|
|
// Test 7: Cross-module integration
|
|
total_tests += 1;
|
|
print("Test 7: Cross-module integration");
|
|
try {
|
|
// Use text module to process content, then process module to execute
|
|
let raw_text = " echo 'cross-module-test' ";
|
|
let processed = dedent(raw_text);
|
|
let final_command = processed.trim();
|
|
|
|
// If dedent removed too much, use a fallback command
|
|
if final_command.len() == 0 {
|
|
final_command = "echo 'cross-module-test'";
|
|
}
|
|
|
|
let result = run_command(final_command);
|
|
if result.success && result.stdout.contains("cross-module-test") {
|
|
print(" ✓ PASSED - Cross-module integration works");
|
|
tests_passed += 1;
|
|
} else {
|
|
print(" ✗ FAILED - Cross-module integration failed");
|
|
}
|
|
} catch (error) {
|
|
print(` ✗ FAILED - Error: ${error}`);
|
|
}
|
|
|
|
// Summary
|
|
print("");
|
|
print("=====================================");
|
|
print(`Results: ${tests_passed}/${total_tests} tests passed`);
|
|
|
|
if tests_passed == total_tests {
|
|
print("🎉 All tests passed! SAL Rhai integration is working!");
|
|
true
|
|
} else {
|
|
print(`⚠️ ${total_tests - tests_passed} test(s) failed`);
|
|
false
|
|
}
|