clank-together/test/units.test.js
Saty 67965b04f1 Refuse removing annotations of functions not held; new source files join the build list
- A submission may not drop the annotation of a function of the current
  build it does not hold (51 annotations were lost that way); removing a
  duplicate is fine.
- A unit missing from compile.json compiles with the command shape of its
  folder, and the merge adds it to compile.json in the same commit (22
  contributor files were outside the build).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 04:56:07 +02:00

18 lines
1.3 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { inferShape, addUnitsToCompileCommands } from '../src/shared/project.js';
test('new source files get the flags of their folder and join the build list', () => {
const compile = { shapes: [['/a'], ['/b']], units: { 'Engine/Gx/A.cpp': 1, 'Engine/Gx/B.cpp': 1, 'Engine/Base/C.cpp': 0, 'WoW/D.cpp': 0 } };
const project = { compile };
assert.equal(inferShape(project, 'Engine/Gx/New.cpp'), 1, 'its folder');
assert.equal(inferShape(project, 'Engine/Gx/Deep/New.cpp'), 1, 'the nearest folder with units');
assert.equal(inferShape(project, 'Tools/X.cpp'), 0, 'the most common one');
const text = JSON.stringify(compile, null, 1);
const grown = addUnitsToCompileCommands(project, text, ['Engine/Gx/New.cpp', 'Engine/Gx/A.cpp', 'Engine/Gx/x.h', 'WoW/Win32/Old.cpp']);
assert.deepEqual(grown.added, ['Engine/Gx/New.cpp'], 'headers, listed units and Win32 copies are left alone');
const doc = JSON.parse(grown.text);
assert.deepEqual(Object.keys(doc.units), ['Engine/Base/C.cpp', 'Engine/Gx/A.cpp', 'Engine/Gx/B.cpp', 'Engine/Gx/New.cpp', 'WoW/D.cpp']);
assert.equal(doc.units['Engine/Gx/New.cpp'], 1);
assert.equal(addUnitsToCompileCommands(project, text, ['Engine/Gx/A.cpp']), null);
});