testWhatASaveReplacedDuringARunStillCounts

tcmts.cli.suites.test.testWhatASaveReplacedDuringARunStillCounts · #5bznidfq · term

A definition a save replaced while the run went on (no name points at it once it ends) still counts, by the name it had when the run started; without those names, nothing follows it, and what the run executed isn't known.

import { ownCode } from "#codebase/tcmts/cli/suites";
import { coveredRun, SOURCE } from "#codebase/tcmts/cli/suites/test";
import assert from "node:assert/strict";

export const testWhatASaveReplacedDuringARunStillCounts = () => {
  const { cb, def, executedBy } = coveredRun(SOURCE);
  const main = def("main").hash;
  const atStart = new Map(
    ["main", "table", "double", "register", "registered", "registry"].map((n) => [def(n).hash, n]),
  );
  const named = cb.store.pathsOf.bind(cb.store);
  cb.store.pathsOf = (h: string) => (h === main ? [] : named(h));
  const ran: [string, string][] = [
    ["main", "main"],
    ["double", "double"],
    ["register", "register"],
  ];
  assert.equal(executedBy(undefined, ran), undefined);
  const out = executedBy(atStart, ran)!;
  assert.ok("main" in out && "table" in out && "double" in out);
  // its code as it was, named as things were
  assert.equal(
    out.main,
    ownCode(cb, def("main"), (h) => atStart.get(h)),
  );
}

uses