leannode-core
Version:
Simple Node.js wrapper for Lean 4 theorem prover
66 lines (58 loc) • 1.86 kB
JavaScript
// ./test/test.js
const assert = require('assert');
const LeanRunner = require('../lib/index.js');
async function runTests() {
console.log('Running leannode-core tests...\n');
// Test 1: Basic evaluation
try {
const result = await LeanRunner.run('#eval 2 + 3');
console.log('✓ Test 1: Basic evaluation');
console.log(` Output: "${result.stdout}"`);
console.log(` Exit code: ${result.exitCode}\n`);
} catch (error) {
console.log('✗ Test 1 failed:', error.message);
}
// Test 2: Simple definition
try {
const leanCode = `
def hello : String := "Hello from Lean!"
#eval hello
`.trim();
const result = await LeanRunner.run(leanCode);
console.log('✓ Test 2: Simple definition');
console.log(` Output: "${result.stdout}"`);
console.log(` Exit code: ${result.exitCode}\n`);
} catch (error) {
console.log('✗ Test 2 failed:', error.message);
}
// Test 3: Error handling
try {
const result = await LeanRunner.run('invalid lean syntax here');
console.log('✓ Test 3: Error handling');
console.log(` Stderr: "${result.stderr}"`);
console.log(` Exit code: ${result.exitCode}\n`);
} catch (error) {
console.log('✗ Test 3 failed:', error.message);
}
console.log('Tests completed!');
}
// Check if Lean is installed before running tests
async function checkLeanInstallation() {
try {
const result = await LeanRunner.run('#eval "Lean is working!"');
if (result.exitCode === 0) {
console.log('Lean 4 detected and working!\n');
return true;
}
} catch (error) {
console.log('❌ Lean 4 not found or not working.');
console.log('Please install Lean 4 first: https://leanprover.github.io/');
return false;
}
}
// Run the tests
checkLeanInstallation().then(leanWorking => {
if (leanWorking) {
runTests();
}
});