mirror of
https://github.com/hi-language/transpiler.git
synced 2026-01-14 00:28:05 +00:00
Fix: Correct table Status key, keep code
This commit is contained in:
130
test_runner.js
130
test_runner.js
@@ -15,79 +15,79 @@ const results = [];
|
|||||||
console.log("Running Hi language tests, Master...");
|
console.log("Running Hi language tests, Master...");
|
||||||
|
|
||||||
for (const file of testFiles) {
|
for (const file of testFiles) {
|
||||||
const testCaseName = basename(file, '.hi');
|
const testCaseName = basename(file, '.hi');
|
||||||
const hiFilePath = join(srcDir, file);
|
const hiFilePath = join(srcDir, file);
|
||||||
const expectedOutputPath = join(expectedDir, `${testCaseName}.txt`);
|
const expectedOutputPath = join(expectedDir, `${testCaseName}.txt`);
|
||||||
|
|
||||||
const hiCode = readFileSync(hiFilePath, 'utf-8');
|
const hiCode = readFileSync(hiFilePath, 'utf-8');
|
||||||
const expectedOutput = readFileSync(expectedOutputPath, 'utf-8').trim();
|
const expectedOutput = readFileSync(expectedOutputPath, 'utf-8').trim();
|
||||||
|
|
||||||
let jsCode = '';
|
let jsCode = '';
|
||||||
try {
|
try {
|
||||||
jsCode = hi2js(hiCode);
|
jsCode = hi2js(hiCode);
|
||||||
const actualOutput = execSync('node', {
|
const actualOutput = execSync('node', {
|
||||||
input: jsCode,
|
input: jsCode,
|
||||||
encoding: 'utf-8'
|
encoding: 'utf-8'
|
||||||
}).trim();
|
}).trim();
|
||||||
|
|
||||||
if (actualOutput === expectedOutput) {
|
if (actualOutput === expectedOutput) {
|
||||||
results.push({ name: testCaseName, status: '✅ PASS' });
|
results.push({ name: testCaseName, status: '✅ PASS' });
|
||||||
} else {
|
} else {
|
||||||
results.push({
|
results.push({
|
||||||
name: testCaseName,
|
name: testCaseName,
|
||||||
status: '❌ FAIL',
|
status: '❌ FAIL',
|
||||||
reason: 'Output mismatch',
|
reason: 'Output mismatch',
|
||||||
expected: expectedOutput,
|
expected: expectedOutput,
|
||||||
actual: actualOutput,
|
actual: actualOutput,
|
||||||
jsCode: jsCode
|
jsCode: jsCode
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
results.push({
|
|
||||||
name: testCaseName,
|
|
||||||
status: '❌ FAIL',
|
|
||||||
reason: 'Transpilation or execution error',
|
|
||||||
error: error.message,
|
|
||||||
jsCode: jsCode
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
results.push({
|
||||||
|
name: testCaseName,
|
||||||
|
status: '❌ FAIL',
|
||||||
|
reason: 'Transpilation or execution error',
|
||||||
|
error: error.message,
|
||||||
|
jsCode: jsCode
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateMarkdownReport(results) {
|
function generateMarkdownReport(results) {
|
||||||
let report = `# Hi Language Test Results\n\n`;
|
let report = `# Hi Language Test Results\n\n`;
|
||||||
report += `**Run at:** ${new Date().toISOString()}\n\n`;
|
report += `**Run at:** ${new Date().toISOString()}\n\n`;
|
||||||
|
|
||||||
const summary = results.map(r => ({
|
const summary = results.map(r => ({
|
||||||
"Test Case": `\`${r.name}.hi\``,
|
"Test Case": `\`${r.name}.hi\``,
|
||||||
"Status": r.status
|
"Status": r.status
|
||||||
}));
|
}));
|
||||||
|
|
||||||
report += `| Test Case | Status |\n`;
|
|
||||||
report += `|-----------|--------|\n`;
|
|
||||||
summary.forEach(s => {
|
|
||||||
report += `| ${s['Test Case']} | ${s.Status} |\n`;
|
|
||||||
});
|
|
||||||
|
|
||||||
const failures = results.filter(r => r.status.includes('FAIL'));
|
report += `| Test Case | Status |\n`;
|
||||||
if (failures.length > 0) {
|
report += `|-----------|--------|\n`;
|
||||||
report += `\n---\n\n## Failures\n\n`;
|
summary.forEach(s => {
|
||||||
for (const failure of failures) {
|
report += `| ${s['Test Case']} | ${s['Status']} |\n`;
|
||||||
report += `### \`${failure.name}.hi\`\n\n`;
|
});
|
||||||
report += `**Reason:** ${failure.reason}\n\n`;
|
|
||||||
|
|
||||||
if (failure.reason === 'Output mismatch') {
|
const failures = results.filter(r => r.status.includes('FAIL'));
|
||||||
report += `**Expected Output:**\n\`\`\`text\n${failure.expected}\n\`\`\`\n\n`;
|
if (failures.length > 0) {
|
||||||
report += `**Actual Output:**\n\`\`\`text\n${failure.actual}\n\`\`\`\n\n`;
|
report += `\n---\n\n## Failures\n\n`;
|
||||||
} else {
|
for (const failure of failures) {
|
||||||
report += `**Error:**\n\`\`\`\n${failure.error}\n\`\`\`\n\n`;
|
report += `### \`${failure.name}.hi\`\n\n`;
|
||||||
}
|
report += `**Reason:** ${failure.reason}\n\n`;
|
||||||
if (failure.jsCode) {
|
|
||||||
report += `**Generated JavaScript:**\n\`\`\`js\n${failure.jsCode}\n\`\`\`\n\n`;
|
if (failure.reason === 'Output mismatch') {
|
||||||
}
|
report += `**Expected Output:**\n\`\`\`text\n${failure.expected}\n\`\`\`\n\n`;
|
||||||
report += `---\n\n`;
|
report += `**Actual Output:**\n\`\`\`text\n${failure.actual}\n\`\`\`\n\n`;
|
||||||
}
|
} else {
|
||||||
|
report += `**Error:**\n\`\`\`\n${failure.error}\n\`\`\`\n\n`;
|
||||||
|
}
|
||||||
|
if (failure.jsCode) {
|
||||||
|
report += `**Generated JavaScript:**\n\`\`\`js\n${failure.jsCode}\n\`\`\`\n\n`;
|
||||||
|
}
|
||||||
|
report += `---\n\n`;
|
||||||
}
|
}
|
||||||
return report;
|
}
|
||||||
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
const markdownReport = generateMarkdownReport(results);
|
const markdownReport = generateMarkdownReport(results);
|
||||||
@@ -96,8 +96,8 @@ writeFileSync(resultsFile, markdownReport);
|
|||||||
console.log(`Test run complete. Results written to ${resultsFile}`);
|
console.log(`Test run complete. Results written to ${resultsFile}`);
|
||||||
|
|
||||||
if (results.some(r => r.status.includes('FAIL'))) {
|
if (results.some(r => r.status.includes('FAIL'))) {
|
||||||
console.log("Some tests failed, Master.");
|
console.log("Some tests failed, Master.");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else {
|
} else {
|
||||||
console.log("All tests passed, Master.");
|
console.log("All tests passed, Master.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user