Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ node --import tsx scripts/gen-golden.ts --all
- `format`: `cadence` or `altium`
- `name`: output file name (without the `.netlist.json` suffix)
- `path`: path to the design file (.DSN, .PrjPcb, or pstxnet.dat)
- `--all`: regenerate all golden files from discovered fixtures. A fixture the parsers refuse, listed in `UNSUPPORTED_FIXTURES` in `test/utils.ts`, is skipped: it has no golden, and the golden test checks its refusal instead
- `--all`: regenerate all golden files from discovered fixtures. A fixture the parsers refuse, listed in `UNSUPPORTED_FIXTURES` in `test/utils.ts`, is skipped: it has no golden, and the golden test checks its refusal instead. A design with a pin on several nets (`labcomm-projecton`, `scr-236`) is skipped too, in both modes: a Universal Netlist gives each pin one net, so no golden can hold it, and `src/cli/export-design.test.ts` checks that `export_design` refuses it

A golden is only rewritten when its content actually moved. The tests compare
structurally, so a parser that merely reorders the keys it writes would
Expand Down
6 changes: 6 additions & 0 deletions scripts/gen-golden.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env -S node --import tsx
import path from "node:path";
import { parseDesign } from "../src/parsers/index.js";
import { exportRefusal } from "../src/cli/export-design.js";
import { parseCadenceDatDesign } from "../src/parsers/cadence/index.js";
import { findCadenceDatFiles } from "../src/parsers/cadence/discovery.js";
import {
Expand Down Expand Up @@ -37,6 +38,11 @@ const generateOne = async (format: Format, name: string, designPath: string): Pr
console.log(
` Components: ${Object.keys(result.components).length}, Nets: ${Object.keys(result.nets).length}`
);
// A design with a pin on several nets has no golden: the file cannot hold it.
if (exportRefusal(result) !== undefined) {
console.log(` Skipped: ${format}/${name} (a pin is on several nets)`);
return false;
}
const written = await saveGolden(format, name, result, parsePath);
console.log(
written
Expand Down
28 changes: 28 additions & 0 deletions src/cli/export-design.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,34 @@ describe("export_design refuses a design the file cannot hold", () => {
},
PARSE_TIMEOUT
);

it.skipIf(!hasFixtures).each([
[
"wired to two nets",
["cadence", "labcomm-projecton", "LABCOMM_PROJECTON.DSN"],
"U10.4 is on 2 nets (+10V, N5769); U10.11 is on 2 nets (-10V, N5793). ",
],
[
"wired on one section and unconnected on another",
["cadence", "scr-236", "SCR-236.dsn"],
"U9.14 is on IN_VCC and also left unconnected; U9.7 is on GND_PT_IN and also left unconnected; U11.14 is on IN_VCC and also left unconnected; U11.7 is on GND_PT_IN and also left unconnected. ",
],
])(
"refuses a real design with a pin %s",
async (_case, fixture, pins) => {
const out = path.join(dir, "refused.netlist.json");

const outcome = await exportDesign(fixturePath(...fixture), "--output", out);

expect(outcome.exitCode).toBe(1);
expect(JSON.parse(outcome.stdout!).error).toBe(
pins +
"A Universal Netlist gives each pin one net, so this design cannot be exported until each pin is wired to one net."
);
expect(existsSync(out)).toBe(false);
},
PARSE_TIMEOUT
);
});

describe.skipIf(!hasFixtures)("export_design on a design with named variants", () => {
Expand Down
4 changes: 4 additions & 0 deletions test/integration/golden.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* 4. Commit the golden JSON file to test/golden/{format}/{name}.netlist.json
*/

import { exportRefusal } from "../../src/cli/export-design.js";
import path from "node:path";
import { describe, it, expect } from "vitest";
import {
Expand Down Expand Up @@ -102,6 +103,9 @@ describe("Parser Golden Output", { timeout: PARSE_TIMEOUT }, async () => {
it("should match golden output", async () => {
const golden = await loadGolden(fixture.format, projectName);

// A design with a pin on several nets has no golden: the file cannot hold it.
if (!golden && exportRefusal(await parseDesign(designFile)) !== undefined) return;

if (!golden) {
throw new Error(
`Missing golden output for ${fixture.format}/${projectName}. ` +
Expand Down