feat: move corpus to library
Test / test (push) Failing after 1m38s

This commit is contained in:
alexm committed 2026-10-06 10:27:46 -04:00
1 parent 5b8b079165
commit cae5cff55a
1350 files changed
+197 -941995

No files matched your search

+17 -17
View File
@@ -1,4 +1,4 @@
// Programming+'s Mojo checker, scored against the real compiler (godbolt's answers in mojo/golden,
// Programming+'s Mojo checker, scored against the real compiler (godbolt's answers in library/mojo/golden,
// and the compiler's own diagnostic tests). Two rules never bend, and two numbers only go up:
// - no error on a program the compiler accepts (a false accusation teaches the wrong lesson)
// - no error on a rejected program that the compiler did not make there, in those words
@@ -12,8 +12,8 @@ import { compilerDiagnostics } from '../dist/services/godbolt.js';
const R = new URL('..', import.meta.url).pathname;
const read = (p) => JSON.parse(fs.readFileSync(R + p, 'utf8'));
const golden = (key) => key && fs.existsSync(`${R}mojo/golden/${key}.json`) ? read(`mojo/golden/${key}.json`) : null;
const verdicts = new Map(read('mojo/golden/status.json').items.map((r) => [r.id, r]));
const golden = (key) => key && fs.existsSync(`${R}library/mojo/golden/${key}.json`) ? read(`library/mojo/golden/${key}.json`) : null;
const verdicts = new Map(read('library/mojo/golden/status.json').items.map((r) => [r.id, r]));
const errorsOf = (src) => checkMojo(src).diagnostics.filter((d) => d.severity === 'error');
/** What the compiler said, as (line, message): its <source> errors, and the one it gives no line. */
@@ -28,18 +28,18 @@ const MATCHED_AT_LEAST = 43; // raise when a stage makes more starters
const ANNOTATIONS_AT_LEAST = 21; // 2a: 14, 2b: 18, 2c: 19, 4c: 21
test('no false accusations: every program the compiler accepts gets no error', () => {
const items = [...read('mojo/corpus/quest/manifest.json').items.map((i) => ['quest', i]), ...read('mojo/corpus/manual/manifest.json').items.map((i) => ['manual', i])];
const items = [...read('library/mojo/corpus/quest/manifest.json').items.map((i) => ['quest', i]), ...read('library/mojo/corpus/manual/manifest.json').items.map((i) => ['manual', i])];
const accused = []; let checked = 0;
for (const [dir, it] of items) {
const g = golden(verdicts.get(it.id)?.key);
if (!g?.result.compiled) continue;
checked++;
for (const d of errorsOf(fs.readFileSync(`${R}mojo/corpus/${dir}/${it.file}`, 'utf8'))) accused.push(`${it.id}: line ${d.line}: ${d.message}`);
for (const d of errorsOf(fs.readFileSync(`${R}library/mojo/corpus/${dir}/${it.file}`, 'utf8'))) accused.push(`${it.id}: line ${d.line}: ${d.message}`);
}
for (const f of fs.readdirSync(`${R}mojo/local`).filter((f) => f.endsWith('.mojo'))) for (const d of errorsOf(fs.readFileSync(`${R}mojo/local/${f}`, 'utf8'))) accused.push(`local/${f}: line ${d.line}: ${d.message}`);
for (const f of fs.readdirSync(`${R}library/mojo/local`).filter((f) => f.endsWith('.mojo'))) for (const d of errorsOf(fs.readFileSync(`${R}library/mojo/local/${f}`, 'utf8'))) accused.push(`local/${f}: line ${d.line}: ${d.message}`);
// the stress programs: every one is meant to compile, so none may be accused, verified or not
for (const f of fs.readdirSync(`${R}mojo/stress`).filter((f) => f.endsWith('.mojo'))) {
const src = fs.readFileSync(`${R}mojo/stress/${f}`, 'utf8');
for (const f of fs.readdirSync(`${R}library/mojo/stress`).filter((f) => f.endsWith('.mojo'))) {
const src = fs.readFileSync(`${R}library/mojo/stress/${f}`, 'utf8');
if (/^# expect: compile-error$/m.test(src)) continue; // kept as checker tests: meant to fail
for (const d of errorsOf(src)) accused.push(`stress/${f}: line ${d.line}: ${d.message}`);
}
@@ -49,10 +49,10 @@ test('no false accusations: every program the compiler accepts gets no error', (
test('rejected starters: what Programming+ says is what the compiler said', () => {
const wrong = [], matched = [];
for (const it of read('mojo/corpus/quest/manifest.json').items.filter((i) => i.id.endsWith('/starter'))) {
for (const it of read('library/mojo/corpus/quest/manifest.json').items.filter((i) => i.id.endsWith('/starter'))) {
const g = golden(verdicts.get(it.id)?.key);
if (!g || g.result.compiled) continue;
const ours = errorsOf(fs.readFileSync(`${R}mojo/corpus/quest/${it.file}`, 'utf8'));
const ours = errorsOf(fs.readFileSync(`${R}library/mojo/corpus/quest/${it.file}`, 'utf8'));
if (!ours.length) continue;
const theirs = compilerSaid(g);
const bad = ours.filter((d) => !theirs.some((t) => t.line === d.line && t.message === d.message));
@@ -67,12 +67,12 @@ test('rejected starters: what Programming+ says is what the compiler said', () =
test('the compiler\'s own diagnostic tests: every error Programming+ reports there is one they expect', () => {
const toRe = (a) => new RegExp(a.message.split(/(\{\{.*?\}\})/).map((p) => p.startsWith('{{') ? p.slice(2, -2) : p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join(''));
const wrong = []; let matched = 0;
for (const it of read('mojo/corpus/diagnostics/manifest.json').items) {
for (const it of read('library/mojo/corpus/diagnostics/manifest.json').items) {
// run with the isolated stdlib or other local files: they know other names, and that mode
// does not check for code at file scope; and as tests, none of them has a main
const special = it.run.some((r) => /isolated|%S\/|-I\s/.test(r));
const skip = new Set(['no-main', ...(special ? ['unknown-name', 'implicit-declaration', 'file-scope'] : [])]);
for (const d of errorsOf(fs.readFileSync(`${R}mojo/corpus/diagnostics/${it.file}`, 'utf8')).filter((d) => !skip.has(d.id))) {
for (const d of errorsOf(fs.readFileSync(`${R}library/mojo/corpus/diagnostics/${it.file}`, 'utf8')).filter((d) => !skip.has(d.id))) {
if (it.annotations.some((a) => a.kind === 'error' && a.line === d.line && (a.regex ? toRe(a).test(d.message) : d.message.includes(a.message)))) matched++;
else wrong.push(`${it.id}: line ${d.line}: ${d.message}`);
}
@@ -158,9 +158,9 @@ test('Stage 2c: types, in the compiler\'s words, and silence where a type is not
test('lifetime warnings: each is the compiler\'s, at its line and column', () => {
const programs = [];
for (const [dir, mf] of [['quest', 'quest'], ['manual', 'manual']]) for (const it of read(`mojo/corpus/${mf}/manifest.json`).items) programs.push([it.id, `mojo/corpus/${dir}/${it.file}`]);
for (const f of fs.readdirSync(`${R}mojo/probes`)) programs.push([`probes/${f.replace('.mojo', '')}`, `mojo/probes/${f}`]);
for (const f of fs.readdirSync(`${R}mojo/stress`)) programs.push([`stress/${f.replace('.mojo', '')}`, `mojo/stress/${f}`]);
for (const [dir, mf] of [['quest', 'quest'], ['manual', 'manual']]) for (const it of read(`library/mojo/corpus/${mf}/manifest.json`).items) programs.push([it.id, `library/mojo/corpus/${dir}/${it.file}`]);
for (const f of fs.readdirSync(`${R}library/mojo/probes`)) programs.push([`probes/${f.replace('.mojo', '')}`, `library/mojo/probes/${f}`]);
for (const f of fs.readdirSync(`${R}library/mojo/stress`)) programs.push([`stress/${f.replace('.mojo', '')}`, `library/mojo/stress/${f}`]);
const wrong = []; let matched = 0;
for (const [id, file] of programs) {
const g = golden(verdicts.get(id)?.key);
@@ -190,8 +190,8 @@ test('Stage 4c: a value read where it may be uninitialized, on any path, in the
test('rejected stress programs: whatever Programming+ reports there is what the compiler said', () => {
const wrong = []; let matched = 0, current = 0;
for (const f of fs.readdirSync(`${R}mojo/stress`).filter((f) => f.endsWith('.mojo'))) {
const src = fs.readFileSync(`${R}mojo/stress/${f}`, 'utf8');
for (const f of fs.readdirSync(`${R}library/mojo/stress`).filter((f) => f.endsWith('.mojo'))) {
const src = fs.readFileSync(`${R}library/mojo/stress/${f}`, 'utf8');
const g = golden(verdicts.get(`stress/${f.replace('.mojo', '')}`)?.key);
// a golden answers the exact source godbolt saw: an edited file waits for the next verify
if (!g || g.result.compiled || g.sourceSha256 !== crypto.createHash('sha256').update(src).digest('hex')) continue;