Cotton code
34 lines · 1.4 KB · TypeScriptRaw
import { readFileSync } from "node:fs";import { resolve } from "node:path";import { describe, expect, it } from "vitest";/** * The Rust toolchain is one exact version. A moving channel ("stable", * "beta", "nightly") is resolved separately by every machine at the moment it * first installs, so two CI lanes — or a new Mac — compile and lint with * different compilers, and a stable release's new clippy lints turn * `rust-lint` red on a main nobody changed. */const ROOT = resolve(__dirname, "../..");const TOOLCHAIN = resolve(ROOT, "crates/rust-toolchain.toml");/** The `channel` value, read the way the workflows read it. */function channel(text: string): string | undefined {  return /^\s*channel\s*=\s*"([^"]*)"/m.exec(text)?.[1];}describe("crates/rust-toolchain.toml", () => {  // RULE: The Rust toolchain is pinned to one exact version, never a moving channel like stable.  it("names one exact version", () => {    const pinned = channel(readFileSync(TOOLCHAIN, "utf8"));    expect(pinned, "the workflows read `channel` out of this file").toBeDefined();    expect(pinned).toMatch(/^\d+\.\d+\.\d+$/);  });  it("reads a channel the same way the workflows' sed does", () => {    expect(channel('[toolchain]\nchannel = "1.98.1"\n')).toBe("1.98.1");    expect(channel('[toolchain]\n  channel="stable"\n')).toBe("stable");    expect(channel("[toolchain]\n")).toBeUndefined();  });});