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
8 changes: 8 additions & 0 deletions __fixtures__/pkg.rust-workspace-deps/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[workspace]
members = ["pkg-a"]

[workspace.package]
version = "1.0.0"

[workspace.dependencies]
serde = "1.0"
6 changes: 6 additions & 0 deletions __fixtures__/pkg.rust-workspace-deps/pkg-a/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "rust_workspace_dep_fixture"
version = "0.5.0"

[dependencies]
serde = { workspace = true }
17 changes: 17 additions & 0 deletions helpers/test-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ it.only = function only(
}
};

it.skipIf = function skipIf(condition: boolean) {
return function (
desc: string,
op?: () => Operation<void>,
timeout?: number
): void {
if (condition) {
return vitest.it.skip(desc, () => {});
}
if (op) {
return vitest.it(desc, async () => scope?.runTest(op), timeout);
} else {
return vitest.it.skip(desc, () => {});
}
};
};

export function captureError<T>(op: Operation<T>): Operation<T | Error> {
return function* () {
try {
Expand Down
30 changes: 10 additions & 20 deletions packages/apply/test/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,9 @@ describe("validate apply", () => {
expect(validated).toBe(true);
});

it("bumps multi rust toml as minor with object dep without version number", function* () {
it("bumps multi rust toml as minor with object dep without version number (path-only)", function* () {
// Path-only dependencies (e.g., { path = "../pkg" }) are valid in Cargo
// for local development and should not cause an error
const stream = pinoTest.sink();
const logger = pino(stream);

Expand All @@ -351,10 +353,6 @@ describe("validate apply", () => {
},
},
};
const allPackages: Record<string, PackageFile> = yield readAllPkgFiles({
config,
cwd: rustFolder,
});

const commands: PackageCommand[] = [
{
Expand All @@ -375,20 +373,12 @@ describe("validate apply", () => {
},
];

const errored = yield captureError(
validateApply({
logger,
commands,
allPackages,
})
);
logger.info("completed");
expect(errored.message).toMatch(
"rust_pkg_a_fixture has a dependency on rust_pkg_b_fixture, and rust_pkg_b_fixture does not have a version number. " +
"This cannot be published. Please pin it to a MAJOR.MINOR.PATCH reference."
);

// to confirm that no error logs have been returned
yield pinoTest.consecutive(stream, [{ msg: "completed", level: 30 }]);
const validated = yield validateApply({
logger,
commands,
config,
cwd: rustFolder,
});
expect(validated).toBe(true);
});
});
11 changes: 9 additions & 2 deletions packages/covector/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ export const loadContent = (cwd: string, pathToContent: string) => {
return fs.readFileSync(path.join(cwd, pathToContent), { encoding: "utf8" });
};

const normalizeLineEndings = (s: string) => s?.replace(/\r\n/g, "\n");

export const checksWithObject =
(keys = ["command"]) =>
(received, expected) => {
if (received.msg !== expected.msg || received.level !== expected.level) {
assert.deepEqual(received, expected);
const receivedMsg = normalizeLineEndings(received.msg);
const expectedMsg = normalizeLineEndings(expected.msg);
if (receivedMsg !== expectedMsg || received.level !== expected.level) {
assert.deepEqual(
{ ...received, msg: receivedMsg },
{ ...expected, msg: expectedMsg }
);
}
for (let key of keys) {
if (expected?.[key]) assert.deepEqual(received?.[key], expected?.[key]);
Expand Down
10 changes: 10 additions & 0 deletions packages/files/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ export const getPackageFileVersion = ({
case "string":
return depDefinition;
case "object":
// Cargo workspace dependencies use { workspace = true } without a version
// The version is inherited from the workspace root
if (depDefinition.workspace === true) {
return depDefinition.version || "";
}
// Cargo path-only dependencies (e.g., { path = "../pkg" }) don't require a version
// for local development - covector should not error on these
if (depDefinition.path && !depDefinition.version) {
return "";
}
if (!depDefinition.version) {
throw new Error(
`${pkg.name} has a dependency on ${dep}, and ${dep} does not have a version number. ` +
Expand Down
30 changes: 29 additions & 1 deletion packages/files/test/toml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { describe, it } from "../../../helpers/test-scope.ts";
import { expect } from "vitest";
import path from "path";
import fixtures from "fixturez";
import { readPkgFile, setPackageFileVersion, writePkgFile } from "../src";
import {
readPkgFile,
setPackageFileVersion,
getPackageFileVersion,
writePkgFile,
} from "../src";

const f = fixtures(__dirname);

Expand Down Expand Up @@ -81,6 +86,29 @@ describe("toml", () => {
expect(cargoFilePkgB?.pkg?.package?.name).toBe("rust_pkg_b_fixture");
expect(cargoFilePkgB.version).toBe("0.8.8");
});

it("with workspace = true dependencies", function* () {
// Cargo workspace dependencies can use { workspace = true } to inherit
// version from the workspace root. This should not throw an error.
const cargoFolder = f.copy("pkg.rust-workspace-deps");

const cargoFilePkgA = yield readPkgFile({
file: "Cargo.toml",
cwd: path.join(cargoFolder, "pkg-a"),
nickname: "rust_workspace_dep_fixture",
});
expect(cargoFilePkgA.name).toBe("rust_workspace_dep_fixture");
expect(cargoFilePkgA.version).toBe("0.5.0");

// getPackageFileVersion should return empty string for workspace deps
// instead of throwing an error
const depVersion = getPackageFileVersion({
pkg: cargoFilePkgA,
property: "dependencies",
dep: "serde",
});
expect(depVersion).toBe("");
});
});
});

Expand Down
Loading